Skip to content

Commit

Permalink
Fix test failures on Bash 4.3
Browse files Browse the repository at this point in the history
Failures are due to scoping issues in traps that only happen when $() is
used:

bats-gather-tests:280, start of bats_gather_tests_source_exit_trap:
  local: can only be used in a function
tracing.bash:301, end of bats_debug_trap:
   pop_scope: head of shell_variables not a temporary environment scope
  • Loading branch information
martin-schulze-vireso committed May 30, 2024
1 parent e3266cd commit cba81e0
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion libexec/bats-core/bats-gather-tests
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,18 @@ for filename in "$@"; do
file_test_count=0
file_included_test_count=0
saved_focus_mode=$focus_mode

# get new values for the variables above
result="$(set -eET; bats_gather_tests_for_file)"
if [[ $BASH_VERSION == 4.3.* ]]; then
# Bash 4.3 has function scoping issues when this is run in $() -> work around via file
bats_gather_tests_var_transfer_file=$BATS_RUN_TMPDIR/gather-tests-var-transfer
(set -eET; bats_gather_tests_for_file >"$bats_gather_tests_var_transfer_file")
result=$(<"$bats_gather_tests_var_transfer_file")
else
# separate retrieval from eval to avoid hiding the exit code
result="$(set -eET; bats_gather_tests_for_file)"
fi

eval "$result"

if [[ -n "$file_duplicate_test_names" ]]; then
Expand Down

0 comments on commit cba81e0

Please sign in to comment.