diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index a2687b2d11..10edebba63 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -27,6 +27,7 @@ quotes around code blocks in error output (#506) * fix recurring errors on CTRL+C tests with NPM on Windows in selftest suite (#516) * fixed leaking of local variables from debug trap (#520) * don't mark FD3 output from `teardown_file` as `` in junit output (#532) +* fix unbound variable error with Bash pre 4.4 (#550) #### Documentation diff --git a/libexec/bats-core/bats-exec-file b/libexec/bats-core/bats-exec-file index aa81c86651..298441b120 100755 --- a/libexec/bats-core/bats-exec-file +++ b/libexec/bats-core/bats-exec-file @@ -1,8 +1,8 @@ #!/usr/bin/env bash set -eET -export flags=() -num_jobs=1 +export flags=('--dummy-flag') +num_jobs=${BATS_NUMBER_OF_PARALLEL_JOBS:-1} filter='' extended_syntax='' BATS_TRACE_LEVEL="${BATS_TRACE_LEVEL:-0}" diff --git a/libexec/bats-core/bats-exec-suite b/libexec/bats-core/bats-exec-suite index b9d4c8e0b1..05c66f44fb 100755 --- a/libexec/bats-core/bats-exec-suite +++ b/libexec/bats-core/bats-exec-suite @@ -3,7 +3,7 @@ set -e count_only_flag='' filter='' -num_jobs=${BATS_NUMBER_OF_PARALLEL_JOBS-1} +num_jobs=${BATS_NUMBER_OF_PARALLEL_JOBS:-1} bats_no_parallelize_across_files=${BATS_NO_PARALLELIZE_ACROSS_FILES-} bats_no_parallelize_within_files= flags=('--dummy-flag') # add a dummy flag to prevent unset varialeb errors on empty array expansion in old bash versions diff --git a/libexec/bats-core/bats-exec-test b/libexec/bats-core/bats-exec-test index 8d599501fd..aae457299f 100755 --- a/libexec/bats-core/bats-exec-test +++ b/libexec/bats-core/bats-exec-test @@ -30,6 +30,8 @@ while [[ "$#" -ne 0 ]]; do # shellcheck disable=SC2034 BATS_EXTENDED_SYNTAX='-x' ;; + --dummy-flag) + ;; --trace) (( ++BATS_TRACE_LEVEL )) # avoid returning 0 ;; diff --git a/test/bats.bats b/test/bats.bats index 514952c321..abc5fa82e9 100755 --- a/test/bats.bats +++ b/test/bats.bats @@ -371,10 +371,24 @@ setup() { @test 'ensure compatibility with unofficial Bash strict mode' { local expected='ok 1 unofficial Bash strict mode conditions met' + if [[ -n "$BATS_NUMBER_OF_PARALLEL_JOBS" ]]; then + if [[ -z "$BATS_NO_PARALLELIZE_ACROSS_FILES" ]]; then + type -p parallel &>/dev/null || skip "Don't check file parallelized without GNU parallel" + fi + (type -p flock &>/dev/null || type -p shlock &>/dev/null) || skip "Don't check parallelized without flock/shlock " + fi + + # PATH required for windows + # HOME required to avoid error from GNU Parallel # Run Bats under SHELLOPTS=nounset (recursive `set -u`) to catch # as many unset variable accesses as possible. - run run_under_clean_bats_env env SHELLOPTS=nounset \ - "${BATS_ROOT}/bin/bats" "$FIXTURE_ROOT/unofficial_bash_strict_mode.bats" + run env - \ + "PATH=$PATH" \ + "HOME=$HOME" \ + "BATS_NO_PARALLELIZE_ACROSS_FILES=$BATS_NO_PARALLELIZE_ACROSS_FILES" \ + "BATS_NUMBER_OF_PARALLEL_JOBS=$BATS_NUMBER_OF_PARALLEL_JOBS" \ + SHELLOPTS=nounset \ + "${BATS_ROOT}/bin/bats" "$FIXTURE_ROOT/unofficial_bash_strict_mode.bats" if [[ "$status" -ne 0 || "${lines[1]}" != "$expected" ]]; then cat < pid=pgid diff --git a/test/test_helper.bash b/test/test_helper.bash index bbfdc778ed..b2ee22b123 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -27,10 +27,3 @@ emit_debug_output() { # shellcheck disable=SC2154 printf '%s\n' 'output:' "$output" >&2 } - -run_under_clean_bats_env() { - # we want the variable names to be separate - # shellcheck disable=SC2086 - unset ${!BATS_@} - "$@" -}