Skip to content

Commit

Permalink
Add runfiles in tests (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
keith authored Jan 14, 2023
1 parent 5e7405c commit 21131ee
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module(
name = "rules_multirun",
version = "0.3.0",
version = "0.3.1",
compatibility_level = 1,
)

Expand Down
1 change: 1 addition & 0 deletions tests/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,5 @@ sh_test(
":validate_args_cmd",
":validate_env_cmd",
],
deps = ["@bazel_tools//tools/bash/runfiles"],
)
30 changes: 24 additions & 6 deletions tests/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,47 @@

set -euo pipefail

output=$(./tests/hello.bash)
# --- begin runfiles.bash initialization v2 ---
# Copy-pasted from the Bazel Bash runfiles library v2.
set -uo pipefail; set +e; f=bazel_tools/tools/bash/runfiles/runfiles.bash
# shellcheck disable=SC1090
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \
source "$0.runfiles/$f" 2>/dev/null || \
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
# --- end runfiles.bash initialization v2 ---

script=$(rlocation rules_multirun/tests/hello.bash)
output=$($script)
if [[ "$output" != "hello" ]]; then
echo "Expected 'hello', got '$output'"
exit 1
fi

./tests/validate_args_cmd.bash
./tests/validate_env_cmd.bash
script=$(rlocation rules_multirun/tests/validate_args_cmd.bash)
$script
script=$(rlocation rules_multirun/tests/validate_env_cmd.bash)
$script

parallel_output="$(./tests/multirun_parallel.bash)"
script="$(rlocation rules_multirun/tests/multirun_parallel.bash)"
parallel_output="$($script)"
if [[ -n "$parallel_output" ]]; then
echo "Expected no output, got '$parallel_output'"
exit 1
fi

serial_output=$(./tests/multirun_serial.bash | sed 's/@@/@/g')
script=$(rlocation rules_multirun/tests/multirun_serial.bash)
serial_output=$($script | sed 's/@@/@/g')
if [[ "$serial_output" != "Running @//tests:validate_args_cmd
Running @//tests:validate_env_cmd" ]]; then
echo "Expected labeled output, got '$serial_output'"
exit 1
fi

serial_no_output=$(./tests/multirun_serial_no_print.bash)
script=$(rlocation rules_multirun/tests/multirun_serial_no_print.bash)
serial_no_output=$($script)
if [[ -n "$serial_no_output" ]]; then
echo "Expected no output, got '$serial_no_output'"
exit 1
Expand Down

0 comments on commit 21131ee

Please sign in to comment.