From 1a92866010dc39cdc1fd4a6f80bdca6a23acaa32 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Mon, 12 Sep 2022 03:59:24 +0900 Subject: [PATCH 1/6] Adjust indentation --- lib/bats-core/common.bash | 12 ++++++------ lib/bats-core/test_functions.bash | 24 ++++++++++++------------ lib/bats-core/validator.bash | 22 +++++++++++----------- lib/bats-core/warnings.bash | 10 +++++----- 4 files changed, 34 insertions(+), 34 deletions(-) diff --git a/lib/bats-core/common.bash b/lib/bats-core/common.bash index fa918ad1e4..b7697d8bf7 100644 --- a/lib/bats-core/common.bash +++ b/lib/bats-core/common.bash @@ -1,12 +1,12 @@ #!/usr/bin/env bash bats_prefix_lines_for_tap_output() { - while IFS= read -r line; do - printf '# %s\n' "$line" || break # avoid feedback loop when errors are redirected into BATS_OUT (see #353) - done - if [[ -n "$line" ]]; then - printf '# %s\n' "$line" - fi + while IFS= read -r line; do + printf '# %s\n' "$line" || break # avoid feedback loop when errors are redirected into BATS_OUT (see #353) + done + if [[ -n "$line" ]]; then + printf '# %s\n' "$line" + fi } function bats_replace_filename() { diff --git a/lib/bats-core/test_functions.bash b/lib/bats-core/test_functions.bash index a5f1097f5a..e2d5773034 100644 --- a/lib/bats-core/test_functions.bash +++ b/lib/bats-core/test_functions.bash @@ -60,12 +60,12 @@ bats_internal_load() { # library_load_path is a library loader if [[ -f "$library_load_path" ]]; then - # shellcheck disable=SC1090 - if ! source "$library_load_path"; then - printf "Error while sourcing library loader at '%s'\n" "$library_load_path" >&2 - return 1 - fi - return 0 + # shellcheck disable=SC1090 + if ! source "$library_load_path"; then + printf "Error while sourcing library loader at '%s'\n" "$library_load_path" >&2 + return 1 + fi + return 0 fi printf "Passed library load path is neither a library loader nor library directory: %s\n" "$library_load_path" >&2 @@ -148,9 +148,9 @@ bats_load_library() { # # load acts like bats_load_safe but exits the shell instead of returning 1. load() { - if ! bats_load_safe "$@"; then - exit 1 - fi + if ! bats_load_safe "$@"; then + exit 1 + fi } bats_redirect_stderr_into_file() { @@ -257,9 +257,9 @@ run() { # [!|-N] [--keep-empty-lines] [--separate-stderr] [--] [--no-stacktrace] [> "$BATS_WARNING_FILE" 2>&3 else printf "Invalid Bats warning number '%s'. It must be an integer between 1 and %d." "$warning_number" "$((${#BATS_WARNING_SHORT_DESCS[@]} - 1))" >&2 From d87dc3a94bcd13d2c648d24e50dfdbcb2c7c2499 Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Sun, 18 Sep 2022 08:39:30 +0200 Subject: [PATCH 2/6] shfmt all the files --- .github/workflows/check_pr_label.sh | 2 +- bin/bats | 4 +- contrib/release.sh | 16 +- contrib/semver | 259 +++++---- docker/install_tini.sh | 26 +- lib/bats-core/common.bash | 56 +- lib/bats-core/formatter.bash | 224 ++++---- lib/bats-core/preprocessing.bash | 20 +- lib/bats-core/semaphore.bash | 132 ++--- lib/bats-core/test_functions.bash | 74 +-- lib/bats-core/tracing.bash | 508 +++++++++--------- lib/bats-core/validator.bash | 12 +- lib/bats-core/warnings.bash | 4 +- libexec/bats-core/bats | 77 +-- libexec/bats-core/bats-exec-file | 38 +- libexec/bats-core/bats-exec-suite | 133 +++-- libexec/bats-core/bats-exec-test | 90 ++-- libexec/bats-core/bats-format-junit | 41 +- libexec/bats-core/bats-format-pretty | 46 +- libexec/bats-core/bats-format-tap | 50 +- libexec/bats-core/bats-format-tap13 | 64 +-- libexec/bats-core/bats-preprocess | 26 +- shellcheck.sh | 17 +- test/bats.bats | 255 +++++---- test/common.bats | 353 ++++++------ test/concurrent-coordination.bash | 94 ++-- test/file_setup_teardown.bats | 42 +- ...variables_dont_contain_double_slashes.bats | 4 +- test/fixtures/bats/comment_style.bats | 20 +- .../fixtures/bats/dos_line_no_shellcheck.bats | 6 +- test/fixtures/bats/empty.bats | 1 + .../fixtures/bats/evaluation_count/file1.bats | 6 +- .../fixtures/bats/evaluation_count/file2.bats | 6 +- .../bats/external_function_calls.bats | 48 +- test/fixtures/bats/external_functions.bash | 10 +- test/fixtures/bats/external_functions.bats | 4 +- .../bats/failing_with_bash_expression.bats | 2 +- test/fixtures/bats/failure_in_free_code.bats | 4 +- test/fixtures/bats/hang_after_run.bats | 10 +- test/fixtures/bats/hang_in_run.bats | 8 +- test/fixtures/bats/hang_in_setup_file.bats | 10 +- test/fixtures/bats/hang_in_teardown.bats | 10 +- test/fixtures/bats/hang_in_teardown_file.bats | 10 +- test/fixtures/bats/hang_in_test.bats | 8 +- test/fixtures/bats/issue-205.bats | 160 +++--- test/fixtures/bats/issue-433/repro1.bats | 5 +- test/fixtures/bats/issue-433/repro2.bats | 5 +- test/fixtures/bats/issue-519.bats | 4 +- test/fixtures/bats/loop_keep_IFS.bats | 2 +- test/fixtures/bats/no-final-newline.bats | 2 +- .../bats/print_output_on_failure.bats | 8 +- .../print_output_on_failure_with_stderr.bats | 10 +- test/fixtures/bats/read_from_stdin.bats | 22 +- test/fixtures/bats/retry.bats | 28 +- test/fixtures/bats/run_long_command.bats | 4 +- .../bats/set_-eu_in_setup_and_teardown.bats | 14 +- test/fixtures/bats/setup.bats | 2 +- .../bats/show-output-of-passing-tests.bats | 4 +- .../fixtures/bats/sigint_in_failing_test.bats | 14 +- .../bats/single_line_no_shellcheck.bats | 4 +- test/fixtures/bats/tab in filename.bats | 2 +- test/fixtures/bats/teardown.bats | 2 +- .../bats/teardown_file_override_status.bats | 10 +- .../bats/teardown_override_status.bats | 8 +- .../setup_suite.bash | 10 +- .../teardown_suite_override_status/test.bats | 4 +- test/fixtures/bats/unbound_variable.bats | 16 +- test/fixtures/bats/verbose-run.bats | 6 +- .../bats/without_trailing_newline.bats | 2 +- .../error_in_setup_and_teardown_file.bats | 8 +- .../file_setup_teardown/no_setup_file.bats | 4 +- .../file_setup_teardown/no_teardown_file.bats | 4 +- .../file_setup_teardown/setup_file.bats | 8 +- .../file_setup_teardown/setup_file2.bats | 6 +- .../setup_file_does_not_leak_env.bats | 6 +- .../setup_file_does_not_leak_env2.bats | 4 +- ...up_file_even_if_all_tests_are_skipped.bats | 6 +- .../setup_file_failed.bats | 8 +- .../setup_file_halfway_error.bats | 10 +- .../file_setup_teardown/teardown_file.bats | 8 +- .../file_setup_teardown/teardown_file2.bats | 8 +- .../teardown_file_after_failing_test.bats | 6 +- .../teardown_file_after_long_test.bats | 8 +- .../teardown_file_does_not_leak.bats | 6 +- .../teardown_file_does_not_leak2.bats | 4 +- ...wn_file_even_if_all_tests_are_skipped.bats | 6 +- .../teardown_file_failed.bats | 7 +- .../teardown_file_halfway_error.bats | 10 +- test/fixtures/formatter/dummy-formatter | 4 +- .../duplicate/first/file1.bats | 4 +- .../duplicate/second/file1.bats | 4 +- test/fixtures/junit-formatter/issue_360.bats | 20 +- test/fixtures/junit-formatter/issue_531.bats | 14 +- test/fixtures/junit-formatter/skipped.bats | 2 +- .../fixtures/junit-formatter/suite/file1.bats | 4 +- .../fixtures/junit-formatter/suite/file2.bats | 4 +- test/fixtures/junit-formatter/xml-escape.bats | 2 +- .../load/failing_bats_load_library.bats | 2 +- test/fixtures/load/failing_load.bats | 2 +- test/fixtures/load/find_library_helper.bats | 6 +- .../load/find_library_helper_err.bats | 4 +- .../load/load_in_teardown_after_failure.bats | 6 +- .../file1.bats | 12 +- .../file2.bats | 22 +- .../must_not_parallelize_within_file.bats | 62 +-- .../parallel-preserve-environment.bats | 8 +- test/fixtures/parallel/parallel.bats | 6 +- test/fixtures/parallel/parallel_factor.bats | 4 +- .../parallel/setup_file/setup_file.bats | 12 +- test/fixtures/parallel/suite/parallel1.bats | 6 +- test/fixtures/run/failing.bats | 2 +- test/fixtures/run/invalid.bats | 2 +- .../override_BATS_FILE_EXTENSION/test.bats | 2 +- .../skip/skip-in-setup-and-teardown.bats | 6 +- test/fixtures/suite/skip/skip-in-setup.bats | 2 +- .../fixtures/suite/skip/skip-in-teardown.bats | 2 +- .../suite/skip/skip-in-test-and-teardown.bats | 4 +- test/fixtures/suite/skip/skip-in-test.bats | 2 +- test/fixtures/suite/test_number/file1.bats | 16 +- test/fixtures/suite/test_number/file2.bats | 20 +- .../call_load/setup_suite.bash | 4 +- .../suite_setup_teardown/call_load/test.bats | 4 +- .../call_load/test_helper.bash | 1 + .../default_name/setup_suite.bash | 6 +- .../default_name/test.bats | 4 +- .../error_in_free_code/setup_suite.bash | 4 +- .../error_in_free_code/test.bats | 2 +- .../error_in_setup_suite/setup_suite.bash | 4 +- .../error_in_setup_suite/test.bats | 2 +- .../error_in_teardown_suite/setup_suite.bash | 6 +- .../error_in_teardown_suite/test.bats | 2 +- .../exported_vars/setup_suite.bash | 4 +- .../exported_vars/test.bats | 8 +- .../failure_in_setup_suite/setup_suite.bash | 10 +- .../failure_in_setup_suite/test.bats | 2 +- .../setup_suite.bash | 10 +- .../failure_in_teardown_suite/test.bats | 2 +- .../no_failure_no_output/setup_suite.bash | 6 +- .../no_failure_no_output/test.bats | 4 +- .../no_setup_suite_function/setup_suite.bash | 4 +- .../no_setup_suite_function/test.bats | 4 +- .../setup_suite_non_default.bash | 6 +- .../non_default_name/test.bats | 4 +- .../output_with_failure/setup_suite.bash | 8 +- .../output_with_failure/test.bats | 4 +- .../pick_up_toplevel/folder1/test.bats | 4 +- .../pick_up_toplevel/folder2/test.bats | 4 +- .../pick_up_toplevel/setup_suite.bash | 6 +- .../pick_up_toplevel/test.bats | 4 +- .../setup_suite.bash | 10 +- .../test.bats | 2 +- .../setup_suite.bash | 12 +- .../stderr_in_setup_teardown_suite/test.bats | 4 +- .../syntax_error/test.bats | 2 +- test/fixtures/tagging/invalid_tags.bats | 4 +- test/fixtures/tagging/tagged.bats | 10 +- test/fixtures/tagging/trimming.bats | 4 +- test/fixtures/timeout/sleep2.bats | 4 +- test/fixtures/warnings/BW01.bats | 8 +- .../warnings/BW01_check_exit_code_is_127.bats | 6 +- ...1_no_exit_code_check_no_exit_code_127.bats | 4 +- test/fixtures/warnings/BW02.bats | 4 +- .../define_setup_suite_in_wrong_file.bats | 6 +- .../BW03/non_default_setup_suite.bash | 4 +- .../warnings/BW03/suppress_warning.bats | 6 +- test/formatter.bats | 12 +- test/junit-formatter.bats | 28 +- test/load.bats | 18 +- test/parallel.bats | 45 +- test/pretty-formatter.bats | 26 +- test/root.bats | 14 +- test/run.bats | 98 ++-- test/suite.bats | 4 +- test/suite_setup_teardown.bats | 169 +++--- test/tagging.bats | 90 ++-- test/tap13-formatter.bats | 80 +-- test/test_helper.bash | 2 +- test/timeout.bats | 32 +- test/trace.bats | 126 ++--- test/warnings.bats | 104 ++-- 180 files changed, 2375 insertions(+), 2269 deletions(-) diff --git a/.github/workflows/check_pr_label.sh b/.github/workflows/check_pr_label.sh index 197335bd15..2ff5723c71 100755 --- a/.github/workflows/check_pr_label.sh +++ b/.github/workflows/check_pr_label.sh @@ -1,7 +1,7 @@ #!/usr/bin/bash get_pr_json() { - curl -s -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/bats-core/bats-core/pulls/$1" + curl -s -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/bats-core/bats-core/pulls/$1" } PR_NUMBER="$1" diff --git a/bin/bats b/bin/bats index 1f7ce2e970..892470c1e8 100755 --- a/bin/bats +++ b/bin/bats @@ -26,8 +26,8 @@ fallback_to_readlinkf_posix() { while [ "$max_symlinks" -ge 0 ] && max_symlinks=$((max_symlinks - 1)); do if [ ! "$target" = "${target%/*}" ]; then case $target in - /*) cd -P "${target%/*}/" 2>/dev/null || break ;; - *) cd -P "./${target%/*}" 2>/dev/null || break ;; + /*) cd -P "${target%/*}/" 2>/dev/null || break ;; + *) cd -P "./${target%/*}" 2>/dev/null || break ;; esac target=${target##*/} fi diff --git a/contrib/release.sh b/contrib/release.sh index 69b7724438..2e4805e1f0 100755 --- a/contrib/release.sh +++ b/contrib/release.sh @@ -65,14 +65,14 @@ git commit -m "feat: release Bats v${NEW_BATS_VERSION}" # changelog start EOF -local DELIM -DELIM=$(echo -en "\001"); -sed -E -n "\\${DELIM}^## \[${NEW_BATS_VERSION}\]${DELIM},\\${DELIM}^## ${DELIM}p" docs/CHANGELOG.md \ - | head -n -1 \ - | sed -E \ - -e 's,^## \[([0-9\.]+)] - (.*),Bats \1\n\nReleased: \2,' \ - -e 's,^### (.*),\1:,g' \ - | tee "${BATS_RELEASE_NOTES}" + local DELIM + DELIM=$(echo -en "\001") + sed -E -n "\\${DELIM}^## \[${NEW_BATS_VERSION}\]${DELIM},\\${DELIM}^## ${DELIM}p" docs/CHANGELOG.md | + head -n -1 | + sed -E \ + -e 's,^## \[([0-9\.]+)] - (.*),Bats \1\n\nReleased: \2,' \ + -e 's,^### (.*),\1:,g' | + tee "${BATS_RELEASE_NOTES}" cat < $2 ]] && { echo 1 ; return ; } - echo 0 + [[ $1 < $2 ]] && { + echo -1 + return + } + [[ $1 > $2 ]] && { + echo 1 + return + } + echo 0 } # given two (named) arrays containing NAT and/or ALPHANUM fields, compare them @@ -126,33 +138,56 @@ function order-string { # is considered greater-than the shorter if the shorter is a prefix of the longer. # function compare-fields { - local l="$1[@]" - local r="$2[@]" - local leftfield=( "${!l}" ) - local rightfield=( "${!r}" ) - local left - local right - - local i=$(( -1 )) - local order=$(( 0 )) - - while true - do - [ $order -ne 0 ] && { echo $order ; return ; } - - : $(( i++ )) - left="${leftfield[$i]}" - right="${rightfield[$i]}" - - is-null "$left" && is-null "$right" && { echo 0 ; return ; } - is-null "$left" && { echo -1 ; return ; } - is-null "$right" && { echo 1 ; return ; } - - is-nat "$left" && is-nat "$right" && { order=$(order-nat "$left" "$right") ; continue ; } - is-nat "$left" && { echo -1 ; return ; } - is-nat "$right" && { echo 1 ; return ; } - { order=$(order-string "$left" "$right") ; continue ; } - done + local l="$1[@]" + local r="$2[@]" + local leftfield=("${!l}") + local rightfield=("${!r}") + local left + local right + + local i=$((-1)) + local order=$((0)) + + while true; do + [ $order -ne 0 ] && { + echo $order + return + } + + : $((i++)) + left="${leftfield[$i]}" + right="${rightfield[$i]}" + + is-null "$left" && is-null "$right" && { + echo 0 + return + } + is-null "$left" && { + echo -1 + return + } + is-null "$right" && { + echo 1 + return + } + + is-nat "$left" && is-nat "$right" && { + order=$(order-nat "$left" "$right") + continue + } + is-nat "$left" && { + echo -1 + return + } + is-nat "$right" && { + echo 1 + return + } + { + order=$(order-string "$left" "$right") + continue + } + done } # shellcheck disable=SC2206 # checked by "validate"; ok to expand prerel id's into array @@ -163,25 +198,37 @@ function compare-version { # compare major, minor, patch - local left=( "${V[0]}" "${V[1]}" "${V[2]}" ) - local right=( "${V_[0]}" "${V_[1]}" "${V_[2]}" ) + local left=("${V[0]}" "${V[1]}" "${V[2]}") + local right=("${V_[0]}" "${V_[1]}" "${V_[2]}") order=$(compare-fields left right) - [ "$order" -ne 0 ] && { echo "$order" ; return ; } + [ "$order" -ne 0 ] && { + echo "$order" + return + } # compare pre-release ids when M.m.p are equal local prerel="${V[3]:1}" local prerel_="${V_[3]:1}" - local left=( ${prerel//./ } ) - local right=( ${prerel_//./ } ) + local left=(${prerel//./ }) + local right=(${prerel_//./ }) # if left and right have no pre-release part, then left equals right # if only one of left/right has pre-release part, that one is less than simple M.m.p - [ -z "$prerel" ] && [ -z "$prerel_" ] && { echo 0 ; return ; } - [ -z "$prerel" ] && { echo 1 ; return ; } - [ -z "$prerel_" ] && { echo -1 ; return ; } + [ -z "$prerel" ] && [ -z "$prerel_" ] && { + echo 0 + return + } + [ -z "$prerel" ] && { + echo 1 + return + } + [ -z "$prerel_" ] && { + echo -1 + return + } # otherwise, compare the pre-release id's @@ -189,18 +236,27 @@ function compare-version { } function command-bump { - local new; local version; local sub_version; local command; + local new + local version + local sub_version + local command case $# in - 2) case $1 in - major|minor|patch|release) command=$1; version=$2;; - *) usage-help;; - esac ;; - 3) case $1 in - prerel|build) command=$1; sub_version=$2 version=$3 ;; - *) usage-help;; - esac ;; - *) usage-help;; + 2) case $1 in + major | minor | patch | release) + command=$1 + version=$2 + ;; + *) usage-help ;; + esac ;; + 3) case $1 in + prerel | build) + command=$1 + sub_version=$2 version=$3 + ;; + *) usage-help ;; + esac ;; + *) usage-help ;; esac validate-version "$version" parts @@ -212,13 +268,13 @@ function command-bump { local build="${parts[4]}" case "$command" in - major) new="$((major + 1)).0.0";; - minor) new="${major}.$((minor + 1)).0";; - patch) new="${major}.${minor}.$((patch + 1))";; - release) new="${major}.${minor}.${patch}";; - prerel) new=$(validate-version "${major}.${minor}.${patch}-${sub_version}");; - build) new=$(validate-version "${major}.${minor}.${patch}${prere}+${sub_version}");; - *) usage-help ;; + major) new="$((major + 1)).0.0" ;; + minor) new="${major}.$((minor + 1)).0" ;; + patch) new="${major}.${minor}.$((patch + 1))" ;; + release) new="${major}.${minor}.${patch}" ;; + prerel) new=$(validate-version "${major}.${minor}.${patch}-${sub_version}") ;; + build) new=$(validate-version "${major}.${minor}.${patch}${prere}+${sub_version}") ;; + *) usage-help ;; esac echo "$new" @@ -226,56 +282,77 @@ function command-bump { } function command-compare { - local v; local v_; + local v + local v_ case $# in - 2) v=$(validate-version "$1"); v_=$(validate-version "$2") ;; - *) usage-help ;; + 2) + v=$(validate-version "$1") + v_=$(validate-version "$2") + ;; + *) usage-help ;; esac - set +u # need unset array element to evaluate to null + set +u # need unset array element to evaluate to null compare-version "$v" "$v_" exit 0 } - # shellcheck disable=SC2034 function command-get { - local part version + local part version - if [[ "$#" -ne "2" ]] || [[ -z "$1" ]] || [[ -z "$2" ]]; then - usage-help - exit 0 - fi + if [[ "$#" -ne "2" ]] || [[ -z "$1" ]] || [[ -z "$2" ]]; then + usage-help + exit 0 + fi - part="$1" - version="$2" + part="$1" + version="$2" - validate-version "$version" parts - local major="${parts[0]}" - local minor="${parts[1]}" - local patch="${parts[2]}" - local prerel="${parts[3]:1}" - local build="${parts[4]:1}" - local release="${major}.${minor}.${patch}" + validate-version "$version" parts + local major="${parts[0]}" + local minor="${parts[1]}" + local patch="${parts[2]}" + local prerel="${parts[3]:1}" + local build="${parts[4]:1}" + local release="${major}.${minor}.${patch}" - case "$part" in - major|minor|patch|release|prerel|build) echo "${!part}" ;; - *) usage-help ;; - esac + case "$part" in + major | minor | patch | release | prerel | build) echo "${!part}" ;; + *) usage-help ;; + esac - exit 0 + exit 0 } case $# in - 0) echo "Unknown command: $*"; usage-help;; +0) + echo "Unknown command: $*" + usage-help + ;; esac case $1 in - --help|-h) echo -e "$USAGE"; exit 0;; - --version|-v) usage-version ;; - bump) shift; command-bump "$@";; - get) shift; command-get "$@";; - compare) shift; command-compare "$@";; - *) echo "Unknown arguments: $*"; usage-help;; +--help | -h) + echo -e "$USAGE" + exit 0 + ;; +--version | -v) usage-version ;; +bump) + shift + command-bump "$@" + ;; +get) + shift + command-get "$@" + ;; +compare) + shift + command-compare "$@" + ;; +*) + echo "Unknown arguments: $*" + usage-help + ;; esac diff --git a/docker/install_tini.sh b/docker/install_tini.sh index cd4f419cf2..8d98da14c6 100755 --- a/docker/install_tini.sh +++ b/docker/install_tini.sh @@ -3,18 +3,18 @@ set -e case ${1#linux/} in - 386) - TINI_PLATFORM=i386 - ;; - arm/v7) - TINI_PLATFORM=armhf - ;; - arm/v6) - TINI_PLATFORM=armel - ;; - *) - TINI_PLATFORM=${1#linux/} - ;; +386) + TINI_PLATFORM=i386 + ;; +arm/v7) + TINI_PLATFORM=armhf + ;; +arm/v6) + TINI_PLATFORM=armel + ;; +*) + TINI_PLATFORM=${1#linux/} + ;; esac echo "Installing tini for $TINI_PLATFORM" @@ -25,6 +25,6 @@ wget "https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-sta chmod +x /tini apk add gnupg -gpg --import < /tmp/docker/tini.pubkey.gpg +gpg --import - printf -v "$1" -- "%s%s%s" "$BATS_BEGIN_CODE_QUOTE" "$2" "$BATS_END_CODE_QUOTE" + printf -v "$1" -- "%s%s%s" "$BATS_BEGIN_CODE_QUOTE" "$2" "$BATS_END_CODE_QUOTE" } bats_check_valid_version() { @@ -36,13 +36,13 @@ bats_version_lt() { # bats_check_valid_version "$2" local -a version1_parts version2_parts - IFS=. read -ra version1_parts <<< "$1" - IFS=. read -ra version2_parts <<< "$2" + IFS=. read -ra version1_parts <<<"$1" + IFS=. read -ra version2_parts <<<"$2" for i in {0..2}; do - if (( version1_parts[i] < version2_parts[i] )); then + if ((version1_parts[i] < version2_parts[i])); then return 0 - elif (( version1_parts[i] > version2_parts[i] )); then + elif ((version1_parts[i] > version2_parts[i])); then return 1 fi done @@ -71,16 +71,16 @@ bats_binary_search() { # fi local -r search_value=$1 array_name=$2 - + # we'd like to test if array is set but we cannot distinguish unset from empty arrays, so we need to skip that - local start=0 mid end mid_value + local start=0 mid end mid_value # start is inclusive, end is exclusive ... eval "end=\${#${array_name}[@]}" # so start == end means empty search space - while (( start < end )); do - mid=$(( (start + end) / 2 )) + while ((start < end)); do + mid=$(((start + end) / 2)) eval "mid_value=\${${array_name}[$mid]}" if [[ "$mid_value" == "$search_value" ]]; then return 0 @@ -103,20 +103,20 @@ bats_sort() { # local -r result_name=$1 shift - if (( $# == 0 )); then + if (($# == 0)); then eval "$result_name=()" return 0 fi local -a sorted_array=() local -i j i=0 - for (( j=1; j <= $#; ++j )); do - for ((i=${#sorted_array[@]}; i >= 0; --i )); do - if [[ $i -eq 0 || ${sorted_array[$((i-1))]} < ${!j} ]]; then + for ((j = 1; j <= $#; ++j)); do + for ((i = ${#sorted_array[@]}; i >= 0; --i)); do + if [[ $i -eq 0 || ${sorted_array[$((i - 1))]} < ${!j} ]]; then sorted_array[$i]=${!j} break else - sorted_array[$i]=${sorted_array[$((i-1))]} + sorted_array[$i]=${sorted_array[$((i - 1))]} fi done done @@ -132,12 +132,12 @@ bats_all_in() { # local -i haystack_length # just to appease shellcheck eval "local -r haystack_length=\${#${haystack_array}[@]}" - - local -i haystack_index=0 # initialize only here to continue from last search position + + local -i haystack_index=0 # initialize only here to continue from last search position local search_value haystack_value # just to appease shellcheck - for (( i=1; i <= $#; ++i )); do + for ((i = 1; i <= $#; ++i)); do eval "local search_value=${!i}" - for ((; haystack_index < haystack_length; ++haystack_index)); do + for (( ; haystack_index < haystack_length; ++haystack_index)); do eval "local haystack_value=\${${haystack_array}[$haystack_index]}" if [[ $haystack_value > "$search_value" ]]; then # we passed the location this value would have been at -> not found @@ -161,12 +161,12 @@ bats_any_in() { # local -i haystack_length # just to appease shellcheck eval "local -r haystack_length=\${#${haystack_array}[@]}" - - local -i haystack_index=0 # initialize only here to continue from last search position + + local -i haystack_index=0 # initialize only here to continue from last search position local search_value haystack_value # just to appease shellcheck - for (( i=1; i <= $#; ++i )); do + for ((i = 1; i <= $#; ++i)); do eval "local search_value=${!i}" - for ((; haystack_index < haystack_length; ++haystack_index)); do + for (( ; haystack_index < haystack_length; ++haystack_index)); do eval "local haystack_value=\${${haystack_array}[$haystack_index]}" if [[ $haystack_value > "$search_value" ]]; then continue 2 # search value not in array! -> try next @@ -180,7 +180,7 @@ bats_any_in() { # return 1 } -bats_trim () { # +bats_trim() { # local -r bats_trim_ltrimmed=${2#"${2%%[![:space:]]*}"} # cut off leading whitespace # shellcheck disable=SC2034 # used in eval! local -r bats_trim_trimmed=${bats_trim_ltrimmed%"${bats_trim_ltrimmed##*[![:space:]]}"} # cut off trailing whitespace @@ -188,9 +188,9 @@ bats_trim () { # } # a helper function to work around unbound variable errors with ${arr[@]} on Bash 3 -bats_append_arrays_as_args () { # -- +bats_append_arrays_as_args() { # -- local -a trailing_args=() - while (( $# > 0)) && [[ $1 != -- ]]; do + while (($# > 0)) && [[ $1 != -- ]]; do local array=$1 shift @@ -198,14 +198,14 @@ bats_append_arrays_as_args () { # -- eval "trailing_args+=(\"\${${array}[@]}\")" fi done - shift # remove -- separator + shift # remove -- separator - if (( $# == 0 )); then + if (($# == 0)); then printf "Error: append_arrays_as_args is missing a command or -- separator\n" >&2 return 1 fi - if (( ${#trailing_args[@]} > 0 )); then + if ((${#trailing_args[@]} > 0)); then "$@" "${trailing_args[@]}" else "$@" diff --git a/lib/bats-core/formatter.bash b/lib/bats-core/formatter.bash index 10f8e930c0..b774e16730 100644 --- a/lib/bats-core/formatter.bash +++ b/lib/bats-core/formatter.bash @@ -3,7 +3,7 @@ # reads (extended) bats tap streams from stdin and calls callback functions for each line # # Segmenting functions -# ==================== +# ==================== # bats_tap_stream_plan -> when the test plan is encountered # bats_tap_stream_suite -> when a new file is begun WARNING: extended only # bats_tap_stream_begin -> when a new test is begun WARNING: extended only @@ -18,126 +18,126 @@ # # Context functions # ================= -# bats_tap_stream_comment -> when a comment line was encountered, +# bats_tap_stream_comment -> when a comment line was encountered, # scope tells the last encountered of plan, begin, ok, not_ok, skipped, suite # bats_tap_stream_unknown -> when a line is encountered that does not match the previous entries, # scope @see bats_tap_stream_comment # forwards all input as is, when there is no TAP test plan header function bats_parse_internal_extended_tap() { - local header_pattern='[0-9]+\.\.[0-9]+' - IFS= read -r header + local header_pattern='[0-9]+\.\.[0-9]+' + IFS= read -r header - if [[ "$header" =~ $header_pattern ]]; then - bats_tap_stream_plan "${header:3}" - else - # If the first line isn't a TAP plan, print it and pass the rest through - printf '%s\n' "$header" - exec cat - fi + if [[ "$header" =~ $header_pattern ]]; then + bats_tap_stream_plan "${header:3}" + else + # If the first line isn't a TAP plan, print it and pass the rest through + printf '%s\n' "$header" + exec cat + fi - ok_line_regexpr="ok ([0-9]+) (.*)" - skip_line_regexpr="ok ([0-9]+) (.*) # skip( (.*))?$" - timeout_line_regexpr="not ok ([0-9]+) (.*) # timeout after ([0-9]+)s$" - not_ok_line_regexpr="not ok ([0-9]+) (.*)" + ok_line_regexpr="ok ([0-9]+) (.*)" + skip_line_regexpr="ok ([0-9]+) (.*) # skip( (.*))?$" + timeout_line_regexpr="not ok ([0-9]+) (.*) # timeout after ([0-9]+)s$" + not_ok_line_regexpr="not ok ([0-9]+) (.*)" - timing_expr="in ([0-9]+)ms$" - local test_name begin_index ok_index not_ok_index index scope - begin_index=0 - index=0 - scope=plan - while IFS= read -r line; do - unset BATS_FORMATTER_TEST_DURATION BATS_FORMATTER_TEST_TIMEOUT - case "$line" in - 'begin '*) # this might only be called in extended tap output - ((++begin_index)) - scope=begin - test_name="${line#* "$begin_index" }" - bats_tap_stream_begin "$begin_index" "$test_name" - ;; - 'ok '*) - ((++index)) - if [[ "$line" =~ $ok_line_regexpr ]]; then - ok_index="${BASH_REMATCH[1]}" - test_name="${BASH_REMATCH[2]}" - if [[ "$line" =~ $skip_line_regexpr ]]; then - scope=skipped - test_name="${BASH_REMATCH[2]}" # cut off name before "# skip" - local skip_reason="${BASH_REMATCH[4]}" - if [[ "$test_name" =~ $timing_expr ]]; then - local BATS_FORMATTER_TEST_DURATION="${BASH_REMATCH[1]}" - test_name="${test_name% in "${BATS_FORMATTER_TEST_DURATION}"ms}" - bats_tap_stream_skipped "$ok_index" "$test_name" "$skip_reason" - else - bats_tap_stream_skipped "$ok_index" "$test_name" "$skip_reason" - fi - else - scope=ok - if [[ "$line" =~ $timing_expr ]]; then - local BATS_FORMATTER_TEST_DURATION="${BASH_REMATCH[1]}" - bats_tap_stream_ok "$ok_index" "${test_name% in "${BASH_REMATCH[1]}"ms}" - else - bats_tap_stream_ok "$ok_index" "$test_name" - fi - fi - else - printf "ERROR: could not match ok line: %s" "$line" >&2 - exit 1 - fi - ;; - 'not ok '*) - ((++index)) - scope=not_ok - if [[ "$line" =~ $not_ok_line_regexpr ]]; then - not_ok_index="${BASH_REMATCH[1]}" - test_name="${BASH_REMATCH[2]}" - if [[ "$line" =~ $timeout_line_regexpr ]]; then - not_ok_index="${BASH_REMATCH[1]}" - test_name="${BASH_REMATCH[2]}" - # shellcheck disable=SC2034 # used in bats_tap_stream_ok - local BATS_FORMATTER_TEST_TIMEOUT="${BASH_REMATCH[3]}" - fi - if [[ "$test_name" =~ $timing_expr ]]; then - # shellcheck disable=SC2034 # used in bats_tap_stream_ok - local BATS_FORMATTER_TEST_DURATION="${BASH_REMATCH[1]}" - test_name="${test_name% in "${BASH_REMATCH[1]}"ms}" - fi - bats_tap_stream_not_ok "$not_ok_index" "$test_name" - else - printf "ERROR: could not match not ok line: %s" "$line" >&2 - exit 1 - fi - ;; - '# '*) - bats_tap_stream_comment "${line:2}" "$scope" - ;; - '#') - bats_tap_stream_comment "" "$scope" - ;; - 'suite '*) - scope=suite - # pass on the - bats_tap_stream_suite "${line:6}" - ;; - *) - bats_tap_stream_unknown "$line" "$scope" - ;; - esac - done + timing_expr="in ([0-9]+)ms$" + local test_name begin_index ok_index not_ok_index index scope + begin_index=0 + index=0 + scope=plan + while IFS= read -r line; do + unset BATS_FORMATTER_TEST_DURATION BATS_FORMATTER_TEST_TIMEOUT + case "$line" in + 'begin '*) # this might only be called in extended tap output + ((++begin_index)) + scope=begin + test_name="${line#* "$begin_index" }" + bats_tap_stream_begin "$begin_index" "$test_name" + ;; + 'ok '*) + ((++index)) + if [[ "$line" =~ $ok_line_regexpr ]]; then + ok_index="${BASH_REMATCH[1]}" + test_name="${BASH_REMATCH[2]}" + if [[ "$line" =~ $skip_line_regexpr ]]; then + scope=skipped + test_name="${BASH_REMATCH[2]}" # cut off name before "# skip" + local skip_reason="${BASH_REMATCH[4]}" + if [[ "$test_name" =~ $timing_expr ]]; then + local BATS_FORMATTER_TEST_DURATION="${BASH_REMATCH[1]}" + test_name="${test_name% in "${BATS_FORMATTER_TEST_DURATION}"ms}" + bats_tap_stream_skipped "$ok_index" "$test_name" "$skip_reason" + else + bats_tap_stream_skipped "$ok_index" "$test_name" "$skip_reason" + fi + else + scope=ok + if [[ "$line" =~ $timing_expr ]]; then + local BATS_FORMATTER_TEST_DURATION="${BASH_REMATCH[1]}" + bats_tap_stream_ok "$ok_index" "${test_name% in "${BASH_REMATCH[1]}"ms}" + else + bats_tap_stream_ok "$ok_index" "$test_name" + fi + fi + else + printf "ERROR: could not match ok line: %s" "$line" >&2 + exit 1 + fi + ;; + 'not ok '*) + ((++index)) + scope=not_ok + if [[ "$line" =~ $not_ok_line_regexpr ]]; then + not_ok_index="${BASH_REMATCH[1]}" + test_name="${BASH_REMATCH[2]}" + if [[ "$line" =~ $timeout_line_regexpr ]]; then + not_ok_index="${BASH_REMATCH[1]}" + test_name="${BASH_REMATCH[2]}" + # shellcheck disable=SC2034 # used in bats_tap_stream_ok + local BATS_FORMATTER_TEST_TIMEOUT="${BASH_REMATCH[3]}" + fi + if [[ "$test_name" =~ $timing_expr ]]; then + # shellcheck disable=SC2034 # used in bats_tap_stream_ok + local BATS_FORMATTER_TEST_DURATION="${BASH_REMATCH[1]}" + test_name="${test_name% in "${BASH_REMATCH[1]}"ms}" + fi + bats_tap_stream_not_ok "$not_ok_index" "$test_name" + else + printf "ERROR: could not match not ok line: %s" "$line" >&2 + exit 1 + fi + ;; + '# '*) + bats_tap_stream_comment "${line:2}" "$scope" + ;; + '#') + bats_tap_stream_comment "" "$scope" + ;; + 'suite '*) + scope=suite + # pass on the + bats_tap_stream_suite "${line:6}" + ;; + *) + bats_tap_stream_unknown "$line" "$scope" + ;; + esac + done } normalize_base_path() { # - # the relative path root to use for reporting filenames - # this is mainly intended for suite mode, where this will be the suite root folder - local base_path="$2" - # use the containing directory when --base-path is a file - if [[ ! -d "$base_path" ]]; then - base_path="$(dirname "$base_path")" - fi - # get the absolute path - base_path="$(cd "$base_path" && pwd)" - # ensure the path ends with / to strip that later on - if [[ "${base_path}" != *"/" ]]; then - base_path="$base_path/" - fi - printf -v "$1" "%s" "$base_path" + # the relative path root to use for reporting filenames + # this is mainly intended for suite mode, where this will be the suite root folder + local base_path="$2" + # use the containing directory when --base-path is a file + if [[ ! -d "$base_path" ]]; then + base_path="$(dirname "$base_path")" + fi + # get the absolute path + base_path="$(cd "$base_path" && pwd)" + # ensure the path ends with / to strip that later on + if [[ "${base_path}" != *"/" ]]; then + base_path="$base_path/" + fi + printf -v "$1" "%s" "$base_path" } diff --git a/lib/bats-core/preprocessing.bash b/lib/bats-core/preprocessing.bash index 806caa3444..5d9a7652c6 100644 --- a/lib/bats-core/preprocessing.bash +++ b/lib/bats-core/preprocessing.bash @@ -6,17 +6,17 @@ BATS_PARENT_TMPNAME="$BATS_RUN_TMPDIR/bats.$PPID" BATS_OUT="${BATS_TMPNAME}.out" # used in bats-exec-file bats_preprocess_source() { - # export to make it visible to bats_evaluate_preprocessed_source - # since the latter runs in bats-exec-test's bash while this runs in bats-exec-file's - export BATS_TEST_SOURCE="${BATS_TMPNAME}.src" - CHECK_BATS_COMMENT_COMMANDS=1 bats-preprocess "$BATS_TEST_FILENAME" >"$BATS_TEST_SOURCE" + # export to make it visible to bats_evaluate_preprocessed_source + # since the latter runs in bats-exec-test's bash while this runs in bats-exec-file's + export BATS_TEST_SOURCE="${BATS_TMPNAME}.src" + CHECK_BATS_COMMENT_COMMANDS=1 bats-preprocess "$BATS_TEST_FILENAME" >"$BATS_TEST_SOURCE" } bats_evaluate_preprocessed_source() { - if [[ -z "${BATS_TEST_SOURCE:-}" ]]; then - BATS_TEST_SOURCE="${BATS_PARENT_TMPNAME}.src" - fi - # Dynamically loaded user files provided outside of Bats. - # shellcheck disable=SC1090 - source "$BATS_TEST_SOURCE" + if [[ -z "${BATS_TEST_SOURCE:-}" ]]; then + BATS_TEST_SOURCE="${BATS_PARENT_TMPNAME}.src" + fi + # Dynamically loaded user files provided outside of Bats. + # shellcheck disable=SC1090 + source "$BATS_TEST_SOURCE" } diff --git a/lib/bats-core/semaphore.bash b/lib/bats-core/semaphore.bash index 48ff185fd4..e299293c76 100644 --- a/lib/bats-core/semaphore.bash +++ b/lib/bats-core/semaphore.bash @@ -2,31 +2,31 @@ # setup the semaphore environment for the loading file bats_semaphore_setup() { - export -f bats_semaphore_get_free_slot_count - export -f bats_semaphore_acquire_while_locked - export BATS_SEMAPHORE_DIR="$BATS_RUN_TMPDIR/semaphores" + export -f bats_semaphore_get_free_slot_count + export -f bats_semaphore_acquire_while_locked + export BATS_SEMAPHORE_DIR="$BATS_RUN_TMPDIR/semaphores" - if command -v flock >/dev/null; then + if command -v flock >/dev/null; then bats_run_under_lock() { - flock "$BATS_SEMAPHORE_DIR" "$@" + flock "$BATS_SEMAPHORE_DIR" "$@" } - elif command -v shlock >/dev/null; then - bats_run_under_lock() { - local lockfile="$BATS_SEMAPHORE_DIR/shlock.lock" - while ! shlock -p $$ -f "$lockfile"; do - sleep 1 - done - # we got the lock now, execute the command - "$@" - local status=$? - # free the lock - rm -f "$lockfile" - return $status - } - else - printf "ERROR: flock/shlock is required for parallelization within files!\n" >&2 - exit 1 - fi + elif command -v shlock >/dev/null; then + bats_run_under_lock() { + local lockfile="$BATS_SEMAPHORE_DIR/shlock.lock" + while ! shlock -p $$ -f "$lockfile"; do + sleep 1 + done + # we got the lock now, execute the command + "$@" + local status=$? + # free the lock + rm -f "$lockfile" + return $status + } + else + printf "ERROR: flock/shlock is required for parallelization within files!\n" >&2 + exit 1 + fi } # $1 - output directory for stdout/stderr @@ -36,72 +36,72 @@ bats_semaphore_setup() { # when there is a free slot, run the command in background # gather the output of the command in files in the given directory bats_semaphore_run() { - local output_dir=$1 - shift - local semaphore_slot - semaphore_slot=$(bats_semaphore_acquire_slot) - bats_semaphore_release_wrapper "$output_dir" "$semaphore_slot" "$@" & - printf "%d\n" "$!" + local output_dir=$1 + shift + local semaphore_slot + semaphore_slot=$(bats_semaphore_acquire_slot) + bats_semaphore_release_wrapper "$output_dir" "$semaphore_slot" "$@" & + printf "%d\n" "$!" } # $1 - output directory for stdout/stderr # $@ - command to run # this wraps the actual function call to install some traps on exiting bats_semaphore_release_wrapper() { - local output_dir="$1" - local semaphore_name="$2" - shift 2 # all other parameters will be use for the command to execute + local output_dir="$1" + local semaphore_name="$2" + shift 2 # all other parameters will be use for the command to execute - # shellcheck disable=SC2064 # we want to expand the semaphore_name right now! - trap "status=$?; bats_semaphore_release_slot '$semaphore_name'; exit $status" EXIT + # shellcheck disable=SC2064 # we want to expand the semaphore_name right now! + trap "status=$?; bats_semaphore_release_slot '$semaphore_name'; exit $status" EXIT - mkdir -p "$output_dir" - "$@" 2>"$output_dir/stderr" >"$output_dir/stdout" - local status=$? + mkdir -p "$output_dir" + "$@" 2>"$output_dir/stderr" >"$output_dir/stdout" + local status=$? - # bash bug: the exit trap is not called for the background process - bats_semaphore_release_slot "$semaphore_name" - trap - EXIT # avoid calling release twice - return $status + # bash bug: the exit trap is not called for the background process + bats_semaphore_release_slot "$semaphore_name" + trap - EXIT # avoid calling release twice + return $status } bats_semaphore_acquire_while_locked() { - if [[ $(bats_semaphore_get_free_slot_count) -gt 0 ]]; then - local slot=0 - while [[ -e "$BATS_SEMAPHORE_DIR/slot-$slot" ]]; do - (( ++slot )) - done - if [[ $slot -lt $BATS_SEMAPHORE_NUMBER_OF_SLOTS ]]; then - touch "$BATS_SEMAPHORE_DIR/slot-$slot" && printf "%d\n" "$slot" && return 0 - fi + if [[ $(bats_semaphore_get_free_slot_count) -gt 0 ]]; then + local slot=0 + while [[ -e "$BATS_SEMAPHORE_DIR/slot-$slot" ]]; do + ((++slot)) + done + if [[ $slot -lt $BATS_SEMAPHORE_NUMBER_OF_SLOTS ]]; then + touch "$BATS_SEMAPHORE_DIR/slot-$slot" && printf "%d\n" "$slot" && return 0 fi - return 1 + fi + return 1 } # block until a semaphore slot becomes free # prints the number of the slot that it received bats_semaphore_acquire_slot() { - mkdir -p "$BATS_SEMAPHORE_DIR" - # wait for a slot to become free - # TODO: avoid busy waiting by using signals -> this opens op prioritizing possibilities as well - while true; do - # don't lock for reading, we are fine with spuriously getting no free slot - if [[ $(bats_semaphore_get_free_slot_count) -gt 0 ]]; then - bats_run_under_lock bash -c bats_semaphore_acquire_while_locked && break - fi - sleep 1 - done + mkdir -p "$BATS_SEMAPHORE_DIR" + # wait for a slot to become free + # TODO: avoid busy waiting by using signals -> this opens op prioritizing possibilities as well + while true; do + # don't lock for reading, we are fine with spuriously getting no free slot + if [[ $(bats_semaphore_get_free_slot_count) -gt 0 ]]; then + bats_run_under_lock bash -c bats_semaphore_acquire_while_locked && break + fi + sleep 1 + done } bats_semaphore_release_slot() { - # we don't need to lock this, since only our process owns this file - # and freeing a semaphore cannot lead to conflicts with others - rm "$BATS_SEMAPHORE_DIR/slot-$1" # this will fail if we had not acquired a semaphore! + # we don't need to lock this, since only our process owns this file + # and freeing a semaphore cannot lead to conflicts with others + rm "$BATS_SEMAPHORE_DIR/slot-$1" # this will fail if we had not acquired a semaphore! } bats_semaphore_get_free_slot_count() { - # find might error out without returning something useful when a file is deleted, - # while the directory is traversed -> only continue when there was no error - until used_slots=$(find "$BATS_SEMAPHORE_DIR" -name 'slot-*' 2>/dev/null | wc -l); do :; done - echo $(( BATS_SEMAPHORE_NUMBER_OF_SLOTS - used_slots )) + # find might error out without returning something useful when a file is deleted, + # while the directory is traversed -> only continue when there was no error + until used_slots=$(find "$BATS_SEMAPHORE_DIR" -name 'slot-*' 2>/dev/null | wc -l); do :; done + echo $((BATS_SEMAPHORE_NUMBER_OF_SLOTS - used_slots)) } diff --git a/lib/bats-core/test_functions.bash b/lib/bats-core/test_functions.bash index e2d5773034..72a337f720 100644 --- a/lib/bats-core/test_functions.bash +++ b/lib/bats-core/test_functions.bash @@ -20,15 +20,15 @@ find_in_bats_lib_path() { # local library_name="${2:?}" local -a bats_lib_paths - IFS=: read -ra bats_lib_paths <<< "$BATS_LIB_PATH" + IFS=: read -ra bats_lib_paths <<<"$BATS_LIB_PATH" for path in "${bats_lib_paths[@]}"; do if [[ -f "$path/$library_name" ]]; then - printf -v "$return_var" "%s" "$path/$library_name" + printf -v "$return_var" "%s" "$path/$library_name" # A library load path was found, return return 0 elif [[ -f "$path/$library_name/load.bash" ]]; then - printf -v "$return_var" "%s" "$path/$library_name/load.bash" + printf -v "$return_var" "%s" "$path/$library_name/load.bash" # A library load path was found, return return 0 fi @@ -192,32 +192,32 @@ run() { # [!|-N] [--keep-empty-lines] [--separate-stderr] [--] &2 - return 1 - elif [[ $expected_rc -gt 255 ]]; then - printf "Usage error: run: '-NNN': NNN must be <= 255 (got: %d)\n" "$expected_rc" >&2 - return 1 - fi + -[0-9]*) + expected_rc=${1#-} + if [[ $expected_rc =~ [^0-9] ]]; then + printf "Usage error: run: '-NNN' requires numeric NNN (got: %s)\n" "$expected_rc" >&2 + return 1 + elif [[ $expected_rc -gt 255 ]]; then + printf "Usage error: run: '-NNN': NNN must be <= 255 (got: %d)\n" "$expected_rc" >&2 + return 1 + fi ;; - --keep-empty-lines) - keep_empty_lines=1 + --keep-empty-lines) + keep_empty_lines=1 ;; - --separate-stderr) - output_case="separate" + --separate-stderr) + output_case="separate" ;; - --) - shift # eat the -- before breaking away - break + --) + shift # eat the -- before breaking away + break ;; - *) - printf "Usage error: unknown flag '%s'" "$1" >&2 - return 1 + *) + printf "Usage error: unknown flag '%s'" "$1" >&2 + return 1 ;; esac shift @@ -230,13 +230,13 @@ run() { # [!|-N] [--keep-empty-lines] [--separate-stderr] [--] - local output_var="$1" path="$2" - if [[ "$output_var" != NORMALIZED_INPUT ]]; then - local NORMALIZED_INPUT - fi - if [[ $path == ?:* ]]; then - NORMALIZED_INPUT="$(cd "$path" || exit 1; pwd)" - else - NORMALIZED_INPUT="$path" - fi - printf -v "$output_var" "%s" "$NORMALIZED_INPUT" + local output_var="$1" path="$2" + if [[ "$output_var" != NORMALIZED_INPUT ]]; then + local NORMALIZED_INPUT + fi + if [[ $path == ?:* ]]; then + NORMALIZED_INPUT="$( + cd "$path" || exit 1 + pwd + )" + else + NORMALIZED_INPUT="$path" + fi + printf -v "$output_var" "%s" "$NORMALIZED_INPUT" } bats_emit_trace() { - if [[ $BATS_TRACE_LEVEL -gt 0 ]]; then - local line=${BASH_LINENO[1]} - # shellcheck disable=SC2016 - if [[ $BASH_COMMAND != '"$BATS_TEST_NAME" >> "$BATS_OUT" 2>&1 4>&1' && $BASH_COMMAND != "bats_test_begin "* ]] && # don't emit these internal calls - [[ $BASH_COMMAND != "$BATS_LAST_BASH_COMMAND" || $line != "$BATS_LAST_BASH_LINENO" ]] && - # avoid printing a function twice (at call site and at definition site) - [[ $BASH_COMMAND != "$BATS_LAST_BASH_COMMAND" || ${BASH_LINENO[2]} != "$BATS_LAST_BASH_LINENO" || ${BASH_SOURCE[3]} != "$BATS_LAST_BASH_SOURCE" ]]; then - local file="${BASH_SOURCE[2]}" # index 2: skip over bats_emit_trace and bats_debug_trap - if [[ $file == "${BATS_TEST_SOURCE}" ]]; then - file="$BATS_TEST_FILENAME" - fi - local padding='$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$' - if (( BATS_LAST_STACK_DEPTH != ${#BASH_LINENO[@]} )); then - printf '%s [%s:%d]\n' "${padding::${#BASH_LINENO[@]}-4}" "${file##*/}" "$line" >&4 - fi - printf '%s %s\n' "${padding::${#BASH_LINENO[@]}-4}" "$BASH_COMMAND" >&4 - BATS_LAST_BASH_COMMAND="$BASH_COMMAND" - BATS_LAST_BASH_LINENO="$line" - BATS_LAST_BASH_SOURCE="${BASH_SOURCE[2]}" - BATS_LAST_STACK_DEPTH="${#BASH_LINENO[@]}" - fi - fi + if [[ $BATS_TRACE_LEVEL -gt 0 ]]; then + local line=${BASH_LINENO[1]} + # shellcheck disable=SC2016 + if [[ $BASH_COMMAND != '"$BATS_TEST_NAME" >> "$BATS_OUT" 2>&1 4>&1' && $BASH_COMMAND != "bats_test_begin "* ]] && # don't emit these internal calls + [[ $BASH_COMMAND != "$BATS_LAST_BASH_COMMAND" || $line != "$BATS_LAST_BASH_LINENO" ]] && + # avoid printing a function twice (at call site and at definition site) + [[ $BASH_COMMAND != "$BATS_LAST_BASH_COMMAND" || ${BASH_LINENO[2]} != "$BATS_LAST_BASH_LINENO" || ${BASH_SOURCE[3]} != "$BATS_LAST_BASH_SOURCE" ]]; then + local file="${BASH_SOURCE[2]}" # index 2: skip over bats_emit_trace and bats_debug_trap + if [[ $file == "${BATS_TEST_SOURCE}" ]]; then + file="$BATS_TEST_FILENAME" + fi + local padding='$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$' + if ((BATS_LAST_STACK_DEPTH != ${#BASH_LINENO[@]})); then + printf '%s [%s:%d]\n' "${padding::${#BASH_LINENO[@]}-4}" "${file##*/}" "$line" >&4 + fi + printf '%s %s\n' "${padding::${#BASH_LINENO[@]}-4}" "$BASH_COMMAND" >&4 + BATS_LAST_BASH_COMMAND="$BASH_COMMAND" + BATS_LAST_BASH_LINENO="$line" + BATS_LAST_BASH_SOURCE="${BASH_SOURCE[2]}" + BATS_LAST_STACK_DEPTH="${#BASH_LINENO[@]}" + fi + fi } # bats_debug_trap tracks the last line of code executed within a test. This is @@ -242,33 +245,33 @@ bats_emit_trace() { # [4] The reported source location is that of the call to the function calling # the command. bats_debug_trap() { - # on windows we sometimes get a mix of paths (when install via nmp install -g) - # which have C:/... or /c/... comparing them is going to be problematic. - # We need to normalize them to a common format! - local NORMALIZED_INPUT - bats_normalize_windows_dir_path NORMALIZED_INPUT "${1%/*}" - local file_excluded='' path - for path in "${BATS_DEBUG_EXCLUDE_PATHS[@]}"; do - if [[ "$NORMALIZED_INPUT" == "$path"* ]]; then - file_excluded=1 - break - fi - done - - # don't update the trace within library functions or we get backtraces from inside traps - # also don't record new stack traces while handling interruptions, to avoid overriding the interrupted command - if [[ -z "$file_excluded" && - "${BATS_INTERRUPTED-NOTSET}" == NOTSET && - "${BATS_TIMED_OUT-NOTSET}" == NOTSET ]]; then - BATS_DEBUG_LASTLAST_STACK_TRACE=( - ${BATS_DEBUG_LAST_STACK_TRACE[@]+"${BATS_DEBUG_LAST_STACK_TRACE[@]}"} - ) - - BATS_DEBUG_LAST_LINENO=(${BASH_LINENO[@]+"${BASH_LINENO[@]}"}) - BATS_DEBUG_LAST_SOURCE=(${BASH_SOURCE[@]+"${BASH_SOURCE[@]}"}) - bats_capture_stack_trace - bats_emit_trace - fi + # on windows we sometimes get a mix of paths (when install via nmp install -g) + # which have C:/... or /c/... comparing them is going to be problematic. + # We need to normalize them to a common format! + local NORMALIZED_INPUT + bats_normalize_windows_dir_path NORMALIZED_INPUT "${1%/*}" + local file_excluded='' path + for path in "${BATS_DEBUG_EXCLUDE_PATHS[@]}"; do + if [[ "$NORMALIZED_INPUT" == "$path"* ]]; then + file_excluded=1 + break + fi + done + + # don't update the trace within library functions or we get backtraces from inside traps + # also don't record new stack traces while handling interruptions, to avoid overriding the interrupted command + if [[ -z "$file_excluded" && + "${BATS_INTERRUPTED-NOTSET}" == NOTSET && + "${BATS_TIMED_OUT-NOTSET}" == NOTSET ]]; then + BATS_DEBUG_LASTLAST_STACK_TRACE=( + ${BATS_DEBUG_LAST_STACK_TRACE[@]+"${BATS_DEBUG_LAST_STACK_TRACE[@]}"} + ) + + BATS_DEBUG_LAST_LINENO=(${BASH_LINENO[@]+"${BASH_LINENO[@]}"}) + BATS_DEBUG_LAST_SOURCE=(${BASH_SOURCE[@]+"${BASH_SOURCE[@]}"}) + bats_capture_stack_trace + bats_emit_trace + fi } # For some versions of Bash, the `ERR` trap may not always fire for every @@ -282,82 +285,81 @@ bats_debug_trap() { # See `bats_exit_trap` for an additional EXIT error handling case when `$?` # isn't set properly during `teardown()` errors. bats_check_status_from_trap() { - local status="$?" - if [[ -z "${BATS_TEST_COMPLETED:-}" ]]; then - BATS_ERROR_STATUS="${BATS_ERROR_STATUS:-$status}" - if [[ "$BATS_ERROR_STATUS" -eq 0 ]]; then - BATS_ERROR_STATUS=1 - fi - trap - DEBUG - fi + local status="$?" + if [[ -z "${BATS_TEST_COMPLETED:-}" ]]; then + BATS_ERROR_STATUS="${BATS_ERROR_STATUS:-$status}" + if [[ "$BATS_ERROR_STATUS" -eq 0 ]]; then + BATS_ERROR_STATUS=1 + fi + trap - DEBUG + fi } bats_add_debug_exclude_path() { # - if [[ -z "$1" ]]; then # don't exclude everything - printf "bats_add_debug_exclude_path: Exclude path must not be empty!\n" >&2 - return 1 - fi - if [[ "$OSTYPE" == cygwin || "$OSTYPE" == msys ]]; then - local normalized_dir - bats_normalize_windows_dir_path normalized_dir "$1" - BATS_DEBUG_EXCLUDE_PATHS+=("$normalized_dir") - else - BATS_DEBUG_EXCLUDE_PATHS+=("$1") - fi + if [[ -z "$1" ]]; then # don't exclude everything + printf "bats_add_debug_exclude_path: Exclude path must not be empty!\n" >&2 + return 1 + fi + if [[ "$OSTYPE" == cygwin || "$OSTYPE" == msys ]]; then + local normalized_dir + bats_normalize_windows_dir_path normalized_dir "$1" + BATS_DEBUG_EXCLUDE_PATHS+=("$normalized_dir") + else + BATS_DEBUG_EXCLUDE_PATHS+=("$1") + fi } bats_setup_tracing() { - # Variables for capturing accurate stack traces. See bats_debug_trap for - # details. - # - # BATS_DEBUG_LAST_LINENO, BATS_DEBUG_LAST_SOURCE, and - # BATS_DEBUG_LAST_STACK_TRACE hold data from the most recent call to - # bats_debug_trap. - # - # BATS_DEBUG_LASTLAST_STACK_TRACE holds data from two bats_debug_trap calls - # ago. - # - # BATS_DEBUG_LAST_STACK_TRACE_IS_VALID indicates that - # BATS_DEBUG_LAST_STACK_TRACE contains the stack trace of the test's error. If - # unset, BATS_DEBUG_LAST_STACK_TRACE is unreliable and - # BATS_DEBUG_LASTLAST_STACK_TRACE should be used instead. - BATS_DEBUG_LASTLAST_STACK_TRACE=() - BATS_DEBUG_LAST_LINENO=() - BATS_DEBUG_LAST_SOURCE=() - BATS_DEBUG_LAST_STACK_TRACE=() - BATS_DEBUG_LAST_STACK_TRACE_IS_VALID= - BATS_ERROR_SUFFIX= - BATS_DEBUG_EXCLUDE_PATHS=() - # exclude some paths by default - bats_add_debug_exclude_path "$BATS_ROOT/lib/" - bats_add_debug_exclude_path "$BATS_ROOT/libexec/" - - - exec 4<&1 # used for tracing - if [[ "${BATS_TRACE_LEVEL:-0}" -gt 0 ]]; then - # avoid undefined variable errors - BATS_LAST_BASH_COMMAND= - BATS_LAST_BASH_LINENO= - BATS_LAST_BASH_SOURCE= - BATS_LAST_STACK_DEPTH= - # try to exclude helper libraries if found, this is only relevant for tracing - while read -r path; do - bats_add_debug_exclude_path "$path" - done < <(find "$PWD" -type d -name bats-assert -o -name bats-support) - fi - - local exclude_paths path - # exclude user defined libraries - IFS=':' read -r exclude_paths <<< "${BATS_DEBUG_EXCLUDE_PATHS:-}" - for path in "${exclude_paths[@]}"; do - if [[ -n "$path" ]]; then - bats_add_debug_exclude_path "$path" - fi - done - - # turn on traps after setting excludes to avoid tracing the exclude setup - trap 'bats_debug_trap "$BASH_SOURCE"' DEBUG - trap 'bats_error_trap' ERR + # Variables for capturing accurate stack traces. See bats_debug_trap for + # details. + # + # BATS_DEBUG_LAST_LINENO, BATS_DEBUG_LAST_SOURCE, and + # BATS_DEBUG_LAST_STACK_TRACE hold data from the most recent call to + # bats_debug_trap. + # + # BATS_DEBUG_LASTLAST_STACK_TRACE holds data from two bats_debug_trap calls + # ago. + # + # BATS_DEBUG_LAST_STACK_TRACE_IS_VALID indicates that + # BATS_DEBUG_LAST_STACK_TRACE contains the stack trace of the test's error. If + # unset, BATS_DEBUG_LAST_STACK_TRACE is unreliable and + # BATS_DEBUG_LASTLAST_STACK_TRACE should be used instead. + BATS_DEBUG_LASTLAST_STACK_TRACE=() + BATS_DEBUG_LAST_LINENO=() + BATS_DEBUG_LAST_SOURCE=() + BATS_DEBUG_LAST_STACK_TRACE=() + BATS_DEBUG_LAST_STACK_TRACE_IS_VALID= + BATS_ERROR_SUFFIX= + BATS_DEBUG_EXCLUDE_PATHS=() + # exclude some paths by default + bats_add_debug_exclude_path "$BATS_ROOT/lib/" + bats_add_debug_exclude_path "$BATS_ROOT/libexec/" + + exec 4<&1 # used for tracing + if [[ "${BATS_TRACE_LEVEL:-0}" -gt 0 ]]; then + # avoid undefined variable errors + BATS_LAST_BASH_COMMAND= + BATS_LAST_BASH_LINENO= + BATS_LAST_BASH_SOURCE= + BATS_LAST_STACK_DEPTH= + # try to exclude helper libraries if found, this is only relevant for tracing + while read -r path; do + bats_add_debug_exclude_path "$path" + done < <(find "$PWD" -type d -name bats-assert -o -name bats-support) + fi + + local exclude_paths path + # exclude user defined libraries + IFS=':' read -r exclude_paths <<<"${BATS_DEBUG_EXCLUDE_PATHS:-}" + for path in "${exclude_paths[@]}"; do + if [[ -n "$path" ]]; then + bats_add_debug_exclude_path "$path" + fi + done + + # turn on traps after setting excludes to avoid tracing the exclude setup + trap 'bats_debug_trap "$BASH_SOURCE"' DEBUG + trap 'bats_error_trap' ERR } bats_error_trap() { @@ -365,9 +367,9 @@ bats_error_trap() { # If necessary, undo the most recent stack trace captured by bats_debug_trap. # See bats_debug_trap for details. - if [[ "${BASH_LINENO[*]}" = "${BATS_DEBUG_LAST_LINENO[*]:-}" - && "${BASH_SOURCE[*]}" = "${BATS_DEBUG_LAST_SOURCE[*]:-}" - && -z "$BATS_DEBUG_LAST_STACK_TRACE_IS_VALID" ]]; then + if [[ "${BASH_LINENO[*]}" = "${BATS_DEBUG_LAST_LINENO[*]:-}" && + "${BASH_SOURCE[*]}" = "${BATS_DEBUG_LAST_SOURCE[*]:-}" && + -z "$BATS_DEBUG_LAST_STACK_TRACE_IS_VALID" ]]; then BATS_DEBUG_LAST_STACK_TRACE=( ${BATS_DEBUG_LASTLAST_STACK_TRACE[@]+"${BATS_DEBUG_LASTLAST_STACK_TRACE[@]}"} ) diff --git a/lib/bats-core/validator.bash b/lib/bats-core/validator.bash index ede74b157e..59fc2c1e69 100644 --- a/lib/bats-core/validator.bash +++ b/lib/bats-core/validator.bash @@ -17,12 +17,12 @@ bats_test_count_validator() { # forward line printf "%s\n" "$line" case "$line" in - 'ok '*) - (( ++actual_number_of_tests )) - ;; - 'not ok'*) - (( ++actual_number_of_tests )) - ;; + 'ok '*) + ((++actual_number_of_tests)) + ;; + 'not ok'*) + ((++actual_number_of_tests)) + ;; esac done # ... and error if they are not the same diff --git a/lib/bats-core/warnings.bash b/lib/bats-core/warnings.bash index 0d285920d8..fbb5186a46 100644 --- a/lib/bats-core/warnings.bash +++ b/lib/bats-core/warnings.bash @@ -12,14 +12,14 @@ bats_generate_warning() { # [--no-stacktrace] [> "$BATS_WARNING_FILE" 2>&3 + } >>"$BATS_WARNING_FILE" 2>&3 else printf "Invalid Bats warning number '%s'. It must be an integer between 1 and %d." "$warning_number" "$((${#BATS_WARNING_SHORT_DESCS[@]} - 1))" >&2 exit 1 diff --git a/libexec/bats-core/bats b/libexec/bats-core/bats index fbb2586e0a..5bf014590c 100755 --- a/libexec/bats-core/bats +++ b/libexec/bats-core/bats @@ -91,7 +91,10 @@ expand_path() { printf -v "$result" '%s/%s' "$dirname" "${path##*/}" } -BATS_LIBEXEC="$(cd "$(dirname "$(bats_readlinkf "${BASH_SOURCE[0]}")")"; pwd)" +BATS_LIBEXEC="$( + cd "$(dirname "$(bats_readlinkf "${BASH_SOURCE[0]}")")" + pwd +)" export BATS_LIBEXEC export BATS_CWD="$PWD" export BATS_TEST_FILTER= @@ -104,10 +107,10 @@ export BATS_GUARANTEED_MINIMUM_VERSION=0.0.0 export BATS_LIB_PATH=${BATS_LIB_PATH-/usr/lib/bats} BATS_REPORT_OUTPUT_DIR=${BATS_REPORT_OUTPUT_DIR-.} -if [[ ! -d "${BATS_TMPDIR}" ]];then +if [[ ! -d "${BATS_TMPDIR}" ]]; then printf "Error: BATS_TMPDIR (%s) does not exist or is not a directory" "${BATS_TMPDIR}" >&2 exit 1 -elif [[ ! -w "${BATS_TMPDIR}" ]];then +elif [[ ! -w "${BATS_TMPDIR}" ]]; then printf "Error: BATS_TMPDIR (%s) is not writable" "${BATS_TMPDIR}" >&2 exit 1 fi @@ -134,7 +137,7 @@ set -- "${arguments[@]}" arguments=() unset flags recursive formatter_flags -flags=('--dummy-flag') # add a dummy flag to prevent unset variable errors on empty array expansion in old bash versions +flags=('--dummy-flag') # add a dummy flag to prevent unset variable errors on empty array expansion in old bash versions formatter_flags=('--dummy-flag') # add a dummy flag to prevent unset variable errors on empty array expansion in old bash versions formatter=${BATS_FORMATTER:-'tap'} report_formatter='' @@ -204,8 +207,8 @@ while [[ "$#" -ne 0 ]]; do formatter_flags+=('-T') ;; # this flag is now a no-op, as it is the parallel default - --parallel-preserve-environment) - ;; + --parallel-preserve-environment) ;; + --no-parallelize-across-files) flags+=("--no-parallelize-across-files") ;; @@ -250,7 +253,7 @@ while [[ "$#" -ne 0 ]]; do --code-quote-style) shift BATS_CODE_QUOTE_STYLE="$1" - ;; + ;; --filter-status) shift flags+=('--filter-status' "$1") @@ -269,16 +272,16 @@ while [[ "$#" -ne 0 ]]; do shift done -if [[ -n "${BATS_RUN_TMPDIR:-}" ]];then +if [[ -n "${BATS_RUN_TMPDIR:-}" ]]; then if [[ -d "$BATS_RUN_TMPDIR" ]]; then printf "Error: BATS_RUN_TMPDIR (%s) already exists\n" "$BATS_RUN_TMPDIR" >&2 printf "Reusing old run directories can lead to unexpected results ... aborting!\n" >&2 exit 1 - elif ! mkdir -p "$BATS_RUN_TMPDIR" ;then + elif ! mkdir -p "$BATS_RUN_TMPDIR"; then printf "Error: Failed to create BATS_RUN_TMPDIR (%s)\n" "$BATS_RUN_TMPDIR" >&2 exit 1 fi -elif ! BATS_RUN_TMPDIR=$(mktemp -d "${BATS_TMPDIR}/bats-run-XXXXXX");then +elif ! BATS_RUN_TMPDIR=$(mktemp -d "${BATS_TMPDIR}/bats-run-XXXXXX"); then printf "Error: Failed to create BATS_RUN_TMPDIR (%s) with mktemp\n" "${BATS_TMPDIR}/bats-run-XXXXXX" >&2 exit 1 fi @@ -361,15 +364,15 @@ if [[ -n "$report_formatter" ]]; then # only set BATS_REPORT_FILENAME if none was given if [[ -z "${BATS_REPORT_FILENAME:-}" ]]; then case "$report_formatter" in - tap|tap13) - BATS_REPORT_FILENAME="report.tap" - ;; - junit) - BATS_REPORT_FILENAME="report.xml" - ;; - *) - BATS_REPORT_FILENAME="report.log" - ;; + tap | tap13) + BATS_REPORT_FILENAME="report.tap" + ;; + junit) + BATS_REPORT_FILENAME="report.xml" + ;; + *) + BATS_REPORT_FILENAME="report.log" + ;; esac fi fi @@ -386,21 +389,21 @@ if [[ "${BATS_CODE_QUOTE_STYLE-BATS_CODE_QUOTE_STYLE_UNSET}" == BATS_CODE_QUOTE_ fi case "${BATS_CODE_QUOTE_STYLE}" in - ??) - BATS_BEGIN_CODE_QUOTE="${BATS_CODE_QUOTE_STYLE::1}" - BATS_END_CODE_QUOTE="${BATS_CODE_QUOTE_STYLE:1:1}" - export BATS_BEGIN_CODE_QUOTE BATS_END_CODE_QUOTE +??) + BATS_BEGIN_CODE_QUOTE="${BATS_CODE_QUOTE_STYLE::1}" + BATS_END_CODE_QUOTE="${BATS_CODE_QUOTE_STYLE:1:1}" + export BATS_BEGIN_CODE_QUOTE BATS_END_CODE_QUOTE ;; - custom) - if [[ ${BATS_BEGIN_CODE_QUOTE-BATS_BEGIN_CODE_QUOTE_UNSET} == BATS_BEGIN_CODE_QUOTE_UNSET - || ${BATS_END_CODE_QUOTE-BATS_BEGIN_CODE_QUOTE_UNSET} == BATS_BEGIN_CODE_QUOTE_UNSET ]]; then - printf "ERROR: BATS_CODE_QUOTE_STYLE=custom requires BATS_BEGIN_CODE_QUOTE and BATS_END_CODE_QUOTE to be set\n" >&2 - exit 1 - fi - ;; - *) - printf "ERROR: Unknown BATS_CODE_QUOTE_STYLE: %s\n" "$BATS_CODE_QUOTE_STYLE" >&2 +custom) + if [[ ${BATS_BEGIN_CODE_QUOTE-BATS_BEGIN_CODE_QUOTE_UNSET} == BATS_BEGIN_CODE_QUOTE_UNSET || + ${BATS_END_CODE_QUOTE-BATS_BEGIN_CODE_QUOTE_UNSET} == BATS_BEGIN_CODE_QUOTE_UNSET ]]; then + printf "ERROR: BATS_CODE_QUOTE_STYLE=custom requires BATS_BEGIN_CODE_QUOTE and BATS_END_CODE_QUOTE to be set\n" >&2 exit 1 + fi + ;; +*) + printf "ERROR: Unknown BATS_CODE_QUOTE_STYLE: %s\n" "$BATS_CODE_QUOTE_STYLE" >&2 + exit 1 ;; esac @@ -453,12 +456,12 @@ trap 'BATS_INTERRUPTED=true' INT # let the lower levels handle the interruption set -o pipefail execfail if [[ -n "$report_formatter" ]]; then - exec bats-exec-suite "${flags[@]}" "${filenames[@]}" | \ - tee >("$interpolated_report_formatter" "${report_formatter_flags[@]}" >"${BATS_REPORT_OUTPUT_DIR}/${BATS_REPORT_FILENAME}") | \ - bats_test_count_validator | \ + exec bats-exec-suite "${flags[@]}" "${filenames[@]}" | + tee >("$interpolated_report_formatter" "${report_formatter_flags[@]}" >"${BATS_REPORT_OUTPUT_DIR}/${BATS_REPORT_FILENAME}") | + bats_test_count_validator | "$interpolated_formatter" "${formatter_flags[@]}" else - exec bats-exec-suite "${flags[@]}" "${filenames[@]}" | \ - bats_test_count_validator | \ + exec bats-exec-suite "${flags[@]}" "${filenames[@]}" | + bats_test_count_validator | "$interpolated_formatter" "${formatter_flags[@]}" fi diff --git a/libexec/bats-core/bats-exec-file b/libexec/bats-core/bats-exec-file index 5ebf8fe418..5f7077f9f6 100755 --- a/libexec/bats-core/bats-exec-file +++ b/libexec/bats-core/bats-exec-file @@ -6,7 +6,7 @@ num_jobs=${BATS_NUMBER_OF_PARALLEL_JOBS:-1} extended_syntax='' BATS_TRACE_LEVEL="${BATS_TRACE_LEVEL:-0}" declare -r BATS_RETRY_RETURN_CODE=126 -export BATS_TEST_RETRIES=0 # no retries by default +export BATS_TEST_RETRIES=0 # no retries by default while [[ "$#" -ne 0 ]]; do case "$1" in @@ -25,8 +25,8 @@ while [[ "$#" -ne 0 ]]; do # use singular to allow for users to override in file BATS_NO_PARALLELIZE_WITHIN_FILE=1 ;; - --dummy-flag) - ;; + --dummy-flag) ;; + --trace) flags+=('--trace') ;; @@ -76,7 +76,7 @@ bats_run_setup_file() { # these are defined only to avoid errors when referencing undefined variables down the line # shellcheck disable=2034 - BATS_TEST_NAME= # used in tracing.bash + BATS_TEST_NAME= # used in tracing.bash # shellcheck disable=2034 BATS_TEST_COMPLETED= # used in tracing.bash @@ -92,7 +92,7 @@ bats_run_setup_file() { local status=0 # get the setup_file/teardown_file functions for this file (if it has them) # shellcheck disable=SC1090 - source "$BATS_TEST_SOURCE" >>"$BATS_OUT" 2>&1 + source "$BATS_TEST_SOURCE" >>"$BATS_OUT" 2>&1 BATS_SOURCE_FILE_COMPLETED=1 @@ -109,7 +109,7 @@ bats_run_teardown_file() { # rely on bats_error_trap to catch failures teardown_file >>"$BATS_OUT" 2>&1 || bats_teardown_file_status=$? - if (( bats_teardown_file_status == 0 )); then + if ((bats_teardown_file_status == 0)); then BATS_TEARDOWN_FILE_COMPLETED=1 elif [[ -n "${BATS_SETUP_FILE_COMPLETED:-}" ]]; then BATS_DEBUG_LAST_STACK_TRACE_IS_VALID=1 @@ -133,13 +133,13 @@ bats_file_exit_trap() { fi trap - ERR EXIT local failure_reason - local -i failure_test_index=$(( BATS_FILE_FIRST_TEST_NUMBER_IN_SUITE + 1 )) + local -i failure_test_index=$((BATS_FILE_FIRST_TEST_NUMBER_IN_SUITE + 1)) if [[ -z "$BATS_SETUP_FILE_COMPLETED" || -z "$BATS_TEARDOWN_FILE_COMPLETED" ]]; then if [[ -z "$BATS_SETUP_FILE_COMPLETED" ]]; then failure_reason='setup_file' elif [[ -z "$BATS_TEARDOWN_FILE_COMPLETED" ]]; then failure_reason='teardown_file' - failure_test_index=$(( BATS_FILE_FIRST_TEST_NUMBER_IN_SUITE + ${#tests_to_run[@]} + 1 )) + failure_test_index=$((BATS_FILE_FIRST_TEST_NUMBER_IN_SUITE + ${#tests_to_run[@]} + 1)) elif [[ -z "$BATS_SOURCE_FILE_COMPLETED" ]]; then failure_reason='source' else @@ -150,7 +150,7 @@ bats_file_exit_trap() { bats_get_failure_stack_trace stack_trace bats_print_stack_trace "${stack_trace[@]}" >&3 bats_print_failed_command "${stack_trace[@]}" >&3 - bats_prefix_lines_for_tap_output < "$BATS_OUT" | bats_replace_filename >&3 + bats_prefix_lines_for_tap_output <"$BATS_OUT" | bats_replace_filename >&3 rm -rf "$BATS_OUT" bats_exec_file_status=1 fi @@ -183,7 +183,7 @@ bats_forward_output_of_parallel_test() { bats_is_next_parallel_test_finished() { local PID # get the pid of the next potentially finished test - PID=$(cat "$output_folder/$(( test_number_in_suite_of_last_finished_test + 1 ))/pid") + PID=$(cat "$output_folder/$((test_number_in_suite_of_last_finished_test + 1))/pid") # try to send a signal to this process # if it fails, the process exited, # if it succeeds, the process is still running @@ -198,10 +198,10 @@ bats_is_next_parallel_test_finished() { bats_forward_output_for_parallel_tests() { local status=0 # was the next test already started? - while (( test_number_in_suite_of_last_finished_test + 1 <= test_number_in_suite )); do + while ((test_number_in_suite_of_last_finished_test + 1 <= test_number_in_suite)); do # if we are okay with waiting or if the test has already been finished - if [[ "$1" == "blocking" ]] || bats_is_next_parallel_test_finished ; then - (( ++test_number_in_suite_of_last_finished_test )) + if [[ "$1" == "blocking" ]] || bats_is_next_parallel_test_finished; then + ((++test_number_in_suite_of_last_finished_test)) bats_forward_output_of_parallel_test "$test_number_in_suite_of_last_finished_test" || status=$? else # non-blocking and the process has not finished -> abort the printing @@ -214,7 +214,7 @@ bats_forward_output_for_parallel_tests() { bats_run_test_with_retries() { # local status=0 local should_try_again=1 try_number - for ((try_number=1; should_try_again; ++try_number)); do + for ((try_number = 1; should_try_again; ++try_number)); do if "$BATS_LIBEXEC/bats-exec-test" "$@" "$try_number"; then should_try_again=0 else @@ -247,8 +247,8 @@ bats_run_tests_in_parallel() { ((++test_number_in_file)) mkdir -p "$output_folder/$test_number_in_suite" bats_semaphore_run "$output_folder/$test_number_in_suite" \ - bats_run_test_with_retries "${flags[@]}" "$filename" "$test_name" "$test_number_in_suite" "$test_number_in_file" \ - > "$output_folder/$test_number_in_suite/pid" + bats_run_test_with_retries "${flags[@]}" "$filename" "$test_name" "$test_number_in_suite" "$test_number_in_file" \ + >"$output_folder/$test_number_in_suite/pid" fi # print results early to get interactive feedback bats_forward_output_for_parallel_tests non-blocking || status=1 # ignore if we did not finish yet @@ -268,7 +268,7 @@ bats_read_tests_list_file() { # use simple string operations to work around that issue if [[ "$filename" == "${test_line::${#filename}}" ]]; then # get the rest of the line without the separator \t - test_name=${test_line:$((1 + ${#filename} ))} + test_name=${test_line:$((1 + ${#filename}))} tests_to_run+=("$test_name") # save the first test's number for later iteration # this assumes that tests for a file are stored consecutive in the file! @@ -290,7 +290,7 @@ bats_run_tests() { bats_run_tests_in_parallel "$BATS_RUN_TMPDIR/parallel_output" || bats_exec_file_status=1 else local test_number_in_suite=$BATS_FILE_FIRST_TEST_NUMBER_IN_SUITE \ - test_number_in_file=0 + test_number_in_file=0 for test_name in "${tests_to_run[@]}"; do if [[ "${BATS_INTERRUPTED-NOTSET}" != NOTSET ]]; then bats_exec_file_status=130 # bash's code for SIGINT exits @@ -301,7 +301,7 @@ bats_run_tests() { ((++test_number_in_suite)) ((++test_number_in_file)) bats_run_test_with_retries "${flags[@]}" "$filename" "$test_name" \ - "$test_number_in_suite" "$test_number_in_file" || bats_exec_file_status=$? + "$test_number_in_suite" "$test_number_in_file" || bats_exec_file_status=$? fi done fi diff --git a/libexec/bats-core/bats-exec-suite b/libexec/bats-core/bats-exec-suite index 6555567bb0..cc8d429aa9 100755 --- a/libexec/bats-core/bats-exec-suite +++ b/libexec/bats-core/bats-exec-suite @@ -55,8 +55,8 @@ while [[ "$#" -ne 0 ]]; do --filter-tags) shift IFS=, read -ra tags <<<"$1" || true - if (( ${#tags[@]} > 0 )); then - for (( i = 0; i < ${#tags[@]}; ++i )); do + if ((${#tags[@]} > 0)); then + for ((i = 0; i < ${#tags[@]}; ++i)); do bats_trim "tags[$i]" "${tags[$i]}" done bats_sort sorted_tags "${tags[@]}" @@ -65,11 +65,11 @@ while [[ "$#" -ne 0 ]]; do filter_tags_list+=("") fi ;; - --dummy-flag) - ;; + --dummy-flag) ;; + --trace) flags+=('--trace') - (( ++BATS_TRACE_LEVEL )) # avoid returning 0 + ((++BATS_TRACE_LEVEL)) # avoid returning 0 ;; --print-output-on-failure) flags+=(--print-output-on-failure) @@ -110,7 +110,7 @@ fi TESTS_LIST_FILE="${BATS_RUN_TMPDIR}/test_list_file.txt" bats_gather_tests() { - local line test_line tags + local line test_line tags all_tests=() for filename in "$@"; do if [[ ! -f "$filename" ]]; then @@ -135,28 +135,28 @@ bats_gather_tests() { if [[ ${#filter_tags_list[@]} -gt 0 ]]; then local match= for filter_tags in "${filter_tags_list[@]}"; do - # empty search tags only match empty test tags! - if [[ -z "$filter_tags" ]]; then - if [[ ${#tags[@]} -eq 0 ]]; then - match=1 - break - fi - continue - fi - local -a positive_filter_tags=() negative_filter_tags=() - IFS=, read -ra filter_tags <<< "$filter_tags" || true - for filter_tag in "${filter_tags[@]}"; do - if [[ $filter_tag == !* ]]; then - bats_trim filter_tag "${filter_tag#!}" - negative_filter_tags+=("${filter_tag}") - else - positive_filter_tags+=("${filter_tag}") - fi - done - if bats_append_arrays_as_args positive_filter_tags -- bats_all_in tags && - ! bats_append_arrays_as_args negative_filter_tags -- bats_any_in tags; then + # empty search tags only match empty test tags! + if [[ -z "$filter_tags" ]]; then + if [[ ${#tags[@]} -eq 0 ]]; then match=1 + break fi + continue + fi + local -a positive_filter_tags=() negative_filter_tags=() + IFS=, read -ra filter_tags <<<"$filter_tags" || true + for filter_tag in "${filter_tags[@]}"; do + if [[ $filter_tag == !* ]]; then + bats_trim filter_tag "${filter_tag#!}" + negative_filter_tags+=("${filter_tag}") + else + positive_filter_tags+=("${filter_tag}") + fi + done + if bats_append_arrays_as_args positive_filter_tags -- bats_all_in tags && + ! bats_append_arrays_as_args negative_filter_tags -- bats_any_in tags; then + match=1 + fi done if [[ -z "$match" ]]; then continue @@ -201,26 +201,26 @@ fi bats_gather_tests "$@" -if [[ -n "$filter_status" ]]; then +if [[ -n "$filter_status" ]]; then case "$filter_status" in - failed) - bats_filter_test_by_status() { # - ! bats_binary_search "$1" "passed_tests" - } + failed) + bats_filter_test_by_status() { # + ! bats_binary_search "$1" "passed_tests" + } ;; - passed) - bats_filter_test_by_status() { - ! bats_binary_search "$1" "failed_tests" - } + passed) + bats_filter_test_by_status() { + ! bats_binary_search "$1" "failed_tests" + } ;; - missed) - bats_filter_test_by_status() { - ! bats_binary_search "$1" "failed_tests" && ! bats_binary_search "$1" "passed_tests" - } + missed) + bats_filter_test_by_status() { + ! bats_binary_search "$1" "failed_tests" && ! bats_binary_search "$1" "passed_tests" + } ;; - *) - printf "Error: Unknown value '%s' for --filter-status. Valid values are 'failed' and 'missed'.\n" "$filter_status">&2 - exit 1 + *) + printf "Error: Unknown value '%s' for --filter-status. Valid values are 'failed' and 'missed'.\n" "$filter_status" >&2 + exit 1 ;; esac @@ -238,22 +238,22 @@ if [[ -n "$filter_status" ]]; then while read -rd $'\n' line; do ((++i)) case "$line" in - "passed "*) - passed_tests+=("${line#passed }") + "passed "*) + passed_tests+=("${line#passed }") ;; - "failed "*) - failed_tests+=("${line#failed }") + "failed "*) + failed_tests+=("${line#failed }") ;; - "status-filtered $filter_status"*) # pick up tests that were filtered in the last round for the same status - last_filtered_tests+=("${line#status-filtered "$filter_status" }") + "status-filtered $filter_status"*) # pick up tests that were filtered in the last round for the same status + last_filtered_tests+=("${line#status-filtered "$filter_status" }") ;; - "status-filtered "*) # ignore other status-filtered lines + "status-filtered "*) # ignore other status-filtered lines ;; - "#"*) # allow for comments + "#"*) # allow for comments ;; - *) - printf "Error: %s:%d: Invalid format: %s\n" "$BATS_PREVIOUS_RUNLOG_FILE" "$i" "$line" >&2 - exit 1 + *) + printf "Error: %s:%d: Invalid format: %s\n" "$BATS_PREVIOUS_RUNLOG_FILE" "$i" "$line" >&2 + exit 1 ;; esac done < <(sort "$BATS_PREVIOUS_RUNLOG_FILE") @@ -264,14 +264,14 @@ if [[ -n "$filter_status" ]]; then printf "%s\n" "$line" filtered_tests+=("$line") else - printf "status-filtered %s %s\n" "$filter_status" "$line" >> "$BATS_RUNLOG_FILE" + printf "status-filtered %s %s\n" "$filter_status" "$line" >>"$BATS_RUNLOG_FILE" fi - done > "$TESTS_LIST_FILE" + done >"$TESTS_LIST_FILE" # save filtered tests to exclude them again in next round - for test_line in "${last_filtered_tests[@]}"; do + for test_line in "${last_filtered_tests[@]}"; do printf "status-filtered %s %s\n" "$filter_status" "$test_line" - done >> "$BATS_RUNLOG_FILE" + done >>"$BATS_RUNLOG_FILE" test_count="${#filtered_tests[@]}" if [[ ${#failed_tests[@]} -eq 0 && ${#filtered_tests[@]} -eq 0 ]]; then @@ -318,7 +318,7 @@ fi # (see https://github.com/bats-core/bats-core/issues/329) # If a file was specified multiple times, we already got it repeatedly in our TESTS_LIST_FILE. # Thus, it suffices to bats-exec-file it once to run all repeated tests on it. -IFS=$'\n' read -d '' -r -a BATS_UNIQUE_TEST_FILENAMES < <(printf "%s\n" "$@"| nl | sort -k 2 | uniq -f 1 | sort -n | cut -f 2-) || true +IFS=$'\n' read -d '' -r -a BATS_UNIQUE_TEST_FILENAMES < <(printf "%s\n" "$@" | nl | sort -k 2 | uniq -f 1 | sort -n | cut -f 2-) || true # shellcheck source=lib/bats-core/tracing.bash source "$BATS_ROOT/lib/bats-core/tracing.bash" @@ -334,7 +334,7 @@ bats_suite_exit_trap() { if [[ -z "${BATS_SETUP_SUITE_COMPLETED}" ]]; then printf "not ok 1 setup_suite\n" elif [[ -z "${BATS_TEARDOWN_SUITE_COMPLETED}" ]]; then - printf "not ok %d teardown_suite\n" $((test_count+1)) + printf "not ok %d teardown_suite\n" $((test_count + 1)) fi local stack_trace bats_get_failure_stack_trace stack_trace @@ -345,13 +345,13 @@ bats_suite_exit_trap() { fi if [[ -n "$print_bats_out" ]]; then - bats_prefix_lines_for_tap_output < "$BATS_OUT" + bats_prefix_lines_for_tap_output <"$BATS_OUT" fi if [[ ${BATS_INTERRUPTED-NOTSET} != NOTSET ]]; then printf "\n# Received SIGINT, aborting ...\n\n" fi - + if [[ -d "$BATS_RUN_LOGS_DIRECTORY" && -n "${BATS_INTERRUPTED:-}" ]]; then # aborting a test run with CTRL+C does not save the runlog file rm "$BATS_RUNLOG_FILE" @@ -366,7 +366,7 @@ bats_run_teardown_suite() { trap bats_suite_exit_trap EXIT BATS_TEARDOWN_SUITE_COMPLETED= teardown_suite >>"$BATS_OUT" 2>&1 || bats_teardown_suite_status=$? - if (( bats_teardown_suite_status == 0 )); then + if ((bats_teardown_suite_status == 0)); then BATS_TEARDOWN_SUITE_COMPLETED=1 elif [[ -n "${BATS_SETUP_SUITE_COMPLETED:-}" ]]; then BATS_DEBUG_LAST_STACK_TRACE_IS_VALID=1 @@ -381,7 +381,7 @@ bats_teardown_suite_trap() { } teardown_suite() { - : + : } trap bats_teardown_suite_trap EXIT @@ -400,25 +400,24 @@ if [[ -n "$setup_suite_file" ]]; then # shellcheck disable=SC1090 source "$setup_suite_file" - + set -eET export BATS_SETUP_SUITE_COMPLETED= setup_suite >>"$BATS_OUT" 2>&1 BATS_SETUP_SUITE_COMPLETED=1 set +ET else - # prevent exit trap from printing an error because of incomplete setup_suite, + # prevent exit trap from printing an error because of incomplete setup_suite, # when there was none to execute BATS_SETUP_SUITE_COMPLETED=1 fi - if [[ "$num_jobs" -gt 1 ]] && [[ -z "$bats_no_parallelize_across_files" ]]; then # run files in parallel to get the maximum pool of parallel tasks # shellcheck disable=SC2086,SC2068 # we need to handle the quoting of ${flags[@]} ourselves, # because parallel can only quote it as one - parallel --keep-order --jobs "$num_jobs" bats-exec-file "$(printf "%q " "${flags[@]}")" "{}" "$TESTS_LIST_FILE" ::: "${BATS_UNIQUE_TEST_FILENAMES[@]}" 2>&1 || bats_exec_suite_status=1 + parallel --keep-order --jobs "$num_jobs" bats-exec-file "$(printf "%q " "${flags[@]}")" "{}" "$TESTS_LIST_FILE" ::: "${BATS_UNIQUE_TEST_FILENAMES[@]}" 2>&1 || bats_exec_suite_status=1 else for filename in "${BATS_UNIQUE_TEST_FILENAMES[@]}"; do if [[ "${BATS_INTERRUPTED-NOTSET}" != NOTSET ]]; then diff --git a/libexec/bats-core/bats-exec-test b/libexec/bats-core/bats-exec-test index c63cbcd1e9..0130b0c5c5 100755 --- a/libexec/bats-core/bats-exec-test +++ b/libexec/bats-core/bats-exec-test @@ -20,10 +20,10 @@ while [[ "$#" -ne 0 ]]; do # shellcheck disable=SC2034 BATS_EXTENDED_SYNTAX='-x' ;; - --dummy-flag) - ;; + --dummy-flag) ;; + --trace) - (( ++BATS_TRACE_LEVEL )) # avoid returning 0 + ((++BATS_TRACE_LEVEL)) # avoid returning 0 ;; --print-output-on-failure) BATS_PRINT_OUTPUT_ON_FAILURE=1 @@ -72,7 +72,7 @@ bats_create_test_tmpdirs() { exit 1 fi - printf "%s\n" "$BATS_TEST_NAME" > "$BATS_TEST_TMPDIR.name" + printf "%s\n" "$BATS_TEST_NAME" >"$BATS_TEST_TMPDIR.name" export BATS_TEST_TMPDIR } @@ -91,7 +91,7 @@ bats_teardown_trap() { # The second parameter is optional and corresponds for to the killer pid # that will be forwarded to the exit trap to kill it if necesary local killer_pid=${2:-} - + # mark the start of this function to distinguish where skip is called # parameter 1 will signify the reason why this function was called # this is used to identify when this is called as exit trap function @@ -124,15 +124,15 @@ bats_exit_trap() { if [[ -n "$BATS_TEST_SKIPPED" ]]; then exit_metadata=' # skip' if [[ "$BATS_TEST_SKIPPED" != '1' ]]; then - exit_metadata+=" $BATS_TEST_SKIPPED" + exit_metadata+=" $BATS_TEST_SKIPPED" fi elif [[ "${BATS_TIMED_OUT-NOTSET}" != NOTSET ]]; then - exit_metadata=" # timeout after ${BATS_TEST_TIMEOUT}s" + exit_metadata=" # timeout after ${BATS_TEST_TIMEOUT}s" fi BATS_TEST_TIME='' if [[ -n "$BATS_ENABLE_TIMING" ]]; then - BATS_TEST_TIME=" in "$(( $(get_mills_since_epoch) - BATS_TEST_START_TIME ))"ms" + BATS_TEST_TIME=" in "$(($(get_mills_since_epoch) - BATS_TEST_START_TIME))"ms" fi local print_bats_out="${BATS_SHOW_OUTPUT_OF_SUCCEEDING_TESTS}" @@ -153,7 +153,7 @@ bats_exit_trap() { fi if bats_should_retry_test; then should_retry=1 - status=126 # signify retry + status=126 # signify retry rm -r "$BATS_TEST_TMPDIR" # clean up for retry else printf 'not ok %d %s%s\n' "$BATS_SUITE_TEST_NUMBER" "${BATS_TEST_NAME_PREFIX:-}${BATS_TEST_DESCRIPTION}${BATS_TEST_TIME}" "$exit_metadata" >&3 @@ -169,9 +169,9 @@ bats_exit_trap() { if [[ -n "${stderr:-}" ]]; then printf "Last stderr: \n%s\n" "$stderr" fi - fi >> "$BATS_OUT" + fi >>"$BATS_OUT" - print_bats_out=1 + print_bats_out=1 status=1 local state=failed fi @@ -183,10 +183,10 @@ bats_exit_trap() { fi if [[ -z "$should_retry" ]]; then - printf "%s %s\t%s\n" "$state" "$BATS_TEST_FILENAME" "$BATS_TEST_NAME" >> "$BATS_RUNLOG_FILE" + printf "%s %s\t%s\n" "$state" "$BATS_TEST_FILENAME" "$BATS_TEST_NAME" >>"$BATS_RUNLOG_FILE" if [[ $print_bats_out ]]; then - bats_prefix_lines_for_tap_output < "$BATS_OUT" | bats_replace_filename >&3 + bats_prefix_lines_for_tap_output <"$BATS_OUT" | bats_replace_filename >&3 fi fi if [[ $BATS_GATHER_TEST_OUTPUTS_IN ]]; then @@ -201,7 +201,7 @@ bats_exit_trap() { } # Marks the test as failed due to timeout. -# The actual termination of subprocesses is done via pkill in the background +# The actual termination of subprocesses is done via pkill in the background # process in bats_start_timeout_countdown bats_timeout_trap() { BATS_TIMED_OUT=1 @@ -210,24 +210,24 @@ bats_timeout_trap() { } bats_get_child_processes_of() { # - local -ri parent_pid=${1?} - { - read -ra header - local pid_col ppid_col - for (( i = 0; i < ${#header[@]}; ++i )); do - if [[ ${header[$i]} == "PID" ]]; then - pid_col=$i - fi - if [[ ${header[$i]} == "PPID" ]]; then - ppid_col=$i - fi - done - while read -ra row; do - if (( ${row[$ppid_col]} == parent_pid )); then - printf "%d\n" "${row[$pid_col]}" - fi - done - } < <(ps -ef "$parent_pid") + local -ri parent_pid=${1?} + { + read -ra header + local pid_col ppid_col + for ((i = 0; i < ${#header[@]}; ++i)); do + if [[ ${header[$i]} == "PID" ]]; then + pid_col=$i + fi + if [[ ${header[$i]} == "PPID" ]]; then + ppid_col=$i + fi + done + while read -ra row; do + if ((${row[$ppid_col]} == parent_pid)); then + printf "%d\n" "${row[$pid_col]}" + fi + done + } < <(ps -ef "$parent_pid") } bats_kill_childprocesses_of() { # @@ -248,7 +248,7 @@ bats_kill_childprocesses_of() { # # Ruled out: # USR1/2 - not available on Windows # SIGALRM - interferes with sleep: -# "sleep(3) may be implemented using SIGALRM; mixing calls to alarm() +# "sleep(3) may be implemented using SIGALRM; mixing calls to alarm() # and sleep(3) is a bad idea." ~ https://linux.die.net/man/2/alarm bats_start_timeout_countdown() { # local -ri timeout=$1 @@ -261,16 +261,16 @@ bats_start_timeout_countdown() { # fi # Start another process to kill the children of this process ( - sleep "$timeout" & - # sleep won't recieve signals, so we use wait below - # and kill sleep explicitly when signalled to do so - # shellcheck disable=SC2064 - trap "kill $!; exit 0" ABRT - wait - if kill -ABRT "$target_pid"; then - # get rid of signal blocking child processes (like sleep) - bats_kill_childprocesses_of "$target_pid" - fi &> /dev/null + sleep "$timeout" & + # sleep won't recieve signals, so we use wait below + # and kill sleep explicitly when signalled to do so + # shellcheck disable=SC2064 + trap "kill $!; exit 0" ABRT + wait + if kill -ABRT "$target_pid"; then + # get rid of signal blocking child processes (like sleep) + bats_kill_childprocesses_of "$target_pid" + fi &>/dev/null ) & } @@ -283,9 +283,9 @@ get_mills_since_epoch() { local ms_since_epoch ms_since_epoch=$(date +%s%N) if [[ "$ms_since_epoch" == *N || "${#ms_since_epoch}" -lt 19 ]]; then - ms_since_epoch=$(( $(date +%s) * 1000 )) + ms_since_epoch=$(($(date +%s) * 1000)) else - ms_since_epoch=$(( ms_since_epoch / 1000000 )) + ms_since_epoch=$((ms_since_epoch / 1000000)) fi printf "%d\n" "$ms_since_epoch" diff --git a/libexec/bats-core/bats-format-junit b/libexec/bats-core/bats-format-junit index a649bdb787..79acdf2a7c 100755 --- a/libexec/bats-core/bats-format-junit +++ b/libexec/bats-core/bats-format-junit @@ -6,12 +6,11 @@ source "$BATS_ROOT/lib/bats-core/formatter.bash" BASE_PATH=. - while [[ "$#" -ne 0 ]]; do case "$1" in - --base-path) - shift - normalize_base_path BASE_PATH "$1" + --base-path) + shift + normalize_base_path BASE_PATH "$1" ;; esac shift @@ -19,7 +18,7 @@ done init_suite() { suite_test_exec_time=0 - # since we have to print the suite header before its contents but we don't know the contents before the header, + # since we have to print the suite header before its contents but we don't know the contents before the header, # we have to buffer the contents _suite_buffer="" test_result_state="" # declare for the first flush, when no test has been encountered @@ -68,7 +67,7 @@ suite_header() { file_header() { timestamp=$(date -u +"%Y-%m-%dT%H:%M:%S") printf "\n" \ - "$(xml_escape "${class}")" "${file_count}" "${file_failures}" "${file_skipped}" "$(milliseconds_to_seconds "${file_exec_time}")" "${timestamp}" "$(host)" + "$(xml_escape "${class}")" "${file_count}" "${file_failures}" "${file_skipped}" "$(milliseconds_to_seconds "${file_exec_time}")" "${timestamp}" "$(host)" } file_footer() { @@ -111,7 +110,10 @@ xml_escape() { suite_buffer() { local output - output="$("$@"; printf "x")" # use x marker to avoid losing trailing newlines + output="$( + "$@" + printf "x" + )" # use x marker to avoid losing trailing newlines _suite_buffer="${_suite_buffer}${output%x}" } @@ -122,7 +124,10 @@ suite_flush() { buffer() { local output - output="$("$@"; printf "x")" # use x marker to avoid losing trailing newlines + output="$( + "$@" + printf "x" + )" # use x marker to avoid losing trailing newlines _buffer="${_buffer}${output%x}" } @@ -216,17 +221,17 @@ bats_tap_stream_not_ok() { # bats_tap_stream_comment() { # local comment="$1" scope="$2" case "$scope" in - begin) - # everything that happens between begin and [not] ok is FD3 output from the test - log_system_out "$comment" + begin) + # everything that happens between begin and [not] ok is FD3 output from the test + log_system_out "$comment" ;; - ok) - # non failed tests can produce FD3 output - log_system_out "$comment" + ok) + # non failed tests can produce FD3 output + log_system_out "$comment" ;; - *) - # everything else is considered error output - log "$1" + *) + # everything else is considered error output + log "$1" ;; esac } @@ -235,7 +240,7 @@ bats_tap_stream_suite() { # flush_log suite_buffer finish_file init_file - class="${1/$BASE_PATH}" + class="${1/$BASE_PATH/}" } bats_tap_stream_unknown() { # diff --git a/libexec/bats-core/bats-format-pretty b/libexec/bats-core/bats-format-pretty index 5a74075d1b..2b03eed8ea 100755 --- a/libexec/bats-core/bats-format-pretty +++ b/libexec/bats-core/bats-format-pretty @@ -83,7 +83,7 @@ finish_test() { fi fi advance - move_down $(( line_backoff_count - 1 )) + move_down $((line_backoff_count - 1)) } pass() { @@ -117,13 +117,13 @@ timeout() { log() { case ${test_result} in - pass) + pass) clear_color ;; - fail) + fail) set_color 1 ;; - timeout) + timeout) set_color 3 ;; esac @@ -132,7 +132,7 @@ log() { } summary() { - if [ "$failures" -eq 0 ] ; then + if [ "$failures" -eq 0 ]; then set_color 2 bold else set_color 1 bold @@ -152,7 +152,7 @@ summary() { buffer ', %d skipped' "$skipped" fi - if (( timed_out > 0 )); then + if ((timed_out > 0)); then buffer ', %d timed out' "$timed_out" fi @@ -276,7 +276,7 @@ bats_tap_stream_ok() { index="$1" name="$2" ((++passed)) - + pass "${BATS_FORMATTER_TEST_DURATION:-}" } @@ -290,7 +290,7 @@ bats_tap_stream_skipped() { bats_tap_stream_not_ok() { index="$1" name="$2" - + if [[ ${BATS_FORMATTER_TEST_TIMEOUT-x} != x ]]; then timeout "${BATS_FORMATTER_TEST_DURATION:-}" "${BATS_FORMATTER_TEST_TIMEOUT}s" ((++timed_out)) @@ -298,7 +298,7 @@ bats_tap_stream_not_ok() { fail "${BATS_FORMATTER_TEST_DURATION:-}" ((++failures)) fi - + } bats_tap_stream_comment() { # @@ -307,11 +307,11 @@ bats_tap_stream_comment() { # if [[ $line_backoff_count -eq 0 && $scope == begin ]]; then # if this is the first line after begin, go down one line buffer "\n" - (( ++line_backoff_count )) # prefix-increment to avoid "error" due to returning 0 + ((++line_backoff_count)) # prefix-increment to avoid "error" due to returning 0 fi - (( ++line_backoff_count )) - (( line_backoff_count += ${#1} / screen_width)) # account for linebreaks due to length + ((++line_backoff_count)) + ((line_backoff_count += ${#1} / screen_width)) # account for linebreaks due to length log "$1" } @@ -329,18 +329,18 @@ bats_tap_stream_suite() { line_backoff_count=0 bats_tap_stream_unknown() { # - local scope=$2 - # count the lines we printed after the begin text, (or after suite, in case of syntax errors) - if [[ $line_backoff_count -eq 0 && ( $scope == begin || $scope == suite )]]; then - # if this is the first line after begin, go down one line - buffer "\n" - (( ++line_backoff_count )) # prefix-increment to avoid "error" due to returning 0 - fi + local scope=$2 + # count the lines we printed after the begin text, (or after suite, in case of syntax errors) + if [[ $line_backoff_count -eq 0 && ($scope == begin || $scope == suite) ]]; then + # if this is the first line after begin, go down one line + buffer "\n" + ((++line_backoff_count)) # prefix-increment to avoid "error" due to returning 0 + fi - (( ++line_backoff_count )) - (( line_backoff_count += ${#1} / screen_width)) # account for linebreaks due to length - buffer "%s\n" "$1" - flush + ((++line_backoff_count)) + ((line_backoff_count += ${#1} / screen_width)) # account for linebreaks due to length + buffer "%s\n" "$1" + flush } bats_parse_internal_extended_tap diff --git a/libexec/bats-core/bats-format-tap b/libexec/bats-core/bats-format-tap index 63eebf94c1..4aed2c140c 100755 --- a/libexec/bats-core/bats-format-tap +++ b/libexec/bats-core/bats-format-tap @@ -6,50 +6,50 @@ trap '' INT source "$BATS_ROOT/lib/bats-core/formatter.bash" bats_tap_stream_plan() { - printf "1..%d\n" "$1" + printf "1..%d\n" "$1" } bats_tap_stream_begin() { # - : + : } bats_tap_stream_ok() { # [ - printf "ok %d %s" "$1" "$2" - if [[ "${BATS_FORMATTER_TEST_DURATION-x}" != x ]]; then - printf " # in %d ms" "$BATS_FORMATTER_TEST_DURATION" - fi - printf "\n" + printf "ok %d %s" "$1" "$2" + if [[ "${BATS_FORMATTER_TEST_DURATION-x}" != x ]]; then + printf " # in %d ms" "$BATS_FORMATTER_TEST_DURATION" + fi + printf "\n" } bats_tap_stream_not_ok() { # - printf "not ok %d %s" "$1" "$2" - if [[ "${BATS_FORMATTER_TEST_DURATION-x}" != x ]]; then - printf " # in %d ms" "$BATS_FORMATTER_TEST_DURATION" - fi - if [[ "${BATS_FORMATTER_TEST_TIMEOUT-x}" != x ]]; then - printf " # timeout after %d s" "${BATS_FORMATTER_TEST_TIMEOUT}" - fi - printf "\n" + printf "not ok %d %s" "$1" "$2" + if [[ "${BATS_FORMATTER_TEST_DURATION-x}" != x ]]; then + printf " # in %d ms" "$BATS_FORMATTER_TEST_DURATION" + fi + if [[ "${BATS_FORMATTER_TEST_TIMEOUT-x}" != x ]]; then + printf " # timeout after %d s" "${BATS_FORMATTER_TEST_TIMEOUT}" + fi + printf "\n" } bats_tap_stream_skipped() { # - if [[ $# -eq 3 ]]; then - printf "ok %d %s # skip %s\n" "$1" "$2" "$3" - else - printf "ok %d %s # skip\n" "$1" "$2" - fi + if [[ $# -eq 3 ]]; then + printf "ok %d %s # skip %s\n" "$1" "$2" "$3" + else + printf "ok %d %s # skip\n" "$1" "$2" + fi } bats_tap_stream_comment() { # - printf "# %s\n" "$1" + printf "# %s\n" "$1" } bats_tap_stream_suite() { # - : + : } -bats_tap_stream_unknown() { # - printf "%s\n" "$1" +bats_tap_stream_unknown() { # + printf "%s\n" "$1" } -bats_parse_internal_extended_tap \ No newline at end of file +bats_parse_internal_extended_tap diff --git a/libexec/bats-core/bats-format-tap13 b/libexec/bats-core/bats-format-tap13 index 5ec96bf92a..98a3ffafbf 100755 --- a/libexec/bats-core/bats-format-tap13 +++ b/libexec/bats-core/bats-format-tap13 @@ -30,60 +30,60 @@ bats_tap_stream_plan() { } bats_tap_stream_begin() { # - : + : } bats_tap_stream_ok() { # - close_previous_yaml_block - number_of_printed_log_lines_for_this_test_so_far=0 - printf "ok %d %s\n" "$1" "$2" - if [[ "${BATS_FORMATTER_TEST_DURATION-x}" != x ]]; then - add_yaml_entry "duration_ms" "${BATS_FORMATTER_TEST_DURATION}" - fi + close_previous_yaml_block + number_of_printed_log_lines_for_this_test_so_far=0 + printf "ok %d %s\n" "$1" "$2" + if [[ "${BATS_FORMATTER_TEST_DURATION-x}" != x ]]; then + add_yaml_entry "duration_ms" "${BATS_FORMATTER_TEST_DURATION}" + fi } pass_on_optional_data() { - if [[ "${BATS_FORMATTER_TEST_DURATION-x}" != x ]]; then - add_yaml_entry "duration_ms" "${BATS_FORMATTER_TEST_DURATION}" - fi - if [[ "${BATS_FORMATTER_TEST_TIMEOUT-x}" != x ]]; then - add_yaml_entry "timeout_sec" "${BATS_FORMATTER_TEST_TIMEOUT}" - fi + if [[ "${BATS_FORMATTER_TEST_DURATION-x}" != x ]]; then + add_yaml_entry "duration_ms" "${BATS_FORMATTER_TEST_DURATION}" + fi + if [[ "${BATS_FORMATTER_TEST_TIMEOUT-x}" != x ]]; then + add_yaml_entry "timeout_sec" "${BATS_FORMATTER_TEST_TIMEOUT}" + fi } bats_tap_stream_not_ok() { # - close_previous_yaml_block - number_of_printed_log_lines_for_this_test_so_far=0 - - printf "not ok %d %s\n" "$1" "$2" - pass_on_optional_data + close_previous_yaml_block + number_of_printed_log_lines_for_this_test_so_far=0 + + printf "not ok %d %s\n" "$1" "$2" + pass_on_optional_data } bats_tap_stream_skipped() { # - close_previous_yaml_block - number_of_printed_log_lines_for_this_test_so_far=0 - - printf "not ok %d %s # SKIP %s\n" "$1" "$2" "$3" - pass_on_optional_data + close_previous_yaml_block + number_of_printed_log_lines_for_this_test_so_far=0 + + printf "not ok %d %s # SKIP %s\n" "$1" "$2" "$3" + pass_on_optional_data } bats_tap_stream_comment() { # - if [[ $number_of_printed_log_lines_for_this_test_so_far -eq 0 ]]; then - add_yaml_entry "message" "|" # use a multiline string for this entry - fi - ((++number_of_printed_log_lines_for_this_test_so_far)) - printf " %s\n" "$1" + if [[ $number_of_printed_log_lines_for_this_test_so_far -eq 0 ]]; then + add_yaml_entry "message" "|" # use a multiline string for this entry + fi + ((++number_of_printed_log_lines_for_this_test_so_far)) + printf " %s\n" "$1" } bats_tap_stream_suite() { # - : + : } -bats_tap_stream_unknown() { # - : +bats_tap_stream_unknown() { # + : } bats_parse_internal_extended_tap # close the final block if there was one -close_previous_yaml_block \ No newline at end of file +close_previous_yaml_block diff --git a/libexec/bats-core/bats-preprocess b/libexec/bats-core/bats-preprocess index 4fe84dfe56..5ef831043d 100755 --- a/libexec/bats-core/bats-preprocess +++ b/libexec/bats-core/bats-preprocess @@ -45,9 +45,9 @@ extract_tags() { # local -a tags=() if [[ $tags_string =~ $BATS_VALID_TAGS_PATTERN ]]; then - IFS=, read -ra tags <<< "$tags_string" + IFS=, read -ra tags <<<"$tags_string" local -ri length=${#tags[@]} - for (( i = 0; i < length; ++i )); do + for ((i = 0; i < length; ++i)); do local element="tags[$i]" bats_trim "$element" "${!element}" 2>/dev/null # printf on bash 3 will complain but work anyways if [[ -z "${!element}" && -n "${CHECK_BATS_COMMENT_COMMANDS:-}" ]]; then @@ -58,10 +58,10 @@ extract_tags() { # done elif [[ -n "${CHECK_BATS_COMMENT_COMMANDS:-}" ]]; then printf "%s:%d: Error: Invalid %s: '%s'. " "$test_file" "$line_number" "$tag_type" "$tags_string" - printf "Valid tags must match %s and be separated with comma (and optional spaces)\n" "$BATS_VALID_TAG_PATTERN" + printf "Valid tags must match %s and be separated with comma (and optional spaces)\n" "$BATS_VALID_TAG_PATTERN" exit_code=1 fi >&2 - if (( ${#tags[@]} > 0)); then + if ((${#tags[@]} > 0)); then eval "$tag_type=(\"\${tags[@]}\")" else eval "$tag_type=()" @@ -77,7 +77,7 @@ line_number=0 exit_code=0 { while IFS= read -r line; do - (( ++line_number )) + ((++line_number)) line="${line//$'\r'/}" if [[ "$line" =~ $BATS_TEST_PATTERN ]] || [[ "$line" =~ $BATS_TEST_PATTERN_COMMENT ]]; then name="${BASH_REMATCH[1]#[\'\"]}" @@ -87,8 +87,8 @@ exit_code=0 printf '%s() { bats_test_begin "%s"; %s\n' "${encoded_name:?}" "$name" "$body" || : bats_append_arrays_as_args \ - test_tags file_tags \ - -- bats_sort tags + test_tags file_tags \ + -- bats_sort tags if [[ -z "$BATS_TEST_FILTER" || "$name" =~ $BATS_TEST_FILTER ]]; then IFS=, tests+=("--tags '${tags[*]-}' $encoded_name") @@ -98,12 +98,12 @@ exit_code=0 else if [[ "$line" =~ $BATS_COMMENT_COMMAND_PATTERN ]]; then command=${BASH_REMATCH[1]} - case $command in - 'test_tags='*) - extract_tags test_tags "${command#test_tags=}" + case $command in + 'test_tags='*) + extract_tags test_tags "${command#test_tags=}" ;; - 'file_tags='*) - extract_tags file_tags "${command#file_tags=}" + 'file_tags='*) + extract_tags file_tags "${command#file_tags=}" ;; esac fi @@ -116,4 +116,4 @@ for test_name in "${tests[@]}"; do printf 'bats_test_function %s\n' "$test_name" done -exit $exit_code \ No newline at end of file +exit $exit_code diff --git a/shellcheck.sh b/shellcheck.sh index fe31b0ed7c..3087264452 100755 --- a/shellcheck.sh +++ b/shellcheck.sh @@ -3,17 +3,18 @@ set -e targets=() -while IFS= read -r -d $'\0'; do - targets+=("$REPLY") +while IFS= read -r -d $'\0'; do + targets+=("$REPLY") done < <( - find . -type f \( -name \*.bash -o -name \*.sh \) -print0; \ - find . -type f -name '*.bats' -not -name '*_no_shellcheck*' -print0; \ - find libexec -type f -print0; - find bin -type f -print0) + find . -type f \( -name \*.bash -o -name \*.sh \) -print0 + find . -type f -name '*.bats' -not -name '*_no_shellcheck*' -print0 + find libexec -type f -print0 + find bin -type f -print0 +) if [[ $1 == --list ]]; then - printf "%s\n" "${targets[@]}" - exit 0 + printf "%s\n" "${targets[@]}" + exit 0 fi LC_ALL=C.UTF-8 shellcheck "${targets[@]}" diff --git a/test/bats.bats b/test/bats.bats index dee9ce9cc8..274f40caf6 100755 --- a/test/bats.bats +++ b/test/bats.bats @@ -132,7 +132,7 @@ setup() { [ "${#lines[@]}" -eq 4 ] [ "${lines[1]}" = 'not ok 1 a failing test' ] [ "${lines[2]}" = "# (in test file $RELATIVE_FIXTURE_ROOT/failing_with_bash_expression.bats, line 3)" ] - [ "${lines[3]}" = "# \`(( 1 == 2 ))' failed" ] + [ "${lines[3]}" = "# \`((1 == 2))' failed" ] } @test "failing negated command logs correct line number" { @@ -197,8 +197,8 @@ setup() { @test "failing test with teardown failure" { PASS=0 reentrant_run bats "$FIXTURE_ROOT/failing_teardown.bats" [ $status -eq 1 ] - [ "${lines[1]}" = 'not ok 1 truth' ] - [ "${lines[2]}" = "# (in test file $RELATIVE_FIXTURE_ROOT/failing_teardown.bats, line 6)" ] + [ "${lines[1]}" = 'not ok 1 truth' ] + [ "${lines[2]}" = "# (in test file $RELATIVE_FIXTURE_ROOT/failing_teardown.bats, line 6)" ] [ "${lines[3]}" = $'# `[ "$PASS" = 1 ]\' failed' ] } @@ -218,8 +218,8 @@ setup() { @test "output is discarded for passing tests and printed for failing tests" { reentrant_run bats "$FIXTURE_ROOT/output.bats" [ $status -eq 1 ] - [ "${lines[6]}" = '# failure stdout 1' ] - [ "${lines[7]}" = '# failure stdout 2' ] + [ "${lines[6]}" = '# failure stdout 1' ] + [ "${lines[7]}" = '# failure stdout 2' ] [ "${lines[11]}" = '# failure stderr' ] } @@ -302,13 +302,13 @@ setup() { } @test "single-line tests" { - reentrant_run bats "$FIXTURE_ROOT/single_line_no_shellcheck.bats" + reentrant_run bats --no-tempdir-cleanup "$FIXTURE_ROOT/single_line_no_shellcheck.bats" [ $status -eq 1 ] - [ "${lines[1]}" = 'ok 1 empty' ] - [ "${lines[2]}" = 'ok 2 passing' ] - [ "${lines[3]}" = 'ok 3 input redirection' ] - [ "${lines[4]}" = 'not ok 4 failing' ] - [ "${lines[5]}" = "# (in test file $RELATIVE_FIXTURE_ROOT/single_line_no_shellcheck.bats, line 9)" ] + [ "${lines[1]}" = 'ok 1 empty' ] + [ "${lines[2]}" = 'ok 2 passing' ] + [ "${lines[3]}" = 'ok 3 input redirection' ] + [ "${lines[4]}" = 'not ok 4 failing' ] + [ "${lines[5]}" = "# (in test file $RELATIVE_FIXTURE_ROOT/single_line_no_shellcheck.bats, line 9)" ] [ "${lines[6]}" = $'# `@test "failing" { false; }\' failed' ] } @@ -344,15 +344,15 @@ setup() { # PATH required for windows # HOME required to avoid error from GNU Parallel - # Run Bats under SHELLOPTS=nounset (recursive `set -u`) to catch + # Run Bats under SHELLOPTS=nounset (recursive `set -u`) to catch # as many unset variable accesses as possible. 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" + "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 <&2 - return 1 + 1) + [ "${lines[$((outputOffset + 1))]}" = "# (in test file $RELATIVE_FIXTURE_ROOT/external_function_calls.bats, line $currentErrorLine)" ] + outputOffset=$((outputOffset + 3)) + ;; + 2) + [[ "${lines[$((outputOffset + 1))]}" =~ ^'# (from function `'.*\'' in file '.*'/test_helper.bash, line '[0-9]+,$ ]] + [ "${lines[$((outputOffset + 2))]}" = "# in test file $RELATIVE_FIXTURE_ROOT/external_function_calls.bats, line $currentErrorLine)" ] + outputOffset=$((outputOffset + 4)) + ;; + *) + printf 'error: stackdepth=%s not implemented\n' "${stackdepth}" >&2 + return 1 + ;; esac currentErrorLine=$((currentErrorLine + linesPerTest)) done @@ -632,10 +633,13 @@ END_OF_ERR_MSG # when the process is gone, we cannot deliver a signal anymore, getting non-zero from kill run kill -0 -- -$SUBPROCESS_PID - [[ $status -ne 0 ]] \ - || (kill -9 -- -$SUBPROCESS_PID; false) - # ^ kill the process for good when SIGINT failed, - # to avoid waiting endlessly for stuck children to finish + [[ $status -ne 0 ]] || + ( + kill -9 -- -$SUBPROCESS_PID + false + ) + # ^ kill the process for good when SIGINT failed, + # to avoid waiting endlessly for stuck children to finish } @test "test comment style" { @@ -734,8 +738,8 @@ END_OF_ERR_MSG [ "$status" -ne 0 ] [ "${lines[0]}" == 1..1 ] [ "${lines[1]}" == 'not ok 1 setup_file failed' ] - [ "${lines[2]}" == "# (from function \`helper' in file $RELATIVE_FIXTURE_ROOT/failure_in_free_code.bats, line 4," ] - [ "${lines[3]}" == "# in test file $RELATIVE_FIXTURE_ROOT/failure_in_free_code.bats, line 7)" ] + [ "${lines[2]}" == "# (from function \`helper' in file $RELATIVE_FIXTURE_ROOT/failure_in_free_code.bats, line 2," ] + [ "${lines[3]}" == "# in test file $RELATIVE_FIXTURE_ROOT/failure_in_free_code.bats, line 5)" ] [ "${lines[4]}" == "# \`helper' failed" ] } @@ -743,25 +747,31 @@ END_OF_ERR_MSG if [[ "${BATS_NUMBER_OF_PARALLEL_JOBS:-1}" -gt 1 ]]; then skip "Aborts don't work in parallel mode" fi - + # shellcheck disable=SC2031,SC2030 export TEMPFILE="$BATS_TEST_TMPDIR/$BATS_TEST_NAME.log" # guarantee that background processes get their own process group -> pid=pgid set -m - + load 'concurrent-coordination' # shellcheck disable=SC2031,SC2030 export SINGLE_USE_LATCH_DIR="${BATS_SUITE_TMPDIR}" # we cannot use run for a background task, so we have to store the output for later - bats "$FIXTURE_ROOT/hang_in_test.bats" --tap >"$TEMPFILE" 2>&1 & # don't block execution, or we cannot send signals + bats "$FIXTURE_ROOT/hang_in_test.bats" --tap >"$TEMPFILE" 2>&1 & # don't block execution, or we cannot send signals SUBPROCESS_PID=$! - single-use-latch::wait hang_in_test 1 10 || (cat "$TEMPFILE"; false) # still forward output on timeout + single-use-latch::wait hang_in_test 1 10 || ( + cat "$TEMPFILE" + false + ) # still forward output on timeout # emulate CTRL-C by sending SIGINT to the whole process group - kill -SIGINT -- -$SUBPROCESS_PID || (cat "$TEMPFILE"; false) + kill -SIGINT -- -$SUBPROCESS_PID || ( + cat "$TEMPFILE" + false + ) # the test suite must be marked as failed! wait $SUBPROCESS_PID && return 1 @@ -778,7 +788,7 @@ END_OF_ERR_MSG @test "CTRL-C aborts and fails the current run" { # shellcheck disable=SC2034 BATS_TEST_RETRIES=2 - + if [[ "${BATS_NUMBER_OF_PARALLEL_JOBS:-1}" -gt 1 ]]; then skip "Aborts don't work in parallel mode" fi @@ -788,25 +798,28 @@ END_OF_ERR_MSG # guarantee that background processes get their own process group -> pid=pgid set -m - + load 'concurrent-coordination' # shellcheck disable=SC2031,SC2030 export SINGLE_USE_LATCH_DIR="${BATS_SUITE_TMPDIR}" # we cannot use run for a background task, so we have to store the output for later - bats "$FIXTURE_ROOT/hang_in_run.bats" --tap >"$TEMPFILE" 2>&1 & # don't block execution, or we cannot send signals + bats "$FIXTURE_ROOT/hang_in_run.bats" --tap >"$TEMPFILE" 2>&1 & # don't block execution, or we cannot send signals SUBPROCESS_PID=$! - + single-use-latch::wait hang_in_run 1 10 # emulate CTRL-C by sending SIGINT to the whole process group - kill -SIGINT -- -$SUBPROCESS_PID || (cat "$TEMPFILE"; false) + kill -SIGINT -- -$SUBPROCESS_PID || ( + cat "$TEMPFILE" + false + ) # the test suite must be marked as failed! wait $SUBPROCESS_PID && return 1 run cat "$TEMPFILE" - + [ "${lines[1]}" == "not ok 1 test" ] # due to scheduling the exact line will vary but we should exit with 130 [[ "${lines[3]}" == *"failed with status 130" ]] || false @@ -825,25 +838,28 @@ END_OF_ERR_MSG # guarantee that background processes get their own process group -> pid=pgid set -m - + load 'concurrent-coordination' # shellcheck disable=SC2031,SC2030 export SINGLE_USE_LATCH_DIR="${BATS_SUITE_TMPDIR}" # we cannot use run for a background task, so we have to store the output for later - bats "$FIXTURE_ROOT/hang_after_run.bats" --tap >"$TEMPFILE" 2>&1 & # don't block execution, or we cannot send signals + bats "$FIXTURE_ROOT/hang_after_run.bats" --tap >"$TEMPFILE" 2>&1 & # don't block execution, or we cannot send signals SUBPROCESS_PID=$! - + single-use-latch::wait hang_after_run 1 10 # emulate CTRL-C by sending SIGINT to the whole process group - kill -SIGINT -- -$SUBPROCESS_PID || (cat "$TEMPFILE"; false) + kill -SIGINT -- -$SUBPROCESS_PID || ( + cat "$TEMPFILE" + false + ) # the test suite must be marked as failed! wait $SUBPROCESS_PID && return 1 run cat "$TEMPFILE" - + [ "${lines[1]}" == "not ok 1 test" ] # due to scheduling the exact line will vary but we should exit with 130 [[ "${lines[3]}" == *"failed with status 130" ]] || false @@ -860,19 +876,22 @@ END_OF_ERR_MSG # guarantee that background processes get their own process group -> pid=pgid set -m - + load 'concurrent-coordination' # shellcheck disable=SC2031,SC2030 export SINGLE_USE_LATCH_DIR="${BATS_SUITE_TMPDIR}" # we cannot use run for a background task, so we have to store the output for later - bats "$FIXTURE_ROOT/hang_in_teardown.bats" --tap >"$TEMPFILE" 2>&1 & # don't block execution, or we cannot send signals + bats "$FIXTURE_ROOT/hang_in_teardown.bats" --tap >"$TEMPFILE" 2>&1 & # don't block execution, or we cannot send signals SUBPROCESS_PID=$! - + single-use-latch::wait hang_in_teardown 1 10 # emulate CTRL-C by sending SIGINT to the whole process group - kill -SIGINT -- -$SUBPROCESS_PID || (cat "$TEMPFILE"; false) + kill -SIGINT -- -$SUBPROCESS_PID || ( + cat "$TEMPFILE" + false + ) # the test suite must be marked as failed! wait $SUBPROCESS_PID && return 1 @@ -896,19 +915,22 @@ END_OF_ERR_MSG # guarantee that background processes get their own process group -> pid=pgid set -m - + load 'concurrent-coordination' # shellcheck disable=SC2031,SC2030 export SINGLE_USE_LATCH_DIR="${BATS_SUITE_TMPDIR}" # we cannot use run for a background task, so we have to store the output for later - bats "$FIXTURE_ROOT/hang_in_setup_file.bats" --tap >"$TEMPFILE" 2>&1 & # don't block execution, or we cannot send signals + bats "$FIXTURE_ROOT/hang_in_setup_file.bats" --tap >"$TEMPFILE" 2>&1 & # don't block execution, or we cannot send signals SUBPROCESS_PID=$! - + single-use-latch::wait hang_in_setup_file 1 10 # emulate CTRL-C by sending SIGINT to the whole process group - kill -SIGINT -- -$SUBPROCESS_PID || (cat "$TEMPFILE"; false) + kill -SIGINT -- -$SUBPROCESS_PID || ( + cat "$TEMPFILE" + false + ) # the test suite must be marked as failed! wait $SUBPROCESS_PID && return 1 @@ -931,19 +953,22 @@ END_OF_ERR_MSG # guarantee that background processes get their own process group -> pid=pgid set -m - + load 'concurrent-coordination' # shellcheck disable=SC2031 export SINGLE_USE_LATCH_DIR="${BATS_SUITE_TMPDIR}" # we cannot use run for a background task, so we have to store the output for later - bats "$FIXTURE_ROOT/hang_in_teardown_file.bats" --tap >"$TEMPFILE" 2>&1 & # don't block execution, or we cannot send signals + bats "$FIXTURE_ROOT/hang_in_teardown_file.bats" --tap >"$TEMPFILE" 2>&1 & # don't block execution, or we cannot send signals SUBPROCESS_PID=$! - + single-use-latch::wait hang_in_teardown_file 1 10 # emulate CTRL-C by sending SIGINT to the whole process group - kill -SIGINT -- -$SUBPROCESS_PID || (cat "$TEMPFILE"; false) + kill -SIGINT -- -$SUBPROCESS_PID || ( + cat "$TEMPFILE" + false + ) # the test suite must be marked as failed! wait $SUBPROCESS_PID && return 1 @@ -960,17 +985,16 @@ END_OF_ERR_MSG [ "${lines[6]}" == "# bats warning: Executed 2 instead of expected 1 tests" ] } - @test "single star in output is not treated as a glob" { - star(){ echo '*'; } - + star() { echo '*'; } + run star [ "${lines[0]}" = '*' ] } @test "multiple stars in output are not treated as a glob" { - stars(){ echo '**'; } - + stars() { echo '**'; } + run stars [ "${lines[0]}" = '**' ] } @@ -983,13 +1007,13 @@ END_OF_ERR_MSG run "./shellcheck.sh" --list echo "$output" - grep bin/bats <<< "$output" - grep contrib/ <<< "$output" - grep docker/ <<< "$output" - grep lib/bats-core/ <<< "$output" - grep libexec/bats-core/ <<< "$output" - grep test/fixtures <<< "$output" - grep install.sh <<< "$output" + grep bin/bats <<<"$output" + grep contrib/ <<<"$output" + grep docker/ <<<"$output" + grep lib/bats-core/ <<<"$output" + grep libexec/bats-core/ <<<"$output" + grep test/fixtures <<<"$output" + grep install.sh <<<"$output" } @test "BATS_RUN_COMMAND: test content of variable" { @@ -1073,8 +1097,8 @@ END_OF_ERR_MSG # even outputs of successful tests are generated OUTPUT=$(<"$OUTPUT_DIR/1-no failure prints no output.log") # own line to trigger failure if file does not exist - [ "$OUTPUT" == "success" ] - + [ "$OUTPUT" == "success" ] + OUTPUT=$(<"$OUTPUT_DIR/2-failure prints output.log") [ "$OUTPUT" == "fail hard" ] @@ -1131,7 +1155,6 @@ END_OF_ERR_MSG # shellcheck disable=SC2016 [ "${lines[3]}" == '# `eval "( exit ${STATUS:-1} )"` failed' ] - export BATS_CODE_QUOTE_STYLE='😁😂' if [[ ${#BATS_CODE_QUOTE_STYLE} -ne 2 ]]; then # for example, this happens on windows! @@ -1158,8 +1181,8 @@ END_OF_ERR_MSG REENTRANT_RUN_PRESERVE+=(BATS_BEGIN_CODE_QUOTE BATS_END_CODE_QUOTE) # shellcheck disable=SC2016 BATS_CODE_QUOTE_STYLE=custom \ - BATS_BEGIN_CODE_QUOTE='$(' \ - BATS_END_CODE_QUOTE=')' \ + BATS_BEGIN_CODE_QUOTE='$(' \ + BATS_END_CODE_QUOTE=')' \ reentrant_run -1 bats --tap "${FIXTURE_ROOT}/failing.bats" # shellcheck disable=SC2016 [ "${lines[3]}" == '# $(eval "( exit ${STATUS:-1} )") failed' ] @@ -1206,9 +1229,9 @@ END_OF_ERR_MSG normalize_variable_list() { # `declare -p`: declare -X VAR_NAME="VALUE" while IFS=' =' read -r _declare _ variable _; do - if [[ "$_declare" == declare ]]; then # skip multiline variables' values - printf "%s\n" "$variable" - fi + if [[ "$_declare" == declare ]]; then # skip multiline variables' values + printf "%s\n" "$variable" + fi done | sort } fi @@ -1219,28 +1242,28 @@ END_OF_ERR_MSG local BATS_DECLARED_VARIABLES_FILE="${BATS_TEST_TMPDIR}/variables.log" bats_require_minimum_version 1.5.0 # now capture bats @test environment - reentrant_run -0 env -i PATH="$PATH" BATS_DECLARED_VARIABLES_FILE="$BATS_DECLARED_VARIABLES_FILE" bash "${BATS_ROOT}/bin/bats" "${FIXTURE_ROOT}/issue-519.bats" + reentrant_run -0 env -i PATH="$PATH" BATS_DECLARED_VARIABLES_FILE="$BATS_DECLARED_VARIABLES_FILE" bash "${BATS_ROOT}/bin/bats" "${FIXTURE_ROOT}/issue-519.bats" # use function to allow failing via !, run is a bit unwieldy with the pipe and subshells check_no_new_variables() { # -23 -> only look at additions on the bats list ! comm -23 <(normalize_variable_list <"$BATS_DECLARED_VARIABLES_FILE") \ - <(normalize_variable_list <<< "$BASH_DECLARED_VARIABLES" ) \ - | grep -v '^BATS_' # variables that are prefixed with BATS_ don't count + <(normalize_variable_list <<<"$BASH_DECLARED_VARIABLES") | + grep -v '^BATS_' # variables that are prefixed with BATS_ don't count } check_no_new_variables } @test "Don't wait for disowned background jobs to finish because of open FDs (#205)" { - SECONDS=0 - export LOG_FILE="$BATS_TEST_TMPDIR/fds.log" - bats_require_minimum_version 1.5.0 - reentrant_run -0 bats --show-output-of-passing-tests --tap "${FIXTURE_ROOT}/issue-205.bats" - echo "Whole suite took: $SECONDS seconds" - FDS_LOG=$(<"$LOG_FILE") - echo "$FDS_LOG" - [ $SECONDS -lt 10 ] - [[ $FDS_LOG == *'otherfunc fds after: (0 1 2)'* ]] || false - [[ $FDS_LOG == *'setup_file fds after: (0 1 2)'* ]] || false + SECONDS=0 + export LOG_FILE="$BATS_TEST_TMPDIR/fds.log" + bats_require_minimum_version 1.5.0 + reentrant_run -0 bats --show-output-of-passing-tests --tap "${FIXTURE_ROOT}/issue-205.bats" + echo "Whole suite took: $SECONDS seconds" + FDS_LOG=$(<"$LOG_FILE") + echo "$FDS_LOG" + [ $SECONDS -lt 10 ] + [[ $FDS_LOG == *'otherfunc fds after: (0 1 2)'* ]] || false + [[ $FDS_LOG == *'setup_file fds after: (0 1 2)'* ]] || false } @test "Allow for prefixing tests' names with BATS_TEST_NAME_PREFIX" { @@ -1293,7 +1316,7 @@ END_OF_ERR_MSG # without previous recording, all tests should be run [ "${lines[0]}" == 'No recording of previous runs found. Running all tests!' ] [ "${lines[1]}" == '1..4' ] - [ "$(grep -c 'not ok' <<< "$output")" -eq 1 ] + [ "$(grep -c 'not ok' <<<"$output")" -eq 1 ] reentrant_run -1 bats --tap --filter-status failed "many_passing_and_one_failing.bats" # now we should only run the failing test @@ -1301,7 +1324,7 @@ END_OF_ERR_MSG [ "${lines[1]}" == "not ok 1 a failing test" ] # add a new test that was missed before - echo $'@test missed { :; }' >> "many_passing_and_one_failing.bats" + echo $'@test missed { :; }' >>"many_passing_and_one_failing.bats" find .bats/run-logs/ -type f -print -exec cat {} \; @@ -1321,20 +1344,20 @@ END_OF_ERR_MSG # without previous recording, all tests should be run [ "${lines[0]}" == 'No recording of previous runs found. Running all tests!' ] [ "${lines[1]}" == '1..4' ] - [ "$(grep -c 'not ok' <<< "$output")" -eq 1 ] + [ "$(grep -c 'not ok' <<<"$output")" -eq 1 ] reentrant_run -0 bats --tap --filter-status passed "many_passing_and_one_failing.bats" # now we should only run the passed tests [ "${lines[0]}" == 1..3 ] - [ "$(grep -c 'not ok' <<< "$output")" -eq 0 ] + [ "$(grep -c 'not ok' <<<"$output")" -eq 0 ] # add a new test that was missed before - echo $'@test missed { :; }' >> "many_passing_and_one_failing.bats" + echo $'@test missed { :; }' >>"many_passing_and_one_failing.bats" reentrant_run -0 bats --tap --filter-status passed "many_passing_and_one_failing.bats" # now we should only run the passed and missed tests [ "${lines[0]}" == 1..4 ] - [ "$(grep -c 'not ok' <<< "$output")" -eq 0 ] + [ "$(grep -c 'not ok' <<<"$output")" -eq 0 ] [ "${lines[4]}" == "ok 4 missed" ] } @@ -1347,10 +1370,10 @@ END_OF_ERR_MSG # without previous recording, all tests should be run [ "${lines[0]}" == 'No recording of previous runs found. Running all tests!' ] [ "${lines[1]}" == '1..4' ] - [ "$(grep -c -E '^ok' <<< "$output")" -eq 3 ] + [ "$(grep -c -E '^ok' <<<"$output")" -eq 3 ] # add a new test that was missed before - echo $'@test missed { :; }' >> "many_passing_and_one_failing.bats" + echo $'@test missed { :; }' >>"many_passing_and_one_failing.bats" reentrant_run -0 bats --tap --filter-status missed "many_passing_and_one_failing.bats" # now we should only run the missed test @@ -1358,8 +1381,6 @@ END_OF_ERR_MSG [ "${lines[1]}" == "ok 1 missed" ] } - - @test "--filter-status failed gives warning on empty failed test list" { cd "$BATS_TEST_TMPDIR" # don't pollute the source folder cp "$FIXTURE_ROOT/passing.bats" . @@ -1375,9 +1396,9 @@ END_OF_ERR_MSG } enforce_own_process_group() { - set -m - "$@" - } + set -m + "$@" +} @test "--filter-status failed does not update list when run is aborted" { if [[ "${BATS_NUMBER_OF_PARALLEL_JOBS:-1}" -gt 1 ]]; then @@ -1419,12 +1440,12 @@ enforce_own_process_group() { [ "${lines[5]}" == 'not ok 3 Override retries' ] run cat "$LOG" - [ "${lines[0]}" == ' setup_file ' ] # should only be executed once + [ "${lines[0]}" == ' setup_file ' ] # should only be executed once [ "${lines[22]}" == ' teardown_file ' ] # should only be executed once [ "${#lines[@]}" -eq 23 ] # 3x Fail All (give up after 3 tries/2 retries) - run grep test_Fail_all < "$LOG" + run grep test_Fail_all <"$LOG" [ "${lines[0]}" == 'test_Fail_all setup 1' ] # should be executed for each try [ "${lines[1]}" == 'test_Fail_all test_Fail_all 1' ] [ "${lines[2]}" == 'test_Fail_all teardown 1' ] # should be executed for each try @@ -1437,7 +1458,7 @@ enforce_own_process_group() { [ "${#lines[@]}" -eq 9 ] # 2x Fail once (pass second try/first retry) - run grep test_Fail_once < "$LOG" + run grep test_Fail_once <"$LOG" [ "${lines[0]}" == 'test_Fail_once setup 1' ] [ "${lines[1]}" == 'test_Fail_once test_Fail_once 1' ] [ "${lines[2]}" == 'test_Fail_once teardown 1' ] @@ -1447,7 +1468,7 @@ enforce_own_process_group() { [ "${#lines[@]}" -eq 6 ] # 2x Override retries (give up after second try/first retry) - run grep test_Override_retries < "$LOG" + run grep test_Override_retries <"$LOG" [ "${lines[0]}" == 'test_Override_retries setup 1' ] [ "${lines[1]}" == 'test_Override_retries test_Override_retries 1' ] [ "${lines[2]}" == 'test_Override_retries teardown 1' ] diff --git a/test/common.bats b/test/common.bats index 0eaf38c104..8d01a10740 100644 --- a/test/common.bats +++ b/test/common.bats @@ -1,207 +1,204 @@ - @test bats_version_lt { - bats_require_minimum_version 1.5.0 - run ! bats_version_lt 1.0.0 1.0 - [ "$output" = "ERROR: version '1.0' must be of format ..!" ] - - run ! bats_version_lt 1.0 1.0.0 - [ "$output" = "ERROR: version '1.0' must be of format ..!" ] - - - run -0 bats_version_lt 1.0.0 2.0.0 - run -0 bats_version_lt 1.2.0 2.0.0 - run -0 bats_version_lt 1.2.3 2.0.0 - run -0 bats_version_lt 1.0.0 1.1.0 - run -0 bats_version_lt 1.0.2 1.1.0 - run -0 bats_version_lt 1.0.0 1.0.1 - - run -1 bats_version_lt 2.0.0 1.0.0 - run -1 bats_version_lt 2.0.0 1.2.0 - run -1 bats_version_lt 2.0.0 1.2.3 - run -1 bats_version_lt 1.1.0 1.0.0 - run -1 bats_version_lt 1.1.0 1.0.2 - run -1 bats_version_lt 1.0.1 1.0.0 - - run -2 bats_version_lt 1.0.0 1.0.0 + bats_require_minimum_version 1.5.0 + run ! bats_version_lt 1.0.0 1.0 + [ "$output" = "ERROR: version '1.0' must be of format ..!" ] + + run ! bats_version_lt 1.0 1.0.0 + [ "$output" = "ERROR: version '1.0' must be of format ..!" ] + + run -0 bats_version_lt 1.0.0 2.0.0 + run -0 bats_version_lt 1.2.0 2.0.0 + run -0 bats_version_lt 1.2.3 2.0.0 + run -0 bats_version_lt 1.0.0 1.1.0 + run -0 bats_version_lt 1.0.2 1.1.0 + run -0 bats_version_lt 1.0.0 1.0.1 + + run -1 bats_version_lt 2.0.0 1.0.0 + run -1 bats_version_lt 2.0.0 1.2.0 + run -1 bats_version_lt 2.0.0 1.2.3 + run -1 bats_version_lt 1.1.0 1.0.0 + run -1 bats_version_lt 1.1.0 1.0.2 + run -1 bats_version_lt 1.0.1 1.0.0 + + run -2 bats_version_lt 1.0.0 1.0.0 } @test bats_require_minimum_version { - [ "$BATS_GUARANTEED_MINIMUM_VERSION" = 0.0.0 ] # check default + [ "$BATS_GUARANTEED_MINIMUM_VERSION" = 0.0.0 ] # check default - bats_require_minimum_version 0.1.2 # (a version that should be safe not to fail) - [ "${BATS_GUARANTEED_MINIMUM_VERSION}" = 0.1.2 ] + bats_require_minimum_version 0.1.2 # (a version that should be safe not to fail) + [ "${BATS_GUARANTEED_MINIMUM_VERSION}" = 0.1.2 ] - # a higher version should upgrade - bats_require_minimum_version 0.2.3 - [ "${BATS_GUARANTEED_MINIMUM_VERSION}" = 0.2.3 ] + # a higher version should upgrade + bats_require_minimum_version 0.2.3 + [ "${BATS_GUARANTEED_MINIMUM_VERSION}" = 0.2.3 ] - # a lower version should not change - bats_require_minimum_version 0.1.2 - [ "${BATS_GUARANTEED_MINIMUM_VERSION}" = 0.2.3 ] + # a lower version should not change + bats_require_minimum_version 0.1.2 + [ "${BATS_GUARANTEED_MINIMUM_VERSION}" = 0.2.3 ] } @test bats_binary_search { - bats_require_minimum_version 1.5.0 - - run -2 bats_binary_search "search-value" - [ "$output" = "ERROR: bats_binary_search requires exactly 2 arguments: " ] - - # unset array = empty array: a bit unfortunate but we can't tell the difference (on older Bash?) - unset no_array - run -1 bats_binary_search "search-value" "no_array" - - # shellcheck disable=SC2034 - empty_array=() - run -1 bats_binary_search "search-value" "empty_array" - - # shellcheck disable=SC2034 - odd_length_array=(1 2 3) - run -1 bats_binary_search a odd_length_array - run -0 bats_binary_search 1 odd_length_array - run -0 bats_binary_search 2 odd_length_array - run -0 bats_binary_search 3 odd_length_array - - # shellcheck disable=SC2034 - even_length_array=(1 2 3 4) - run -1 bats_binary_search a even_length_array - run -0 bats_binary_search 1 even_length_array - run -0 bats_binary_search 2 even_length_array - run -0 bats_binary_search 3 even_length_array - run -0 bats_binary_search 4 even_length_array + bats_require_minimum_version 1.5.0 + + run -2 bats_binary_search "search-value" + [ "$output" = "ERROR: bats_binary_search requires exactly 2 arguments: " ] + + # unset array = empty array: a bit unfortunate but we can't tell the difference (on older Bash?) + unset no_array + run -1 bats_binary_search "search-value" "no_array" + + # shellcheck disable=SC2034 + empty_array=() + run -1 bats_binary_search "search-value" "empty_array" + + # shellcheck disable=SC2034 + odd_length_array=(1 2 3) + run -1 bats_binary_search a odd_length_array + run -0 bats_binary_search 1 odd_length_array + run -0 bats_binary_search 2 odd_length_array + run -0 bats_binary_search 3 odd_length_array + + # shellcheck disable=SC2034 + even_length_array=(1 2 3 4) + run -1 bats_binary_search a even_length_array + run -0 bats_binary_search 1 even_length_array + run -0 bats_binary_search 2 even_length_array + run -0 bats_binary_search 3 even_length_array + run -0 bats_binary_search 4 even_length_array } @test bats_sort { - local -a empty one_element two_sorted two_elements_reversed three_elements_scrambled - - bats_sort empty - echo "empty(${#empty[@]}): ${empty[*]}" - [ ${#empty[@]} -eq 0 ] - - bats_sort one_element 1 - echo "one_element(${#one_element[@]}): ${one_element[*]}" - [ ${#one_element[@]} -eq 1 ] - [ "${one_element[0]}" = 1 ] - - bats_sort two_sorted 1 2 - echo "two_sorted(${#two_sorted[@]}): ${two_sorted[*]}" - [ ${#two_sorted[@]} -eq 2 ] - [ "${two_sorted[0]}" = 1 ] - [ "${two_sorted[1]}" = 2 ] - - bats_sort two_elements_reversed 2 1 - echo "two_elements_reversed(${#two_elements_reversed[@]}): ${two_elements_reversed[*]}" - [ ${#two_elements_reversed[@]} -eq 2 ] - [ "${two_elements_reversed[0]}" = 1 ] - [ "${two_elements_reversed[1]}" = 2 ] - - bats_sort three_elements_scrambled 2 1 3 - echo "three_elements_scrambled(${#three_elements_scrambled[@]}): ${three_elements_scrambled[*]}" - [ ${#three_elements_scrambled[@]} -eq 3 ] - [ "${three_elements_scrambled[0]}" = 1 ] - [ "${three_elements_scrambled[1]}" = 2 ] - [ "${three_elements_scrambled[2]}" = 3 ] + local -a empty one_element two_sorted two_elements_reversed three_elements_scrambled + + bats_sort empty + echo "empty(${#empty[@]}): ${empty[*]}" + [ ${#empty[@]} -eq 0 ] + + bats_sort one_element 1 + echo "one_element(${#one_element[@]}): ${one_element[*]}" + [ ${#one_element[@]} -eq 1 ] + [ "${one_element[0]}" = 1 ] + + bats_sort two_sorted 1 2 + echo "two_sorted(${#two_sorted[@]}): ${two_sorted[*]}" + [ ${#two_sorted[@]} -eq 2 ] + [ "${two_sorted[0]}" = 1 ] + [ "${two_sorted[1]}" = 2 ] + + bats_sort two_elements_reversed 2 1 + echo "two_elements_reversed(${#two_elements_reversed[@]}): ${two_elements_reversed[*]}" + [ ${#two_elements_reversed[@]} -eq 2 ] + [ "${two_elements_reversed[0]}" = 1 ] + [ "${two_elements_reversed[1]}" = 2 ] + + bats_sort three_elements_scrambled 2 1 3 + echo "three_elements_scrambled(${#three_elements_scrambled[@]}): ${three_elements_scrambled[*]}" + [ ${#three_elements_scrambled[@]} -eq 3 ] + [ "${three_elements_scrambled[0]}" = 1 ] + [ "${three_elements_scrambled[1]}" = 2 ] + [ "${three_elements_scrambled[2]}" = 3 ] } @test bats_all_in { - bats_require_minimum_version 1.5.0 - - local -ra empty=() one=(1) onetwo=(1 2) - # find nothing in any array - run -0 bats_all_in empty - run -0 bats_all_in one - run -0 bats_all_in onetwo - # find single search value in single element array - run -0 bats_all_in one 1 - # find single search values in multi element array - run -0 bats_all_in onetwo 1 - # find multiple search values in multi element array - run -0 bats_all_in onetwo 1 2 - - # don't find in empty array - run -1 bats_all_in empty 1 - # don't find in non empty - run -1 bats_all_in one 2 - # don't find smaller values - run -1 bats_all_in onetwo 0 1 2 - # don't find greater values - run -1 bats_all_in onetwo 1 2 3 + bats_require_minimum_version 1.5.0 + + local -ra empty=() one=(1) onetwo=(1 2) + # find nothing in any array + run -0 bats_all_in empty + run -0 bats_all_in one + run -0 bats_all_in onetwo + # find single search value in single element array + run -0 bats_all_in one 1 + # find single search values in multi element array + run -0 bats_all_in onetwo 1 + # find multiple search values in multi element array + run -0 bats_all_in onetwo 1 2 + + # don't find in empty array + run -1 bats_all_in empty 1 + # don't find in non empty + run -1 bats_all_in one 2 + # don't find smaller values + run -1 bats_all_in onetwo 0 1 2 + # don't find greater values + run -1 bats_all_in onetwo 1 2 3 } @test bats_any_in { - bats_require_minimum_version 1.5.0 - - # shellcheck disable=SC2030,SC2034 - local -ra empty=() one=(1) onetwo=(1 2) - # empty search set is always false - run -1 bats_any_in empty - run -1 bats_any_in one - run -1 bats_any_in onetwo - - # find single search value in single element array - run -0 bats_any_in one 1 - # find single search values in multi element array - run -0 bats_any_in onetwo 2 - # find multiple search values in multi element array - run -0 bats_any_in onetwo 1 2 - - # don't find in empty array - run -1 bats_any_in empty 1 - # don't find in non empty - run -1 bats_any_in one 2 - # don't find smaller values - run -1 bats_any_in onetwo 0 - # don't find greater values - run -1 bats_any_in onetwo 3 + bats_require_minimum_version 1.5.0 + + # shellcheck disable=SC2030,SC2034 + local -ra empty=() one=(1) onetwo=(1 2) + # empty search set is always false + run -1 bats_any_in empty + run -1 bats_any_in one + run -1 bats_any_in onetwo + + # find single search value in single element array + run -0 bats_any_in one 1 + # find single search values in multi element array + run -0 bats_any_in onetwo 2 + # find multiple search values in multi element array + run -0 bats_any_in onetwo 1 2 + + # don't find in empty array + run -1 bats_any_in empty 1 + # don't find in non empty + run -1 bats_any_in one 2 + # don't find smaller values + run -1 bats_any_in onetwo 0 + # don't find greater values + run -1 bats_any_in onetwo 3 } @test bats_trim { - local empty already_trimmed trimmed whitespaces_within - bats_trim empty "" - # shellcheck disable=SC2031 - [ "${empty-NOTSET}" = "" ] + local empty already_trimmed trimmed whitespaces_within + bats_trim empty "" + # shellcheck disable=SC2031 + [ "${empty-NOTSET}" = "" ] - bats_trim already_trimmed "abc" - [ "$already_trimmed" = abc ] + bats_trim already_trimmed "abc" + [ "$already_trimmed" = abc ] - bats_trim trimmed " abc " - [ "$trimmed" = abc ] + bats_trim trimmed " abc " + [ "$trimmed" = abc ] - bats_trim whitespaces_within " a b " - [ "$whitespaces_within" = "a b" ] + bats_trim whitespaces_within " a b " + [ "$whitespaces_within" = "a b" ] } @test bats_append_arrays_as_args { - bats_require_minimum_version 1.5.0 - count_and_print_args() { - echo "$# $*" - } - - run -1 bats_append_arrays_as_args - [ "${lines[0]}" == "Error: append_arrays_as_args is missing a command or -- separator" ] - - run -1 bats_append_arrays_as_args -- - [ "${lines[0]}" == "Error: append_arrays_as_args is missing a command or -- separator" ] - - # shellcheck disable=SC2034 - empty=() - run -0 bats_append_arrays_as_args empty -- count_and_print_args - [ "${lines[0]}" == '0 ' ] - - run -0 bats_append_arrays_as_args -- count_and_print_args - [ "${lines[0]}" == '0 ' ] - - # shellcheck disable=SC2034 - arr=(a) - run -0 bats_append_arrays_as_args arr -- count_and_print_args - [ "${lines[0]}" == '1 a' ] - - # shellcheck disable=SC2034 - arr2=(b) - run -0 bats_append_arrays_as_args arr arr2 -- count_and_print_args - [ "${lines[0]}" == '2 a b' ] - - - run -0 bats_append_arrays_as_args arr empty arr2 -- count_and_print_args - [ "${lines[0]}" == '2 a b' ] -} \ No newline at end of file + bats_require_minimum_version 1.5.0 + count_and_print_args() { + echo "$# $*" + } + + run -1 bats_append_arrays_as_args + [ "${lines[0]}" == "Error: append_arrays_as_args is missing a command or -- separator" ] + + run -1 bats_append_arrays_as_args -- + [ "${lines[0]}" == "Error: append_arrays_as_args is missing a command or -- separator" ] + + # shellcheck disable=SC2034 + empty=() + run -0 bats_append_arrays_as_args empty -- count_and_print_args + [ "${lines[0]}" == '0 ' ] + + run -0 bats_append_arrays_as_args -- count_and_print_args + [ "${lines[0]}" == '0 ' ] + + # shellcheck disable=SC2034 + arr=(a) + run -0 bats_append_arrays_as_args arr -- count_and_print_args + [ "${lines[0]}" == '1 a' ] + + # shellcheck disable=SC2034 + arr2=(b) + run -0 bats_append_arrays_as_args arr arr2 -- count_and_print_args + [ "${lines[0]}" == '2 a b' ] + + run -0 bats_append_arrays_as_args arr empty arr2 -- count_and_print_args + [ "${lines[0]}" == '2 a b' ] +} diff --git a/test/concurrent-coordination.bash b/test/concurrent-coordination.bash index c1ee8d0258..387686be4b 100644 --- a/test/concurrent-coordination.bash +++ b/test/concurrent-coordination.bash @@ -2,64 +2,64 @@ # once this happened, all latecomers will go through immediately! # WARNING: a barrier group consists of all processes with the same barrier name *and* size! single-use-barrier() { # [ []] - local barrier_name="$1" - local barrier_size="$2" - local timeout_in_seconds="${3:-0}" - local sleep_cycle_time="${4:-1}" - # use name and size to distinguish between invocations - # this will block inconsistent sizes on the same name! - local BARRIER_SUFFIX=${barrier_name//\//_}-$barrier_size - local BARRIER_FILE="$BATS_SUITE_TMPDIR/barrier-$BARRIER_SUFFIX" - # mark our entry for all others - # concurrent writes may interleave but should not lose their newlines - echo "in-$$" >> "$BARRIER_FILE" - local start="$SECONDS" - # wait for others to enter - while [[ $(wc -l <"$BARRIER_FILE" ) -lt $barrier_size ]]; do - if [[ $timeout_in_seconds -ne 0 && $(( SECONDS - start )) -gt $timeout_in_seconds ]]; then - mv "$BARRIER_FILE" "$BARRIER_FILE-timeout" - printf "ERROR: single-use-barrier %s timed out\n" "$BARRIER_SUFFIX" >&2 - return 1 - fi - sleep "$sleep_cycle_time" - done - # mark our exit - echo "out-$$" >> "$BARRIER_FILE" + local barrier_name="$1" + local barrier_size="$2" + local timeout_in_seconds="${3:-0}" + local sleep_cycle_time="${4:-1}" + # use name and size to distinguish between invocations + # this will block inconsistent sizes on the same name! + local BARRIER_SUFFIX=${barrier_name//\//_}-$barrier_size + local BARRIER_FILE="$BATS_SUITE_TMPDIR/barrier-$BARRIER_SUFFIX" + # mark our entry for all others + # concurrent writes may interleave but should not lose their newlines + echo "in-$$" >>"$BARRIER_FILE" + local start="$SECONDS" + # wait for others to enter + while [[ $(wc -l <"$BARRIER_FILE") -lt $barrier_size ]]; do + if [[ $timeout_in_seconds -ne 0 && $((SECONDS - start)) -gt $timeout_in_seconds ]]; then + mv "$BARRIER_FILE" "$BARRIER_FILE-timeout" + printf "ERROR: single-use-barrier %s timed out\n" "$BARRIER_SUFFIX" >&2 + return 1 + fi + sleep "$sleep_cycle_time" + done + # mark our exit + echo "out-$$" >>"$BARRIER_FILE" } # block until at least signalling threads have passed the latch # SINGLE_USE_LATCH_DIR must be exported! single-use-latch::wait() { # [ []] - local latch_name="$1" - local latch_size="$2" - local timeout_in_seconds="${3:-0}" - local sleep_cycle_time="${4:-1}" - - local LATCH_FILE - LATCH_FILE="$(single-use-latch::_filename "$latch_name")" - local start="$SECONDS" - while [[ (! -e "$LATCH_FILE") || $(wc -l <"$LATCH_FILE" ) -lt $latch_size ]]; do - if [[ $timeout_in_seconds -ne 0 && $(( SECONDS - start )) -gt $timeout_in_seconds ]]; then - printf "ERROR: single-use-latch %s timed out\n" "$latch_name" >&2 - mv "$LATCH_FILE" "$LATCH_FILE-timeout" - return 1 - fi - sleep "$sleep_cycle_time" - done + local latch_name="$1" + local latch_size="$2" + local timeout_in_seconds="${3:-0}" + local sleep_cycle_time="${4:-1}" + + local LATCH_FILE + LATCH_FILE="$(single-use-latch::_filename "$latch_name")" + local start="$SECONDS" + while [[ (! -e "$LATCH_FILE") || $(wc -l <"$LATCH_FILE") -lt $latch_size ]]; do + if [[ $timeout_in_seconds -ne 0 && $((SECONDS - start)) -gt $timeout_in_seconds ]]; then + printf "ERROR: single-use-latch %s timed out\n" "$latch_name" >&2 + mv "$LATCH_FILE" "$LATCH_FILE-timeout" + return 1 + fi + sleep "$sleep_cycle_time" + done } # signal the waiting process that the latch was passed # this does not block # SINGLE_USE_LATCH_DIR must be exported! single-use-latch::signal() { # - local latch_name="$1" - local LATCH_FILE - LATCH_FILE="$(single-use-latch::_filename "$latch_name")" - # mark our passing - # concurrent process might interleave but will still post their newline - echo "passed-$$" >> "$LATCH_FILE" + local latch_name="$1" + local LATCH_FILE + LATCH_FILE="$(single-use-latch::_filename "$latch_name")" + # mark our passing + # concurrent process might interleave but will still post their newline + echo "passed-$$" >>"$LATCH_FILE" } -single-use-latch::_filename() { # - printf "%s\n" "${SINGLE_USE_LATCH_DIR?}/latch-${1//\//_}" +single-use-latch::_filename() { # + printf "%s\n" "${SINGLE_USE_LATCH_DIR?}/latch-${1//\//_}" } diff --git a/test/file_setup_teardown.bats b/test/file_setup_teardown.bats index 1ca8a42fe2..6c00eb41e9 100644 --- a/test/file_setup_teardown.bats +++ b/test/file_setup_teardown.bats @@ -8,9 +8,9 @@ setup_file() { } @test "setup_file is run once per file" { - # shellcheck disable=SC2031,SC2030 - export LOG="$BATS_TEST_TMPDIR/setup_file_once.log" - bats "$FIXTURE_ROOT/setup_file.bats" + # shellcheck disable=SC2031,SC2030 + export LOG="$BATS_TEST_TMPDIR/setup_file_once.log" + bats "$FIXTURE_ROOT/setup_file.bats" } @test "teardown_file is run once per file" { @@ -23,20 +23,20 @@ setup_file() { # expect to find an entry for the tested file grep 'teardown_file.bats' "$LOG" # it should be the only entry - run wc -l < "$LOG" + run wc -l <"$LOG" [[ $output -eq 1 ]] } @test "setup_file is called correctly in multi file suite" { - # shellcheck disable=SC2031,SC2030 - export LOG="$BATS_TEST_TMPDIR/setup_file_multi_file_suite.log" - reentrant_run bats "$FIXTURE_ROOT/setup_file.bats" "$FIXTURE_ROOT/no_setup_file.bats" "$FIXTURE_ROOT/setup_file2.bats" - [[ $status -eq 0 ]] - run wc -l < "$LOG" - # each setup_file[2].bats is in the log exactly once! - [[ $output -eq 2 ]] - grep setup_file.bats "$LOG" - grep setup_file2.bats "$LOG" + # shellcheck disable=SC2031,SC2030 + export LOG="$BATS_TEST_TMPDIR/setup_file_multi_file_suite.log" + reentrant_run bats "$FIXTURE_ROOT/setup_file.bats" "$FIXTURE_ROOT/no_setup_file.bats" "$FIXTURE_ROOT/setup_file2.bats" + [[ $status -eq 0 ]] + run wc -l <"$LOG" + # each setup_file[2].bats is in the log exactly once! + [[ $output -eq 2 ]] + grep setup_file.bats "$LOG" + grep setup_file2.bats "$LOG" } @test "teardown_file is called correctly in multi file suite" { @@ -44,7 +44,7 @@ setup_file() { export LOG="$BATS_TEST_TMPDIR/teardown_file_multi_file_suite.log" reentrant_run bats "$FIXTURE_ROOT/teardown_file.bats" "$FIXTURE_ROOT/no_teardown_file.bats" "$FIXTURE_ROOT/teardown_file2.bats" [[ $status -eq 0 ]] - run wc -l < "$LOG" + run wc -l <"$LOG" # each teardown_file[2].bats is in the log exactly once! [[ $output -eq 2 ]] grep teardown_file.bats "$LOG" @@ -61,7 +61,7 @@ setup_file() { [[ "${lines[2]}" == "# (from function \`setup_file' in test file $RELATIVE_FIXTURE_ROOT/setup_file_failed.bats, line 2)" ]] [[ "${lines[3]}" == "# \`false' failed" ]] [[ "${lines[4]}" == "# bats warning: Executed 1 instead of expected 2 tests" ]] # this warning is expected - # to appease the count validator, we would have to reduce the expected number of tests (retroactively?) or + # to appease the count validator, we would have to reduce the expected number of tests (retroactively?) or # output even those tests that should be skipped due to a failed setup_file. # Since we are already in a failure mode, the additional error does not hurt and is less verbose than # printing all the failed/skipped tests due to the setup failure. @@ -74,7 +74,7 @@ setup_file() { [[ "${lines[0]}" == "1..1" ]] [[ "${lines[1]}" == "ok 1 test" ]] [[ "${lines[2]}" == "not ok 2 teardown_file failed" ]] - [[ "${lines[3]}" == "# (from function \`teardown_file' in test file $RELATIVE_FIXTURE_ROOT/teardown_file_failed.bats, line 3)" ]] + [[ "${lines[3]}" == "# (from function \`teardown_file' in test file $RELATIVE_FIXTURE_ROOT/teardown_file_failed.bats, line 2)" ]] [[ "${lines[4]}" == "# \`false' failed" ]] [[ "${lines[5]}" == "# bats warning: Executed 2 instead of expected 1 tests" ]] # for now this warning is expected # for a failed teardown_file not to change the number of tests being reported, we would have to alter at least one previous test result report @@ -105,7 +105,7 @@ not ok 1 failing test set -m SECONDS=0 # run testsubprocess in background to not avoid blocking this test - bats "$FIXTURE_ROOT/teardown_file_after_long_test.bats"& + bats "$FIXTURE_ROOT/teardown_file_after_long_test.bats" & SUBPROCESS_PID=$! # wait until we enter the test sleep 2 @@ -123,7 +123,7 @@ not ok 1 failing test @test "setup_file runs even if all tests in the file are skipped" { # shellcheck disable=SC2031,SC2030 - export LOG="$BATS_TEST_TMPDIR/setup_file_skipped.log" + export LOG="$BATS_TEST_TMPDIR/setup_file_skipped.log" reentrant_run bats "$FIXTURE_ROOT/setup_file_even_if_all_tests_are_skipped.bats" [[ -f "$LOG" ]] grep setup_file_even_if_all_tests_are_skipped.bats "$LOG" @@ -131,7 +131,7 @@ not ok 1 failing test @test "teardown_file runs even if all tests in the file are skipped" { # shellcheck disable=SC2031,SC2030 - export LOG="$BATS_TEST_TMPDIR/teardown_file_skipped.log" + export LOG="$BATS_TEST_TMPDIR/teardown_file_skipped.log" reentrant_run bats "$FIXTURE_ROOT/teardown_file_even_if_all_tests_are_skipped.bats" [[ $status -eq 0 ]] [[ -f "$LOG" ]] @@ -171,7 +171,7 @@ ok 2 must not see variable from first run" ]] [ "${lines[0]}" == "1..1" ] [ "${lines[1]}" == "ok 1 empty" ] [ "${#lines[@]}" -eq 2 ] - + } @test "variables exported in setup_file are visible in tests" { @@ -184,7 +184,7 @@ ok 2 must not see variable from first run" ]] # only select the test from no_setup_file reentrant_run bats -f test "$FIXTURE_ROOT/setup_file.bats" "$FIXTURE_ROOT/no_setup_file.bats" - [ ! -f "$LOG" ] # setup_file must not have been executed! + [ ! -f "$LOG" ] # setup_file must not have been executed! [ "${lines[0]}" == '1..1' ] # but at least one test should have been run } diff --git a/test/fixtures/bats/BATS_variables_dont_contain_double_slashes.bats b/test/fixtures/bats/BATS_variables_dont_contain_double_slashes.bats index 1673a73a80..2994bbe84f 100644 --- a/test/fixtures/bats/BATS_variables_dont_contain_double_slashes.bats +++ b/test/fixtures/bats/BATS_variables_dont_contain_double_slashes.bats @@ -2,8 +2,8 @@ for var_name in ${!BATS_@}; do local var_value="${!var_name}" if [[ "$var_value" == *'//'* ]]; then - + echo "$var_name contains // ${#var_value}: ${var_value}" && false fi done -} \ No newline at end of file +} diff --git a/test/fixtures/bats/comment_style.bats b/test/fixtures/bats/comment_style.bats index 5363bd9601..5696948e67 100644 --- a/test/fixtures/bats/comment_style.bats +++ b/test/fixtures/bats/comment_style.bats @@ -2,7 +2,7 @@ function should_be_found { # @test true } -function should_be_found_with_trailing_whitespace { # @test +function should_be_found_with_trailing_whitespace { # @test true } @@ -10,7 +10,7 @@ should_be_found_with_parens() { #@test true } -should_be_found_with_parens_and_whitespace () { #@test +should_be_found_with_parens_and_whitespace() { #@test true } @@ -18,15 +18,15 @@ function should_be_found_with_function_and_parens() { #@test true } -function should_be_found_with_function_parens_and_whitespace () { #@test +function should_be_found_with_function_parens_and_whitespace() { #@test true } -should_not_be_found() { - false - #@test -} +should_not_be_found() { + false + #@test +} -should_not_be_found() { - false -} #@test +should_not_be_found() { + false +} #@test diff --git a/test/fixtures/bats/dos_line_no_shellcheck.bats b/test/fixtures/bats/dos_line_no_shellcheck.bats index b5f65c67b0..d04c17f17b 100644 --- a/test/fixtures/bats/dos_line_no_shellcheck.bats +++ b/test/fixtures/bats/dos_line_no_shellcheck.bats @@ -1,3 +1,3 @@ -@test "foo" { - echo "foo" -} +@test "foo" { + echo "foo" +} diff --git a/test/fixtures/bats/empty.bats b/test/fixtures/bats/empty.bats index e69de29bb2..8b13789179 100644 --- a/test/fixtures/bats/empty.bats +++ b/test/fixtures/bats/empty.bats @@ -0,0 +1 @@ + diff --git a/test/fixtures/bats/evaluation_count/file1.bats b/test/fixtures/bats/evaluation_count/file1.bats index eb7d85b8ed..c2ea77f37e 100644 --- a/test/fixtures/bats/evaluation_count/file1.bats +++ b/test/fixtures/bats/evaluation_count/file1.bats @@ -1,5 +1,5 @@ -echo "file1" >> "$TEMPFILE" +echo "file1" >>"$TEMPFILE" @test "test1" { - : -} \ No newline at end of file + : +} diff --git a/test/fixtures/bats/evaluation_count/file2.bats b/test/fixtures/bats/evaluation_count/file2.bats index fee360f76c..49ff64af68 100644 --- a/test/fixtures/bats/evaluation_count/file2.bats +++ b/test/fixtures/bats/evaluation_count/file2.bats @@ -1,9 +1,9 @@ -echo "file2" >> "$TEMPFILE" +echo "file2" >>"$TEMPFILE" @test "test 1" { - : + : } @test "test 2" { - : + : } diff --git a/test/fixtures/bats/external_function_calls.bats b/test/fixtures/bats/external_function_calls.bats index 5b009ebf2e..6a9a5fadf0 100644 --- a/test/fixtures/bats/external_function_calls.bats +++ b/test/fixtures/bats/external_function_calls.bats @@ -5,61 +5,61 @@ load test_helper # All tests fail on the same line so checking can be automated @test "Call true function && false stackdepth=1" { - help_me - help_me && false + help_me + help_me && false } @test "Call true function && return 1 stackdepth=1" { - help_me - help_me && return 1 + help_me + help_me && return 1 } @test "Call true function and invert stackdepth=2" { - help_me - ! help_me + help_me + ! help_me } @test "Call false function || false stackdepth=1" { - ! failing_helper - failing_helper || false + ! failing_helper + failing_helper || false } @test "Call false function && return 1 stackdepth=1" { - ! failing_helper - failing_helper || return 1 + ! failing_helper + failing_helper || return 1 } @test "Call false function stackdepth=2" { - ! failing_helper - failing_helper + ! failing_helper + failing_helper } @test "Call return_0 function && false stackdepth=1" { - return_0 - return_0 && false + return_0 + return_0 && false } @test "Call return_0 function && return 1 stackdepth=1" { - return_0 - return_0 && return 1 + return_0 + return_0 && return 1 } @test "Call return_0 function and invert stackdepth=2" { - return_0 - ! return_0 + return_0 + ! return_0 } @test "Call return_1 function || false stackdepth=1" { - ! return_1 - return_1 || false + ! return_1 + return_1 || false } @test "Call return_1 function && return 1 stackdepth=1" { - ! return_1 - return_1 || return 1 + ! return_1 + return_1 || return 1 } @test "Call return_1 function stackdepth=2" { - ! return_1 - return_1 + ! return_1 + return_1 } diff --git a/test/fixtures/bats/external_functions.bash b/test/fixtures/bats/external_functions.bash index 12057c2b75..4ed5d5980b 100644 --- a/test/fixtures/bats/external_functions.bash +++ b/test/fixtures/bats/external_functions.bash @@ -1,15 +1,15 @@ setup() { - true + true } teardown() { - true + true } setup_file() { - true + true } teardown_file() { - true -} \ No newline at end of file + true +} diff --git a/test/fixtures/bats/external_functions.bats b/test/fixtures/bats/external_functions.bats index 5709a84b0d..946fca248f 100644 --- a/test/fixtures/bats/external_functions.bats +++ b/test/fixtures/bats/external_functions.bats @@ -1,5 +1,5 @@ load external_functions @test test { - true -} \ No newline at end of file + true +} diff --git a/test/fixtures/bats/failing_with_bash_expression.bats b/test/fixtures/bats/failing_with_bash_expression.bats index 71e8ee363d..4574da54c8 100644 --- a/test/fixtures/bats/failing_with_bash_expression.bats +++ b/test/fixtures/bats/failing_with_bash_expression.bats @@ -1,4 +1,4 @@ @test "a failing test" { true - (( 1 == 2 )) + ((1 == 2)) } diff --git a/test/fixtures/bats/failure_in_free_code.bats b/test/fixtures/bats/failure_in_free_code.bats index 42afad1553..63ef844a38 100644 --- a/test/fixtures/bats/failure_in_free_code.bats +++ b/test/fixtures/bats/failure_in_free_code.bats @@ -1,5 +1,3 @@ - - helper() { false } @@ -8,4 +6,4 @@ helper @test "everything is ok" { true -} \ No newline at end of file +} diff --git a/test/fixtures/bats/hang_after_run.bats b/test/fixtures/bats/hang_after_run.bats index 702e5fd387..3cfae39f12 100644 --- a/test/fixtures/bats/hang_after_run.bats +++ b/test/fixtures/bats/hang_after_run.bats @@ -1,9 +1,9 @@ setup() { - load '../../concurrent-coordination' + load '../../concurrent-coordination' } @test "test" { - single-use-latch::signal hang_after_run - run true - sleep 10 -} \ No newline at end of file + single-use-latch::signal hang_after_run + run true + sleep 10 +} diff --git a/test/fixtures/bats/hang_in_run.bats b/test/fixtures/bats/hang_in_run.bats index ded0789b87..b08c2a8ae4 100644 --- a/test/fixtures/bats/hang_in_run.bats +++ b/test/fixtures/bats/hang_in_run.bats @@ -1,8 +1,8 @@ setup() { - load '../../concurrent-coordination' + load '../../concurrent-coordination' } @test "test" { - single-use-latch::signal hang_in_run - run sleep 10 -} \ No newline at end of file + single-use-latch::signal hang_in_run + run sleep 10 +} diff --git a/test/fixtures/bats/hang_in_setup_file.bats b/test/fixtures/bats/hang_in_setup_file.bats index d372815329..b21ef7b890 100644 --- a/test/fixtures/bats/hang_in_setup_file.bats +++ b/test/fixtures/bats/hang_in_setup_file.bats @@ -1,9 +1,9 @@ setup_file() { - load '../../concurrent-coordination' - single-use-latch::signal hang_in_setup_file - sleep 10 + load '../../concurrent-coordination' + single-use-latch::signal hang_in_setup_file + sleep 10 } @test "empty" { - : -} \ No newline at end of file + : +} diff --git a/test/fixtures/bats/hang_in_teardown.bats b/test/fixtures/bats/hang_in_teardown.bats index 314838b02c..229920da6f 100644 --- a/test/fixtures/bats/hang_in_teardown.bats +++ b/test/fixtures/bats/hang_in_teardown.bats @@ -1,9 +1,9 @@ teardown() { - load '../../concurrent-coordination' - single-use-latch::signal hang_in_teardown - sleep 10 + load '../../concurrent-coordination' + single-use-latch::signal hang_in_teardown + sleep 10 } @test "empty" { - : -} \ No newline at end of file + : +} diff --git a/test/fixtures/bats/hang_in_teardown_file.bats b/test/fixtures/bats/hang_in_teardown_file.bats index 640d8ce8ae..40143ed42d 100644 --- a/test/fixtures/bats/hang_in_teardown_file.bats +++ b/test/fixtures/bats/hang_in_teardown_file.bats @@ -1,9 +1,9 @@ teardown_file() { - load '../../concurrent-coordination' - single-use-latch::signal hang_in_teardown_file - sleep 10 + load '../../concurrent-coordination' + single-use-latch::signal hang_in_teardown_file + sleep 10 } @test "empty" { - : -} \ No newline at end of file + : +} diff --git a/test/fixtures/bats/hang_in_test.bats b/test/fixtures/bats/hang_in_test.bats index 52479b1727..40fdf8838b 100644 --- a/test/fixtures/bats/hang_in_test.bats +++ b/test/fixtures/bats/hang_in_test.bats @@ -1,8 +1,8 @@ setup() { - load '../../concurrent-coordination' + load '../../concurrent-coordination' } @test "test" { - single-use-latch::signal hang_in_test - sleep 10 -} \ No newline at end of file + single-use-latch::signal hang_in_test + sleep 10 +} diff --git a/test/fixtures/bats/issue-205.bats b/test/fixtures/bats/issue-205.bats index 4c8a7ec44b..ddc826a34b 100644 --- a/test/fixtures/bats/issue-205.bats +++ b/test/fixtures/bats/issue-205.bats @@ -1,103 +1,103 @@ #!/usr/bin/env bats function bgfunc { - get_open_fds - echo "${FUNCNAME[1]} fds before: (${open_fds[*]})" >>"${LOG_FILE}" - close_non_std_fds - get_open_fds - echo "${FUNCNAME[1]} fds after: (${open_fds[*]})" >>"${LOG_FILE}" - sleep 10 - echo "bgfunc done" - return 0 + get_open_fds + echo "${FUNCNAME[1]} fds before: (${open_fds[*]})" >>"${LOG_FILE}" + close_non_std_fds + get_open_fds + echo "${FUNCNAME[1]} fds after: (${open_fds[*]})" >>"${LOG_FILE}" + sleep 10 + echo "bgfunc done" + return 0 } # store the list of open FDs in array open_fds function get_open_fds() { - open_fds=() # reset output array in case it was already set - if [[ ${BASH_VERSINFO[0]} == 3 ]]; then - local BASHPID - BASHPID=$(bash -c 'echo $PPID') - fi - local tmpfile - tmpfile=$(mktemp "$BATS_SUITE_TMPDIR/fds-XXXXXX") - # Avoid opening a new fd to read fds: Don't use <(), glob expansion. - # Instead, redirect stdout to file which does not create an extra FD. - if [[ -d /proc/$BASHPID/fd ]]; then # Linux - ls -1 "/proc/$BASHPID/fd" > "$tmpfile" - IFS=$'\n' read -d '' -ra open_fds <"$tmpfile" || true - elif command -v lsof >/dev/null ; then # MacOS - local -a fds - lsof -F f -p "$BASHPID" >"$tmpfile" - IFS=$'\n' read -d '' -ra fds < "$tmpfile" || true - for fd in "${fds[@]}"; do - case $fd in - f[0-9]*) # filter non fd entries (mainly pid?) - open_fds+=("${fd#f}") # cut off f prefix - ;; - esac - done - elif command -v procstat >/dev/null ; then # BSDs - local -a columns header - procstat fds "$BASHPID" > "$tmpfile" - { - read -r -a header - local fd_column_index=-1 - for ((i=0; i<${#header[@]}; ++i)); do - if [[ ${header[$i]} == *FD* ]]; then - fd_column_index=$i - break - fi - done - if [[ $fd_column_index -eq -1 ]]; then - printf "Could not find FD column in procstat" >&2 - exit 1 - fi - while read -r -a columns; do - local fd=${columns[$fd_column_index]} - if [[ $fd == [0-9]* ]]; then # only take up numeric entries - open_fds+=("$fd") - fi - done - } < "$tmpfile" - else - # TODO: MSYS (Windows) - printf "Neither FD discovery mechanism available\n" >&2 + open_fds=() # reset output array in case it was already set + if [[ ${BASH_VERSINFO[0]} == 3 ]]; then + local BASHPID + BASHPID=$(bash -c 'echo $PPID') + fi + local tmpfile + tmpfile=$(mktemp "$BATS_SUITE_TMPDIR/fds-XXXXXX") + # Avoid opening a new fd to read fds: Don't use <(), glob expansion. + # Instead, redirect stdout to file which does not create an extra FD. + if [[ -d /proc/$BASHPID/fd ]]; then # Linux + ls -1 "/proc/$BASHPID/fd" >"$tmpfile" + IFS=$'\n' read -d '' -ra open_fds <"$tmpfile" || true + elif command -v lsof >/dev/null; then # MacOS + local -a fds + lsof -F f -p "$BASHPID" >"$tmpfile" + IFS=$'\n' read -d '' -ra fds <"$tmpfile" || true + for fd in "${fds[@]}"; do + case $fd in + f[0-9]*) # filter non fd entries (mainly pid?) + open_fds+=("${fd#f}") # cut off f prefix + ;; + esac + done + elif command -v procstat >/dev/null; then # BSDs + local -a columns header + procstat fds "$BASHPID" >"$tmpfile" + { + read -r -a header + local fd_column_index=-1 + for ((i = 0; i < ${#header[@]}; ++i)); do + if [[ ${header[$i]} == *FD* ]]; then + fd_column_index=$i + break + fi + done + if [[ $fd_column_index -eq -1 ]]; then + printf "Could not find FD column in procstat" >&2 exit 1 - fi + fi + while read -r -a columns; do + local fd=${columns[$fd_column_index]} + if [[ $fd == [0-9]* ]]; then # only take up numeric entries + open_fds+=("$fd") + fi + done + } <"$tmpfile" + else + # TODO: MSYS (Windows) + printf "Neither FD discovery mechanism available\n" >&2 + exit 1 + fi } function close_non_std_fds() { - local open_fds non_std_fds=() - get_open_fds - for fd in "${open_fds[@]}"; do - if [[ $fd -gt 2 ]]; then - non_std_fds+=("$fd") - fi - done - close_fds "${non_std_fds[@]}" + local open_fds non_std_fds=() + get_open_fds + for fd in "${open_fds[@]}"; do + if [[ $fd -gt 2 ]]; then + non_std_fds+=("$fd") + fi + done + close_fds "${non_std_fds[@]}" } function close_fds() { # - for fd in "$@"; do - eval "exec $fd>&-" - done + for fd in "$@"; do + eval "exec $fd>&-" + done } function otherfunc { - bgfunc & - PID=$! - disown - return 0 + bgfunc & + PID=$! + disown + return 0 } -setup_file (){ # see issue #530 - bgfunc & +setup_file() { # see issue #530 + bgfunc & } @test "min bg" { - echo "sec: $SECONDS" - otherfunc - sleep 1 # leave some space for the background job to print/fail early - kill -s 0 -- $PID # fail it the process already finished due to error! - echo "sec: $SECONDS" + echo "sec: $SECONDS" + otherfunc + sleep 1 # leave some space for the background job to print/fail early + kill -s 0 -- $PID # fail it the process already finished due to error! + echo "sec: $SECONDS" } diff --git a/test/fixtures/bats/issue-433/repro1.bats b/test/fixtures/bats/issue-433/repro1.bats index fc488e746c..d37d4b607e 100644 --- a/test/fixtures/bats/issue-433/repro1.bats +++ b/test/fixtures/bats/issue-433/repro1.bats @@ -1,8 +1,7 @@ @test "1" { - sleep 1 + sleep 1 } @test "2" { - sleep 1 + sleep 1 } - diff --git a/test/fixtures/bats/issue-433/repro2.bats b/test/fixtures/bats/issue-433/repro2.bats index 2863d959b9..92d37971fe 100644 --- a/test/fixtures/bats/issue-433/repro2.bats +++ b/test/fixtures/bats/issue-433/repro2.bats @@ -1,8 +1,7 @@ @test "11" { - sleep 1 + sleep 1 } @test "12" { - sleep 1 + sleep 1 } - diff --git a/test/fixtures/bats/issue-519.bats b/test/fixtures/bats/issue-519.bats index a28f38c4e1..307bbb5857 100644 --- a/test/fixtures/bats/issue-519.bats +++ b/test/fixtures/bats/issue-519.bats @@ -1,3 +1,3 @@ @test "no unprefixed variables" { - declare -p >"${BATS_DECLARED_VARIABLES_FILE?}" -} \ No newline at end of file + declare -p >"${BATS_DECLARED_VARIABLES_FILE?}" +} diff --git a/test/fixtures/bats/loop_keep_IFS.bats b/test/fixtures/bats/loop_keep_IFS.bats index 4af343dc30..a08c39c05f 100644 --- a/test/fixtures/bats/loop_keep_IFS.bats +++ b/test/fixtures/bats/loop_keep_IFS.bats @@ -3,7 +3,7 @@ loop_func() { local search="none one two tree" local d - for d in $search ; do + for d in $search; do echo "$d" done } diff --git a/test/fixtures/bats/no-final-newline.bats b/test/fixtures/bats/no-final-newline.bats index 09014f0eee..a7061a1dac 100644 --- a/test/fixtures/bats/no-final-newline.bats +++ b/test/fixtures/bats/no-final-newline.bats @@ -6,4 +6,4 @@ @test "test function returns nonzero" { printf 'foo\nbar' return 1 -} \ No newline at end of file +} diff --git a/test/fixtures/bats/print_output_on_failure.bats b/test/fixtures/bats/print_output_on_failure.bats index 793b972369..e7f9168fad 100644 --- a/test/fixtures/bats/print_output_on_failure.bats +++ b/test/fixtures/bats/print_output_on_failure.bats @@ -1,11 +1,11 @@ @test "no failure prints no output" { - run echo success + run echo success } bats_require_minimum_version 1.5.0 # don't be fooled by order, this will run before the test above! @test "failure prints output" { - run -1 echo "fail hard" + run -1 echo "fail hard" } @test "empty output on failure" { - false -} \ No newline at end of file + false +} diff --git a/test/fixtures/bats/print_output_on_failure_with_stderr.bats b/test/fixtures/bats/print_output_on_failure_with_stderr.bats index d411c5172a..4ad5e412dc 100644 --- a/test/fixtures/bats/print_output_on_failure_with_stderr.bats +++ b/test/fixtures/bats/print_output_on_failure_with_stderr.bats @@ -1,12 +1,12 @@ @test "no failure prints no output" { - run echo success + run echo success } @test "failure prints output" { - bats_require_minimum_version 1.5.0 - run -1 --separate-stderr bash -c 'echo "fail hard"; echo with stderr >&2' + bats_require_minimum_version 1.5.0 + run -1 --separate-stderr bash -c 'echo "fail hard"; echo with stderr >&2' } @test "empty output on failure" { - false -} \ No newline at end of file + false +} diff --git a/test/fixtures/bats/read_from_stdin.bats b/test/fixtures/bats/read_from_stdin.bats index 0ff76e7035..7bb41b63d1 100644 --- a/test/fixtures/bats/read_from_stdin.bats +++ b/test/fixtures/bats/read_from_stdin.bats @@ -1,21 +1,21 @@ #!/usr/bin/env bats @test "test 1" { - # Don't print anything - run bash -c "$BATS_TEST_DIRNAME/cmd_using_stdin.bash" - [ "$status" -eq 1 ] - [ "$output" = "Not found" ] + # Don't print anything + run bash -c "$BATS_TEST_DIRNAME/cmd_using_stdin.bash" + [ "$status" -eq 1 ] + [ "$output" = "Not found" ] } @test "test 2 with TAB in name" { - run bash -c "echo EXIT | $BATS_TEST_DIRNAME/cmd_using_stdin.bash" - [ "$status" -eq 0 ] - echo "$output" - [ "$output" = "Found" ] + run bash -c "echo EXIT | $BATS_TEST_DIRNAME/cmd_using_stdin.bash" + [ "$status" -eq 0 ] + echo "$output" + [ "$output" = "Found" ] } @test "test 3" { - run bash -c "echo EXIT | $BATS_TEST_DIRNAME/cmd_using_stdin.bash" - [ "$status" -eq 0 ] - [ "$output" = "Found" ] + run bash -c "echo EXIT | $BATS_TEST_DIRNAME/cmd_using_stdin.bash" + [ "$status" -eq 0 ] + [ "$output" = "Found" ] } diff --git a/test/fixtures/bats/retry.bats b/test/fixtures/bats/retry.bats index fe8d47d44b..085672841d 100644 --- a/test/fixtures/bats/retry.bats +++ b/test/fixtures/bats/retry.bats @@ -1,38 +1,38 @@ BATS_TEST_RETRIES=2 # means three tries per test log_caller() { - printf "%s %s %s\n" "${BATS_TEST_NAME:-}" "${FUNCNAME[1]}" "${BATS_TEST_TRY_NUMBER:-}" >> "${LOG?}" + printf "%s %s %s\n" "${BATS_TEST_NAME:-}" "${FUNCNAME[1]}" "${BATS_TEST_TRY_NUMBER:-}" >>"${LOG?}" } setup_file() { - log_caller + log_caller } teardown_file() { - log_caller + log_caller } setup() { - log_caller + log_caller } teardown() { - log_caller + log_caller } @test "Fail all" { - log_caller - false + log_caller + false } @test "Fail once" { - log_caller - (( BATS_TEST_TRY_NUMBER > 1 )) || false + log_caller + ((BATS_TEST_TRY_NUMBER > 1)) || false } @test "Override retries" { - log_caller - # shellcheck disable=SC2034 - BATS_TEST_RETRIES=1 - (( BATS_TEST_TRY_NUMBER > 2 )) || false -} \ No newline at end of file + log_caller + # shellcheck disable=SC2034 + BATS_TEST_RETRIES=1 + ((BATS_TEST_TRY_NUMBER > 2)) || false +} diff --git a/test/fixtures/bats/run_long_command.bats b/test/fixtures/bats/run_long_command.bats index c725f43b66..f49a8dee26 100644 --- a/test/fixtures/bats/run_long_command.bats +++ b/test/fixtures/bats/run_long_command.bats @@ -1,3 +1,3 @@ @test "run long command" { - run sleep 3 -} \ No newline at end of file + run sleep 3 +} diff --git a/test/fixtures/bats/set_-eu_in_setup_and_teardown.bats b/test/fixtures/bats/set_-eu_in_setup_and_teardown.bats index e9879f0ab5..49a25c9a5f 100644 --- a/test/fixtures/bats/set_-eu_in_setup_and_teardown.bats +++ b/test/fixtures/bats/set_-eu_in_setup_and_teardown.bats @@ -1,23 +1,23 @@ setup() { - set -eu + set -eu } teardown() { - set -eu + set -eu } @test "skipped test" { - skip + skip } @test "skipped test with reason" { - skip "reason" + skip "reason" } @test "passing test" { - run true + run true } @test "failing test" { - false -} \ No newline at end of file + false +} diff --git a/test/fixtures/bats/setup.bats b/test/fixtures/bats/setup.bats index 0fc9eea6ec..ee88b162fa 100644 --- a/test/fixtures/bats/setup.bats +++ b/test/fixtures/bats/setup.bats @@ -1,7 +1,7 @@ LOG="$BATS_TEST_SUITE_TMPDIR/setup.log" setup() { - echo "$BATS_TEST_NAME" >> "$LOG" + echo "$BATS_TEST_NAME" >>"$LOG" } @test "one" { diff --git a/test/fixtures/bats/show-output-of-passing-tests.bats b/test/fixtures/bats/show-output-of-passing-tests.bats index 421da017ca..acd8b2fe44 100644 --- a/test/fixtures/bats/show-output-of-passing-tests.bats +++ b/test/fixtures/bats/show-output-of-passing-tests.bats @@ -1,3 +1,3 @@ @test "test" { - echo output -} \ No newline at end of file + echo output +} diff --git a/test/fixtures/bats/sigint_in_failing_test.bats b/test/fixtures/bats/sigint_in_failing_test.bats index b6f0be4589..0755cc96ab 100644 --- a/test/fixtures/bats/sigint_in_failing_test.bats +++ b/test/fixtures/bats/sigint_in_failing_test.bats @@ -1,11 +1,11 @@ @test "failing" { - if [[ -z "${DONT_ABORT:-}" ]]; then - # emulate CTRL-C by sending SIGINT to the whole process group - kill -SIGINT -- -"$BATS_ROOT_PID" - fi - false + if [[ -z "${DONT_ABORT:-}" ]]; then + # emulate CTRL-C by sending SIGINT to the whole process group + kill -SIGINT -- -"$BATS_ROOT_PID" + fi + false } @test "passing" { - : -} \ No newline at end of file + : +} diff --git a/test/fixtures/bats/single_line_no_shellcheck.bats b/test/fixtures/bats/single_line_no_shellcheck.bats index fc342d9666..ea8df787dd 100644 --- a/test/fixtures/bats/single_line_no_shellcheck.bats +++ b/test/fixtures/bats/single_line_no_shellcheck.bats @@ -1,8 +1,8 @@ -@test "empty" { } +@test "empty" {; } @test "passing" { true; } -@test "input redirection" { diff - <( echo hello ); } <> "$LOG" + echo "$BATS_TEST_NAME" >>"$LOG" } @test "one" { diff --git a/test/fixtures/bats/teardown_file_override_status.bats b/test/fixtures/bats/teardown_file_override_status.bats index 61b6de6b0e..9717d94c79 100644 --- a/test/fixtures/bats/teardown_file_override_status.bats +++ b/test/fixtures/bats/teardown_file_override_status.bats @@ -1,9 +1,9 @@ teardown_file() { - # shellcheck disable=SC2034 - status=${STATUS?} - return "${TEARDOWN_RETURN_CODE?}" + # shellcheck disable=SC2034 + status=${STATUS?} + return "${TEARDOWN_RETURN_CODE?}" } @test "return expected code" { - return "${TEST_RETURN_CODE?}" -} \ No newline at end of file + return "${TEST_RETURN_CODE?}" +} diff --git a/test/fixtures/bats/teardown_override_status.bats b/test/fixtures/bats/teardown_override_status.bats index b45996cc05..69fb4200a7 100644 --- a/test/fixtures/bats/teardown_override_status.bats +++ b/test/fixtures/bats/teardown_override_status.bats @@ -1,8 +1,8 @@ teardown() { - status=${STATUS?} - return "${TEARDOWN_RETURN_CODE?}" + status=${STATUS?} + return "${TEARDOWN_RETURN_CODE?}" } @test "return expected code" { - return "${TEST_RETURN_CODE?}" -} \ No newline at end of file + return "${TEST_RETURN_CODE?}" +} diff --git a/test/fixtures/bats/teardown_suite_override_status/setup_suite.bash b/test/fixtures/bats/teardown_suite_override_status/setup_suite.bash index 0eb3b0cd9a..79a1c76231 100644 --- a/test/fixtures/bats/teardown_suite_override_status/setup_suite.bash +++ b/test/fixtures/bats/teardown_suite_override_status/setup_suite.bash @@ -1,9 +1,9 @@ setup_suite() { - : + : } teardown_suite() { - # shellcheck disable=SC2034 - status=${STATUS?} - return "${TEARDOWN_RETURN_CODE?}" -} \ No newline at end of file + # shellcheck disable=SC2034 + status=${STATUS?} + return "${TEARDOWN_RETURN_CODE?}" +} diff --git a/test/fixtures/bats/teardown_suite_override_status/test.bats b/test/fixtures/bats/teardown_suite_override_status/test.bats index 7c1c779209..4cde17a383 100644 --- a/test/fixtures/bats/teardown_suite_override_status/test.bats +++ b/test/fixtures/bats/teardown_suite_override_status/test.bats @@ -1,3 +1,3 @@ @test test { - return "${TEST_RETURN_CODE?}" -} \ No newline at end of file + return "${TEST_RETURN_CODE?}" +} diff --git a/test/fixtures/bats/unbound_variable.bats b/test/fixtures/bats/unbound_variable.bats index 4b8c2d956c..a8219fa14c 100644 --- a/test/fixtures/bats/unbound_variable.bats +++ b/test/fixtures/bats/unbound_variable.bats @@ -1,16 +1,16 @@ - set -u +set -u # This file is used to test line number offsets. Any changes to lines will affect tests @test "access unbound variable" { - unset unset_variable - # Add a line for checking line number - # shellcheck disable=SC2154 - foo=$unset_variable + unset unset_variable + # Add a line for checking line number + # shellcheck disable=SC2154 + foo=$unset_variable } @test "access second unbound variable" { - unset second_unset_variable - # shellcheck disable=SC2034,SC2154 - foo=$second_unset_variable + unset second_unset_variable + # shellcheck disable=SC2034,SC2154 + foo=$second_unset_variable } diff --git a/test/fixtures/bats/verbose-run.bats b/test/fixtures/bats/verbose-run.bats index de2942b507..1fb2d00fcb 100644 --- a/test/fixtures/bats/verbose-run.bats +++ b/test/fixtures/bats/verbose-run.bats @@ -1,4 +1,4 @@ @test "test" { - bats_require_minimum_version 1.5.0 - run ! echo test -} \ No newline at end of file + bats_require_minimum_version 1.5.0 + run ! echo test +} diff --git a/test/fixtures/bats/without_trailing_newline.bats b/test/fixtures/bats/without_trailing_newline.bats index e3ace8b578..fbc1f3833a 100644 --- a/test/fixtures/bats/without_trailing_newline.bats +++ b/test/fixtures/bats/without_trailing_newline.bats @@ -1,3 +1,3 @@ @test "truth" { true -} \ No newline at end of file +} diff --git a/test/fixtures/file_setup_teardown/error_in_setup_and_teardown_file.bats b/test/fixtures/file_setup_teardown/error_in_setup_and_teardown_file.bats index 24390137ad..c0a2582093 100644 --- a/test/fixtures/file_setup_teardown/error_in_setup_and_teardown_file.bats +++ b/test/fixtures/file_setup_teardown/error_in_setup_and_teardown_file.bats @@ -1,11 +1,11 @@ setup_file() { - false + false } teardown_file() { - false + false } @test dummy { - : -} \ No newline at end of file + : +} diff --git a/test/fixtures/file_setup_teardown/no_setup_file.bats b/test/fixtures/file_setup_teardown/no_setup_file.bats index f66092a863..5e6619ea0e 100644 --- a/test/fixtures/file_setup_teardown/no_setup_file.bats +++ b/test/fixtures/file_setup_teardown/no_setup_file.bats @@ -1,3 +1,3 @@ @test "test" { - true -} \ No newline at end of file + true +} diff --git a/test/fixtures/file_setup_teardown/no_teardown_file.bats b/test/fixtures/file_setup_teardown/no_teardown_file.bats index 55379e4a1a..e9e48c36f7 100644 --- a/test/fixtures/file_setup_teardown/no_teardown_file.bats +++ b/test/fixtures/file_setup_teardown/no_teardown_file.bats @@ -1,3 +1,3 @@ @test "first" { - true -} \ No newline at end of file + true +} diff --git a/test/fixtures/file_setup_teardown/setup_file.bats b/test/fixtures/file_setup_teardown/setup_file.bats index 3a84ca897a..116f7e0146 100644 --- a/test/fixtures/file_setup_teardown/setup_file.bats +++ b/test/fixtures/file_setup_teardown/setup_file.bats @@ -1,11 +1,11 @@ setup_file() { - echo "$BATS_TEST_FILENAME" >> "$LOG" + echo "$BATS_TEST_FILENAME" >>"$LOG" } @test "Test 1" { - true + true } @test "Test 2" { - true -} \ No newline at end of file + true +} diff --git a/test/fixtures/file_setup_teardown/setup_file2.bats b/test/fixtures/file_setup_teardown/setup_file2.bats index bd9fd59244..0ea1de67bf 100644 --- a/test/fixtures/file_setup_teardown/setup_file2.bats +++ b/test/fixtures/file_setup_teardown/setup_file2.bats @@ -1,7 +1,7 @@ setup_file() { - echo "$BATS_TEST_FILENAME" >> "$LOG" + echo "$BATS_TEST_FILENAME" >>"$LOG" } @test "test" { - true -} \ No newline at end of file + true +} diff --git a/test/fixtures/file_setup_teardown/setup_file_does_not_leak_env.bats b/test/fixtures/file_setup_teardown/setup_file_does_not_leak_env.bats index 0db3d9cfa0..44ae813601 100644 --- a/test/fixtures/file_setup_teardown/setup_file_does_not_leak_env.bats +++ b/test/fixtures/file_setup_teardown/setup_file_does_not_leak_env.bats @@ -1,7 +1,7 @@ setup_file() { - export SETUP_FILE_VAR="$BATS_TEST_FILENAME" + export SETUP_FILE_VAR="$BATS_TEST_FILENAME" } @test "test" { - true -} \ No newline at end of file + true +} diff --git a/test/fixtures/file_setup_teardown/setup_file_does_not_leak_env2.bats b/test/fixtures/file_setup_teardown/setup_file_does_not_leak_env2.bats index cb71b3adbd..fc10d6e204 100644 --- a/test/fixtures/file_setup_teardown/setup_file_does_not_leak_env2.bats +++ b/test/fixtures/file_setup_teardown/setup_file_does_not_leak_env2.bats @@ -1,3 +1,3 @@ @test "test" { - [[ "${SETUP_FILE_VAR-"NOT_SET"}" == "NOT_SET" ]] -} \ No newline at end of file + [[ "${SETUP_FILE_VAR-"NOT_SET"}" == "NOT_SET" ]] +} diff --git a/test/fixtures/file_setup_teardown/setup_file_even_if_all_tests_are_skipped.bats b/test/fixtures/file_setup_teardown/setup_file_even_if_all_tests_are_skipped.bats index ae339957a5..791b14830b 100644 --- a/test/fixtures/file_setup_teardown/setup_file_even_if_all_tests_are_skipped.bats +++ b/test/fixtures/file_setup_teardown/setup_file_even_if_all_tests_are_skipped.bats @@ -1,7 +1,7 @@ setup_file() { - echo "$BATS_TEST_FILENAME" >> "$LOG" + echo "$BATS_TEST_FILENAME" >>"$LOG" } @test "test" { - skip "We only want to see if setup file runs" -} \ No newline at end of file + skip "We only want to see if setup file runs" +} diff --git a/test/fixtures/file_setup_teardown/setup_file_failed.bats b/test/fixtures/file_setup_teardown/setup_file_failed.bats index 2a8e3287b1..4811c513e9 100644 --- a/test/fixtures/file_setup_teardown/setup_file_failed.bats +++ b/test/fixtures/file_setup_teardown/setup_file_failed.bats @@ -1,11 +1,11 @@ setup_file() { - false + false } @test "test 1" { - true + true } @test "test 2" { - true -} \ No newline at end of file + true +} diff --git a/test/fixtures/file_setup_teardown/setup_file_halfway_error.bats b/test/fixtures/file_setup_teardown/setup_file_halfway_error.bats index 929bf29929..3a156a54fc 100644 --- a/test/fixtures/file_setup_teardown/setup_file_halfway_error.bats +++ b/test/fixtures/file_setup_teardown/setup_file_halfway_error.bats @@ -1,9 +1,9 @@ setup_file() { - true - false - true + true + false + true } @test "test" { - true -} \ No newline at end of file + true +} diff --git a/test/fixtures/file_setup_teardown/teardown_file.bats b/test/fixtures/file_setup_teardown/teardown_file.bats index 50886fb71e..7ae78d1121 100644 --- a/test/fixtures/file_setup_teardown/teardown_file.bats +++ b/test/fixtures/file_setup_teardown/teardown_file.bats @@ -1,11 +1,11 @@ teardown_file() { - echo "$BATS_TEST_FILENAME" >> "$LOG" + echo "$BATS_TEST_FILENAME" >>"$LOG" } @test "first" { - true + true } @test "second" { - true -} \ No newline at end of file + true +} diff --git a/test/fixtures/file_setup_teardown/teardown_file2.bats b/test/fixtures/file_setup_teardown/teardown_file2.bats index 50886fb71e..7ae78d1121 100644 --- a/test/fixtures/file_setup_teardown/teardown_file2.bats +++ b/test/fixtures/file_setup_teardown/teardown_file2.bats @@ -1,11 +1,11 @@ teardown_file() { - echo "$BATS_TEST_FILENAME" >> "$LOG" + echo "$BATS_TEST_FILENAME" >>"$LOG" } @test "first" { - true + true } @test "second" { - true -} \ No newline at end of file + true +} diff --git a/test/fixtures/file_setup_teardown/teardown_file_after_failing_test.bats b/test/fixtures/file_setup_teardown/teardown_file_after_failing_test.bats index 05d8b14de9..3e8fb54ac6 100644 --- a/test/fixtures/file_setup_teardown/teardown_file_after_failing_test.bats +++ b/test/fixtures/file_setup_teardown/teardown_file_after_failing_test.bats @@ -1,7 +1,7 @@ teardown_file() { - echo "$BATS_TEST_FILENAME" >> "$LOG" + echo "$BATS_TEST_FILENAME" >>"$LOG" } @test "failing test" { - false -} \ No newline at end of file + false +} diff --git a/test/fixtures/file_setup_teardown/teardown_file_after_long_test.bats b/test/fixtures/file_setup_teardown/teardown_file_after_long_test.bats index c3acdf1ae3..c266c462e3 100644 --- a/test/fixtures/file_setup_teardown/teardown_file_after_long_test.bats +++ b/test/fixtures/file_setup_teardown/teardown_file_after_long_test.bats @@ -1,8 +1,8 @@ teardown_file() { - echo "$BATS_TEST_FILENAME" >> "$LOG" + echo "$BATS_TEST_FILENAME" >>"$LOG" } @test "long running test" { - sleep 10 - echo "test finished successfully" >> "$LOG" -} \ No newline at end of file + sleep 10 + echo "test finished successfully" >>"$LOG" +} diff --git a/test/fixtures/file_setup_teardown/teardown_file_does_not_leak.bats b/test/fixtures/file_setup_teardown/teardown_file_does_not_leak.bats index cf620cdffc..9288045213 100644 --- a/test/fixtures/file_setup_teardown/teardown_file_does_not_leak.bats +++ b/test/fixtures/file_setup_teardown/teardown_file_does_not_leak.bats @@ -1,7 +1,7 @@ teardown_file() { - export POTENTIALLY_LEAKING_VARIABLE="$BATS_TEST_FILENAME" + export POTENTIALLY_LEAKING_VARIABLE="$BATS_TEST_FILENAME" } @test "test" { - true -} \ No newline at end of file + true +} diff --git a/test/fixtures/file_setup_teardown/teardown_file_does_not_leak2.bats b/test/fixtures/file_setup_teardown/teardown_file_does_not_leak2.bats index ed85ac934a..2af74fd3f3 100644 --- a/test/fixtures/file_setup_teardown/teardown_file_does_not_leak2.bats +++ b/test/fixtures/file_setup_teardown/teardown_file_does_not_leak2.bats @@ -1,3 +1,3 @@ @test "must not see variable from first run" { - [[ -z "${POTENTIALLY_LEAKING_VARIABLE:-}" ]] -} \ No newline at end of file + [[ -z "${POTENTIALLY_LEAKING_VARIABLE:-}" ]] +} diff --git a/test/fixtures/file_setup_teardown/teardown_file_even_if_all_tests_are_skipped.bats b/test/fixtures/file_setup_teardown/teardown_file_even_if_all_tests_are_skipped.bats index ba63ece26d..6263ffa673 100644 --- a/test/fixtures/file_setup_teardown/teardown_file_even_if_all_tests_are_skipped.bats +++ b/test/fixtures/file_setup_teardown/teardown_file_even_if_all_tests_are_skipped.bats @@ -1,7 +1,7 @@ teardown_file() { - echo "$BATS_TEST_FILENAME" >> "$LOG" + echo "$BATS_TEST_FILENAME" >>"$LOG" } @test "skipped test" { - skip 'All tests in this file are skipped! Teardown_file runs anyways' -} \ No newline at end of file + skip 'All tests in this file are skipped! Teardown_file runs anyways' +} diff --git a/test/fixtures/file_setup_teardown/teardown_file_failed.bats b/test/fixtures/file_setup_teardown/teardown_file_failed.bats index 627b1201f6..14b22f74e5 100644 --- a/test/fixtures/file_setup_teardown/teardown_file_failed.bats +++ b/test/fixtures/file_setup_teardown/teardown_file_failed.bats @@ -1,8 +1,7 @@ - teardown_file() { - false + false } @test "test" { - true -} \ No newline at end of file + true +} diff --git a/test/fixtures/file_setup_teardown/teardown_file_halfway_error.bats b/test/fixtures/file_setup_teardown/teardown_file_halfway_error.bats index 1337805826..326b16a99e 100644 --- a/test/fixtures/file_setup_teardown/teardown_file_halfway_error.bats +++ b/test/fixtures/file_setup_teardown/teardown_file_halfway_error.bats @@ -1,9 +1,9 @@ teardown_file() { - true - false - true + true + false + true } @test "empty" { - true -} \ No newline at end of file + true +} diff --git a/test/fixtures/formatter/dummy-formatter b/test/fixtures/formatter/dummy-formatter index 1ff9abd624..255acc0544 100755 --- a/test/fixtures/formatter/dummy-formatter +++ b/test/fixtures/formatter/dummy-formatter @@ -1,5 +1,5 @@ #!/usr/bin/env bash -cat >/dev/null # ignore input +cat >/dev/null # ignore input -echo "Dummy Formatter!" \ No newline at end of file +echo "Dummy Formatter!" diff --git a/test/fixtures/junit-formatter/duplicate/first/file1.bats b/test/fixtures/junit-formatter/duplicate/first/file1.bats index e1df58729d..3084334434 100644 --- a/test/fixtures/junit-formatter/duplicate/first/file1.bats +++ b/test/fixtures/junit-formatter/duplicate/first/file1.bats @@ -1,3 +1,3 @@ @test "test in duplicate file" { - true -} \ No newline at end of file + true +} diff --git a/test/fixtures/junit-formatter/duplicate/second/file1.bats b/test/fixtures/junit-formatter/duplicate/second/file1.bats index e1df58729d..3084334434 100644 --- a/test/fixtures/junit-formatter/duplicate/second/file1.bats +++ b/test/fixtures/junit-formatter/duplicate/second/file1.bats @@ -1,3 +1,3 @@ @test "test in duplicate file" { - true -} \ No newline at end of file + true +} diff --git a/test/fixtures/junit-formatter/issue_360.bats b/test/fixtures/junit-formatter/issue_360.bats index f4bd850bdb..3cf103636d 100644 --- a/test/fixtures/junit-formatter/issue_360.bats +++ b/test/fixtures/junit-formatter/issue_360.bats @@ -1,22 +1,22 @@ #!/usr/bin/env bats setup() { - echo "# setup stdout" - echo "# setup FD3" >&3 + echo "# setup stdout" + echo "# setup FD3" >&3 } teardown() { - echo "# teardown stdout" - echo "# teardown FD3" >&3 + echo "# teardown stdout" + echo "# teardown FD3" >&3 } @test "say hello to Biblo" { - echo "# hello stdout" - echo "# hello Bilbo" >&3 + echo "# hello stdout" + echo "# hello Bilbo" >&3 } @test "fail to say hello to Biblo" { - echo "# hello stdout" - echo "# hello Bilbo" >&3 - false -} \ No newline at end of file + echo "# hello stdout" + echo "# hello Bilbo" >&3 + false +} diff --git a/test/fixtures/junit-formatter/issue_531.bats b/test/fixtures/junit-formatter/issue_531.bats index b4add812ae..d7135e027b 100644 --- a/test/fixtures/junit-formatter/issue_531.bats +++ b/test/fixtures/junit-formatter/issue_531.bats @@ -1,16 +1,16 @@ #!/usr/bin/env bats setup_file() { - echo "# setup_file stdout" - echo "# setup_file fd3" >&3 + echo "# setup_file stdout" + echo "# setup_file fd3" >&3 } teardown_file() { - echo "# teardown_file stdout" - echo "# teardown_file fd3" >&3 + echo "# teardown_file stdout" + echo "# teardown_file fd3" >&3 } @test "My test" { - echo "# test stdout" - echo "# test fd3" >&3 -} \ No newline at end of file + echo "# test stdout" + echo "# test fd3" >&3 +} diff --git a/test/fixtures/junit-formatter/skipped.bats b/test/fixtures/junit-formatter/skipped.bats index aeedda181a..3a37a6776f 100644 --- a/test/fixtures/junit-formatter/skipped.bats +++ b/test/fixtures/junit-formatter/skipped.bats @@ -6,4 +6,4 @@ @test "a skipped test with a reason" { skip "a reason" -} \ No newline at end of file +} diff --git a/test/fixtures/junit-formatter/suite/file1.bats b/test/fixtures/junit-formatter/suite/file1.bats index e2be967be4..f39c513874 100644 --- a/test/fixtures/junit-formatter/suite/file1.bats +++ b/test/fixtures/junit-formatter/suite/file1.bats @@ -1,3 +1,3 @@ @test "one test" { - true -} \ No newline at end of file + true +} diff --git a/test/fixtures/junit-formatter/suite/file2.bats b/test/fixtures/junit-formatter/suite/file2.bats index 7f6bd39558..624efe4ee8 100644 --- a/test/fixtures/junit-formatter/suite/file2.bats +++ b/test/fixtures/junit-formatter/suite/file2.bats @@ -1,3 +1,3 @@ @test "another test" { - true -} \ No newline at end of file + true +} diff --git a/test/fixtures/junit-formatter/xml-escape.bats b/test/fixtures/junit-formatter/xml-escape.bats index 71a8101d0f..da0b1e00ad 100644 --- a/test/fixtures/junit-formatter/xml-escape.bats +++ b/test/fixtures/junit-formatter/xml-escape.bats @@ -8,4 +8,4 @@ @test "Skipped test with escape characters: \"'<>& (0x1b)" { skip "\"'<>&" -} \ No newline at end of file +} diff --git a/test/fixtures/load/failing_bats_load_library.bats b/test/fixtures/load/failing_bats_load_library.bats index 3bff0baf24..0adb3be623 100644 --- a/test/fixtures/load/failing_bats_load_library.bats +++ b/test/fixtures/load/failing_bats_load_library.bats @@ -1,5 +1,5 @@ bats_load_library "return1" @test "true" { - true + true } diff --git a/test/fixtures/load/failing_load.bats b/test/fixtures/load/failing_load.bats index f17935ca81..f437dacdf6 100644 --- a/test/fixtures/load/failing_load.bats +++ b/test/fixtures/load/failing_load.bats @@ -1,5 +1,5 @@ load "return1" @test "true" { - true + true } diff --git a/test/fixtures/load/find_library_helper.bats b/test/fixtures/load/find_library_helper.bats index d42b7458ac..a95cd04536 100644 --- a/test/fixtures/load/find_library_helper.bats +++ b/test/fixtures/load/find_library_helper.bats @@ -1,5 +1,5 @@ @test "find a library" { - run find_in_bats_lib_path "$LIBRARY_NAME" - [ $status -eq 0 ] - [ "${lines[0]}" = "$LIBRARY_PATH" ] + run find_in_bats_lib_path "$LIBRARY_NAME" + [ $status -eq 0 ] + [ "${lines[0]}" = "$LIBRARY_PATH" ] } diff --git a/test/fixtures/load/find_library_helper_err.bats b/test/fixtures/load/find_library_helper_err.bats index 0ff3345743..e38491dd6f 100644 --- a/test/fixtures/load/find_library_helper_err.bats +++ b/test/fixtures/load/find_library_helper_err.bats @@ -1,4 +1,4 @@ @test "does not find a library" { - run find_in_bats_lib_path "$LIBRARY_NAME" - [ $status -eq 1 ] + run find_in_bats_lib_path "$LIBRARY_NAME" + [ $status -eq 1 ] } diff --git a/test/fixtures/load/load_in_teardown_after_failure.bats b/test/fixtures/load/load_in_teardown_after_failure.bats index 673040a922..a24d6dc7d3 100644 --- a/test/fixtures/load/load_in_teardown_after_failure.bats +++ b/test/fixtures/load/load_in_teardown_after_failure.bats @@ -1,7 +1,7 @@ teardown() { - load 'test_helper' + load 'test_helper' } @test failed { - false -} \ No newline at end of file + false +} diff --git a/test/fixtures/parallel/must_not_parallelize_across_files/file1.bats b/test/fixtures/parallel/must_not_parallelize_across_files/file1.bats index 144390ed39..86c96a0d5a 100644 --- a/test/fixtures/parallel/must_not_parallelize_across_files/file1.bats +++ b/test/fixtures/parallel/must_not_parallelize_across_files/file1.bats @@ -1,14 +1,14 @@ setup() { - echo "start $BATS_TEST_NAME" >> "$FILE_MARKER" + echo "start $BATS_TEST_NAME" >>"$FILE_MARKER" } teardown() { - echo "end $BATS_TEST_NAME" >> "$FILE_MARKER" + echo "end $BATS_TEST_NAME" >>"$FILE_MARKER" } @test "test 1" { - # stretch the time this test runs to prevent accidental serialization by the scheduler - # if both tests could run in parallel, this will increase the likelihood of detecting it - # by delaying this test's teardown past the other's - sleep 3 + # stretch the time this test runs to prevent accidental serialization by the scheduler + # if both tests could run in parallel, this will increase the likelihood of detecting it + # by delaying this test's teardown past the other's + sleep 3 } diff --git a/test/fixtures/parallel/must_not_parallelize_across_files/file2.bats b/test/fixtures/parallel/must_not_parallelize_across_files/file2.bats index 6ec54bc570..df29fd918d 100644 --- a/test/fixtures/parallel/must_not_parallelize_across_files/file2.bats +++ b/test/fixtures/parallel/must_not_parallelize_across_files/file2.bats @@ -1,19 +1,19 @@ setup() { - echo "start $BATS_TEST_NAME" >> "$FILE_MARKER" + echo "start $BATS_TEST_NAME" >>"$FILE_MARKER" } teardown() { - echo "end $BATS_TEST_NAME" >> "$FILE_MARKER" + echo "end $BATS_TEST_NAME" >>"$FILE_MARKER" } @test "test 2" { - run cat "$FILE_MARKER" - echo "$output" + run cat "$FILE_MARKER" + echo "$output" - # assuming serialized, ordered execution we will always see the first test start and end before this runs - [[ "${lines[0]}" == "start"* ]] - OTHER_TEST_NAME="${lines[0]:6}" - [[ "$OTHER_TEST_NAME" != "$BATS_TEST_NAME" ]] - [[ "${lines[1]}" == "end $OTHER_TEST_NAME" ]] - [[ "${lines[2]}" == "start $BATS_TEST_NAME" ]] -} \ No newline at end of file + # assuming serialized, ordered execution we will always see the first test start and end before this runs + [[ "${lines[0]}" == "start"* ]] + OTHER_TEST_NAME="${lines[0]:6}" + [[ "$OTHER_TEST_NAME" != "$BATS_TEST_NAME" ]] + [[ "${lines[1]}" == "end $OTHER_TEST_NAME" ]] + [[ "${lines[2]}" == "start $BATS_TEST_NAME" ]] +} diff --git a/test/fixtures/parallel/must_not_parallelize_within_file.bats b/test/fixtures/parallel/must_not_parallelize_within_file.bats index 22f5e2d5c9..b8380df16d 100644 --- a/test/fixtures/parallel/must_not_parallelize_within_file.bats +++ b/test/fixtures/parallel/must_not_parallelize_within_file.bats @@ -1,52 +1,52 @@ setup_file() { - export FILE_MARKER - FILE_MARKER=$(mktemp "${BATS_RUN_TMPDIR}/file_marker.XXXXXX") - if [[ -n "${DISABLE_IN_SETUP_FILE_FUNCTION:-}" ]]; then - export BATS_NO_PARALLELIZE_WITHIN_FILE=true - echo "setup_file() sets BATS_NO_PARALLELIZE_WITHIN_FILE=true" >&2 - fi + export FILE_MARKER + FILE_MARKER=$(mktemp "${BATS_RUN_TMPDIR}/file_marker.XXXXXX") + if [[ -n "${DISABLE_IN_SETUP_FILE_FUNCTION:-}" ]]; then + export BATS_NO_PARALLELIZE_WITHIN_FILE=true + echo "setup_file() sets BATS_NO_PARALLELIZE_WITHIN_FILE=true" >&2 + fi } if [[ -n "${DISABLE_OUTSIDE_ALL_FUNCTIONS:-}" ]]; then - export BATS_NO_PARALLELIZE_WITHIN_FILE=true - echo "File sets BATS_NO_PARALLELIZE_WITHIN_FILE=true" >&2 + export BATS_NO_PARALLELIZE_WITHIN_FILE=true + echo "File sets BATS_NO_PARALLELIZE_WITHIN_FILE=true" >&2 fi teardown_file() { - rm "$FILE_MARKER" + rm "$FILE_MARKER" } setup() { - if [[ -n "${DISABLE_IN_SETUP_FUNCTION:-}" ]]; then - export BATS_NO_PARALLELIZE_WITHIN_FILE=true - echo "setup() sets BATS_NO_PARALLELIZE_WITHIN_FILE=true" >&3 - fi - echo "start $BATS_TEST_NAME" >> "$FILE_MARKER" + if [[ -n "${DISABLE_IN_SETUP_FUNCTION:-}" ]]; then + export BATS_NO_PARALLELIZE_WITHIN_FILE=true + echo "setup() sets BATS_NO_PARALLELIZE_WITHIN_FILE=true" >&3 + fi + echo "start $BATS_TEST_NAME" >>"$FILE_MARKER" } teardown() { - echo "end $BATS_TEST_NAME" >> "$FILE_MARKER" + echo "end $BATS_TEST_NAME" >>"$FILE_MARKER" } @test "test 1" { - if [[ -n "${DISABLE_IN_TEST_FUNCTION:-}" ]]; then - export BATS_NO_PARALLELIZE_WITHIN_FILE=true - echo "Test function sets BATS_NO_PARALLELIZE_WITHIN_FILE=true" >&3 - fi - # stretch the time this test runs to prevent accidental serialization by the scheduler - # if both tests could run in parallel, this will increase the likelihood of detecting it - # by delaying this test's teardown past the other's - sleep 3 + if [[ -n "${DISABLE_IN_TEST_FUNCTION:-}" ]]; then + export BATS_NO_PARALLELIZE_WITHIN_FILE=true + echo "Test function sets BATS_NO_PARALLELIZE_WITHIN_FILE=true" >&3 + fi + # stretch the time this test runs to prevent accidental serialization by the scheduler + # if both tests could run in parallel, this will increase the likelihood of detecting it + # by delaying this test's teardown past the other's + sleep 3 } @test "test 2" { - run cat "$FILE_MARKER" - echo "$output" + run cat "$FILE_MARKER" + echo "$output" - # assuming serialized, ordered execution we will always see the first test start and end before this runs - [[ "${lines[0]}" == "start"* ]] - OTHER_TEST_NAME="${lines[0]:6}" - [[ "$OTHER_TEST_NAME" != "$BATS_TEST_NAME" ]] - [[ "${lines[1]}" == "end $OTHER_TEST_NAME" ]] - [[ "${lines[2]}" == "start $BATS_TEST_NAME" ]] + # assuming serialized, ordered execution we will always see the first test start and end before this runs + [[ "${lines[0]}" == "start"* ]] + OTHER_TEST_NAME="${lines[0]:6}" + [[ "$OTHER_TEST_NAME" != "$BATS_TEST_NAME" ]] + [[ "${lines[1]}" == "end $OTHER_TEST_NAME" ]] + [[ "${lines[2]}" == "start $BATS_TEST_NAME" ]] } diff --git a/test/fixtures/parallel/parallel-preserve-environment.bats b/test/fixtures/parallel/parallel-preserve-environment.bats index c40322b2db..729e1c66cc 100644 --- a/test/fixtures/parallel/parallel-preserve-environment.bats +++ b/test/fixtures/parallel/parallel-preserve-environment.bats @@ -1,8 +1,8 @@ setup_file() { - export OTHER_ENV_VARIABLE='my-value' + export OTHER_ENV_VARIABLE='my-value' } @test "check env variables are set" { - [[ "$TEST_ENV_VARIABLE" == "test-value" ]] - [[ "$OTHER_ENV_VARIABLE" == "my-value" ]] -} \ No newline at end of file + [[ "$TEST_ENV_VARIABLE" == "test-value" ]] + [[ "$OTHER_ENV_VARIABLE" == "my-value" ]] +} diff --git a/test/fixtures/parallel/parallel.bats b/test/fixtures/parallel/parallel.bats index 5a3eba4386..046a165f09 100644 --- a/test/fixtures/parallel/parallel.bats +++ b/test/fixtures/parallel/parallel.bats @@ -1,10 +1,10 @@ setup() { load '../../concurrent-coordination' - echo "start $BATS_TEST_NAME $BATS_TEST_FILENAME" >> "$FILE_MARKER" + echo "start $BATS_TEST_NAME $BATS_TEST_FILENAME" >>"$FILE_MARKER" } teardown() { - echo "stop $BATS_TEST_NAME $BATS_TEST_FILENAME" >> "$FILE_MARKER" + echo "stop $BATS_TEST_NAME $BATS_TEST_FILENAME" >>"$FILE_MARKER" } @test "slow test 1" { @@ -17,4 +17,4 @@ teardown() { @test "slow test 3" { single-use-barrier "parallel" "$PARALLELITY" -} \ No newline at end of file +} diff --git a/test/fixtures/parallel/parallel_factor.bats b/test/fixtures/parallel/parallel_factor.bats index f687fbdf5f..67b83f81e7 100644 --- a/test/fixtures/parallel/parallel_factor.bats +++ b/test/fixtures/parallel/parallel_factor.bats @@ -1,10 +1,10 @@ setup() { load '../../concurrent-coordination' - echo setup "$BATS_TEST_NUMBER" >> "${MARKER_FILE?}" + echo setup "$BATS_TEST_NUMBER" >>"${MARKER_FILE?}" } teardown() { - echo teardown "$BATS_TEST_NUMBER" >> "${MARKER_FILE?}" + echo teardown "$BATS_TEST_NUMBER" >>"${MARKER_FILE?}" } @test "slow test 1" { diff --git a/test/fixtures/parallel/setup_file/setup_file.bats b/test/fixtures/parallel/setup_file/setup_file.bats index 2f687f93f1..40c8a5ba64 100644 --- a/test/fixtures/parallel/setup_file/setup_file.bats +++ b/test/fixtures/parallel/setup_file/setup_file.bats @@ -1,13 +1,13 @@ setup_file() { - load '../../../concurrent-coordination' - echo "start $BATS_TEST_FILENAME" >> "${FILE_MARKER?}" - single-use-barrier setup-file "${PARALLELITY?}" 10 + load '../../../concurrent-coordination' + echo "start $BATS_TEST_FILENAME" >>"${FILE_MARKER?}" + single-use-barrier setup-file "${PARALLELITY?}" 10 } teardown_file() { - echo "stop $BATS_TEST_FILENAME" >> "$FILE_MARKER" + echo "stop $BATS_TEST_FILENAME" >>"$FILE_MARKER" } @test "nothing" { - true -} \ No newline at end of file + true +} diff --git a/test/fixtures/parallel/suite/parallel1.bats b/test/fixtures/parallel/suite/parallel1.bats index 6bc967dd41..caf557c428 100644 --- a/test/fixtures/parallel/suite/parallel1.bats +++ b/test/fixtures/parallel/suite/parallel1.bats @@ -1,10 +1,10 @@ setup() { load '../../../concurrent-coordination' - echo "start $BATS_TEST_NAME $BATS_TEST_FILENAME" >> "$FILE_MARKER" + echo "start $BATS_TEST_NAME $BATS_TEST_FILENAME" >>"$FILE_MARKER" } teardown() { - echo "stop $BATS_TEST_NAME $BATS_TEST_FILENAME" >> "$FILE_MARKER" + echo "stop $BATS_TEST_NAME $BATS_TEST_FILENAME" >>"$FILE_MARKER" } @test "slow test 1" { @@ -17,4 +17,4 @@ teardown() { @test "slow test 3" { single-use-barrier "parallel" "$PARALLELITY" -} \ No newline at end of file +} diff --git a/test/fixtures/run/failing.bats b/test/fixtures/run/failing.bats index 6b154177f8..fd61992c39 100644 --- a/test/fixtures/run/failing.bats +++ b/test/fixtures/run/failing.bats @@ -20,4 +20,4 @@ bats_require_minimum_version 1.5.0 run -0 echo hi run -127 /no/such/cmd run -1 /etc -} \ No newline at end of file +} diff --git a/test/fixtures/run/invalid.bats b/test/fixtures/run/invalid.bats index 97d9733303..e810d12da1 100644 --- a/test/fixtures/run/invalid.bats +++ b/test/fixtures/run/invalid.bats @@ -4,4 +4,4 @@ @test "run -256 echo hi" { run -256 echo hi -} \ No newline at end of file +} diff --git a/test/fixtures/suite/override_BATS_FILE_EXTENSION/test.bats b/test/fixtures/suite/override_BATS_FILE_EXTENSION/test.bats index 1328af14e0..135f3a185b 100644 --- a/test/fixtures/suite/override_BATS_FILE_EXTENSION/test.bats +++ b/test/fixtures/suite/override_BATS_FILE_EXTENSION/test.bats @@ -1,3 +1,3 @@ @test "test.bats" { - true + true } diff --git a/test/fixtures/suite/skip/skip-in-setup-and-teardown.bats b/test/fixtures/suite/skip/skip-in-setup-and-teardown.bats index 6992a96419..8c58532277 100644 --- a/test/fixtures/suite/skip/skip-in-setup-and-teardown.bats +++ b/test/fixtures/suite/skip/skip-in-setup-and-teardown.bats @@ -1,7 +1,7 @@ #!/usr/bin/env bats -setup () { - skip "This is not working (https://github.com/kata-containers/runtime/issues/175)" +setup() { + skip "This is not working (https://github.com/kata-containers/runtime/issues/175)" } @test "skip in setup and teardown" { @@ -13,5 +13,5 @@ setup () { } teardown() { - skip "This is not working (https://github.com/clearcontainers/runtime/issues/1042)" + skip "This is not working (https://github.com/clearcontainers/runtime/issues/1042)" } diff --git a/test/fixtures/suite/skip/skip-in-setup.bats b/test/fixtures/suite/skip/skip-in-setup.bats index 8ca1c8e2a7..05b72b09bf 100644 --- a/test/fixtures/suite/skip/skip-in-setup.bats +++ b/test/fixtures/suite/skip/skip-in-setup.bats @@ -10,4 +10,4 @@ setup() { @test "skip in setup and test" { skip -} \ No newline at end of file +} diff --git a/test/fixtures/suite/skip/skip-in-teardown.bats b/test/fixtures/suite/skip/skip-in-teardown.bats index 209832b5ee..89896caa65 100644 --- a/test/fixtures/suite/skip/skip-in-teardown.bats +++ b/test/fixtures/suite/skip/skip-in-teardown.bats @@ -5,5 +5,5 @@ } teardown() { - skip "This is not working (https://github.com/clearcontainers/runtime/issues/1042)" + skip "This is not working (https://github.com/clearcontainers/runtime/issues/1042)" } diff --git a/test/fixtures/suite/skip/skip-in-test-and-teardown.bats b/test/fixtures/suite/skip/skip-in-test-and-teardown.bats index aa48ea8559..6c34d9db6d 100644 --- a/test/fixtures/suite/skip/skip-in-test-and-teardown.bats +++ b/test/fixtures/suite/skip/skip-in-test-and-teardown.bats @@ -1,9 +1,9 @@ #!/usr/bin/env bats teardown() { - skip "This is not working (https://github.com/clearcontainers/runtime/issues/1042)" + skip "This is not working (https://github.com/clearcontainers/runtime/issues/1042)" } @test "skip in test and teardown" { - skip "This is not working (https://github.com/clearcontainers/runtime/issues/1042)" + skip "This is not working (https://github.com/clearcontainers/runtime/issues/1042)" } diff --git a/test/fixtures/suite/skip/skip-in-test.bats b/test/fixtures/suite/skip/skip-in-test.bats index 0e340c1f56..f1f2dcdb24 100644 --- a/test/fixtures/suite/skip/skip-in-test.bats +++ b/test/fixtures/suite/skip/skip-in-test.bats @@ -1,5 +1,5 @@ #!/usr/bin/env bats @test "skip in test" { - skip "This is not working (https://github.com/clearcontainers/runtime/issues/1042)" + skip "This is not working (https://github.com/clearcontainers/runtime/issues/1042)" } diff --git a/test/fixtures/suite/test_number/file1.bats b/test/fixtures/suite/test_number/file1.bats index 1b692ec16c..8ab3a27d42 100644 --- a/test/fixtures/suite/test_number/file1.bats +++ b/test/fixtures/suite/test_number/file1.bats @@ -1,18 +1,18 @@ #!/usr/bin/env bats @test "first test in file 1" { - echo "BATS_TEST_NUMBER=$BATS_TEST_NUMBER" - [[ "$BATS_TEST_NUMBER" == 1 ]] - echo "BATS_SUITE_TEST_NUMBER=$BATS_SUITE_TEST_NUMBER" - [[ "$BATS_SUITE_TEST_NUMBER" == 1 ]] + echo "BATS_TEST_NUMBER=$BATS_TEST_NUMBER" + [[ "$BATS_TEST_NUMBER" == 1 ]] + echo "BATS_SUITE_TEST_NUMBER=$BATS_SUITE_TEST_NUMBER" + [[ "$BATS_SUITE_TEST_NUMBER" == 1 ]] } @test "second test in file 1" { - [[ "$BATS_TEST_NUMBER" == 2 ]] - [[ "$BATS_SUITE_TEST_NUMBER" == 2 ]] + [[ "$BATS_TEST_NUMBER" == 2 ]] + [[ "$BATS_SUITE_TEST_NUMBER" == 2 ]] } @test "BATS_TEST_NAMES is per file" { - echo "${#BATS_TEST_NAMES[@]}" - [[ "${#BATS_TEST_NAMES[@]}" == 3 ]] + echo "${#BATS_TEST_NAMES[@]}" + [[ "${#BATS_TEST_NAMES[@]}" == 3 ]] } diff --git a/test/fixtures/suite/test_number/file2.bats b/test/fixtures/suite/test_number/file2.bats index 636689fc28..c62d10b8f9 100644 --- a/test/fixtures/suite/test_number/file2.bats +++ b/test/fixtures/suite/test_number/file2.bats @@ -1,23 +1,23 @@ #!/usr/bin/env bats @test "first test in file 2" { - echo "BATS_TEST_NUMBER=$BATS_TEST_NUMBER" - [[ "$BATS_TEST_NUMBER" == 1 ]] - echo "BATS_SUITE_TEST_NUMBER=$BATS_SUITE_TEST_NUMBER" - [[ "$BATS_SUITE_TEST_NUMBER" == 4 ]] + echo "BATS_TEST_NUMBER=$BATS_TEST_NUMBER" + [[ "$BATS_TEST_NUMBER" == 1 ]] + echo "BATS_SUITE_TEST_NUMBER=$BATS_SUITE_TEST_NUMBER" + [[ "$BATS_SUITE_TEST_NUMBER" == 4 ]] } @test "second test in file 2" { - [[ "$BATS_TEST_NUMBER" == 2 ]] - [[ "$BATS_SUITE_TEST_NUMBER" == 5 ]] + [[ "$BATS_TEST_NUMBER" == 2 ]] + [[ "$BATS_SUITE_TEST_NUMBER" == 5 ]] } @test "second test in file 3" { - [[ "$BATS_TEST_NUMBER" == 3 ]] - [[ "$BATS_SUITE_TEST_NUMBER" == 6 ]] + [[ "$BATS_TEST_NUMBER" == 3 ]] + [[ "$BATS_SUITE_TEST_NUMBER" == 6 ]] } @test "BATS_TEST_NAMES is per file" { - echo "${#BATS_TEST_NAMES[@]}" - [[ "${#BATS_TEST_NAMES[@]}" == 4 ]] + echo "${#BATS_TEST_NAMES[@]}" + [[ "${#BATS_TEST_NAMES[@]}" == 4 ]] } diff --git a/test/fixtures/suite_setup_teardown/call_load/setup_suite.bash b/test/fixtures/suite_setup_teardown/call_load/setup_suite.bash index d07e006476..1bc38a83ea 100644 --- a/test/fixtures/suite_setup_teardown/call_load/setup_suite.bash +++ b/test/fixtures/suite_setup_teardown/call_load/setup_suite.bash @@ -1,3 +1,3 @@ setup_suite() { - load test_helper -} \ No newline at end of file + load test_helper +} diff --git a/test/fixtures/suite_setup_teardown/call_load/test.bats b/test/fixtures/suite_setup_teardown/call_load/test.bats index d2a7628f6c..23670ca12a 100644 --- a/test/fixtures/suite_setup_teardown/call_load/test.bats +++ b/test/fixtures/suite_setup_teardown/call_load/test.bats @@ -1,3 +1,3 @@ @test passing { - : -} \ No newline at end of file + : +} diff --git a/test/fixtures/suite_setup_teardown/call_load/test_helper.bash b/test/fixtures/suite_setup_teardown/call_load/test_helper.bash index e69de29bb2..8b13789179 100644 --- a/test/fixtures/suite_setup_teardown/call_load/test_helper.bash +++ b/test/fixtures/suite_setup_teardown/call_load/test_helper.bash @@ -0,0 +1 @@ + diff --git a/test/fixtures/suite_setup_teardown/default_name/setup_suite.bash b/test/fixtures/suite_setup_teardown/default_name/setup_suite.bash index e074c802c3..df42a37c5d 100644 --- a/test/fixtures/suite_setup_teardown/default_name/setup_suite.bash +++ b/test/fixtures/suite_setup_teardown/default_name/setup_suite.bash @@ -1,7 +1,7 @@ setup_suite() { - echo setup_suite >> "$LOGFILE" + echo setup_suite >>"$LOGFILE" } teardown_suite() { - echo teardown_suite >> "$LOGFILE" -} \ No newline at end of file + echo teardown_suite >>"$LOGFILE" +} diff --git a/test/fixtures/suite_setup_teardown/default_name/test.bats b/test/fixtures/suite_setup_teardown/default_name/test.bats index d2a7628f6c..23670ca12a 100644 --- a/test/fixtures/suite_setup_teardown/default_name/test.bats +++ b/test/fixtures/suite_setup_teardown/default_name/test.bats @@ -1,3 +1,3 @@ @test passing { - : -} \ No newline at end of file + : +} diff --git a/test/fixtures/suite_setup_teardown/error_in_free_code/setup_suite.bash b/test/fixtures/suite_setup_teardown/error_in_free_code/setup_suite.bash index 578e6cc0e1..7ecf291255 100644 --- a/test/fixtures/suite_setup_teardown/error_in_free_code/setup_suite.bash +++ b/test/fixtures/suite_setup_teardown/error_in_free_code/setup_suite.bash @@ -1,5 +1,5 @@ call-to-undefined-command setup_suite() { - : -} \ No newline at end of file + : +} diff --git a/test/fixtures/suite_setup_teardown/error_in_free_code/test.bats b/test/fixtures/suite_setup_teardown/error_in_free_code/test.bats index 6c9a238ea3..581252daa9 100644 --- a/test/fixtures/suite_setup_teardown/error_in_free_code/test.bats +++ b/test/fixtures/suite_setup_teardown/error_in_free_code/test.bats @@ -1 +1 @@ -@test test { :; } \ No newline at end of file +@test test { :; } diff --git a/test/fixtures/suite_setup_teardown/error_in_setup_suite/setup_suite.bash b/test/fixtures/suite_setup_teardown/error_in_setup_suite/setup_suite.bash index 3c08bb23f5..844add6640 100644 --- a/test/fixtures/suite_setup_teardown/error_in_setup_suite/setup_suite.bash +++ b/test/fixtures/suite_setup_teardown/error_in_setup_suite/setup_suite.bash @@ -1,3 +1,3 @@ setup_suite() { - call-to-undefined-command -} \ No newline at end of file + call-to-undefined-command +} diff --git a/test/fixtures/suite_setup_teardown/error_in_setup_suite/test.bats b/test/fixtures/suite_setup_teardown/error_in_setup_suite/test.bats index 6c9a238ea3..581252daa9 100644 --- a/test/fixtures/suite_setup_teardown/error_in_setup_suite/test.bats +++ b/test/fixtures/suite_setup_teardown/error_in_setup_suite/test.bats @@ -1 +1 @@ -@test test { :; } \ No newline at end of file +@test test { :; } diff --git a/test/fixtures/suite_setup_teardown/error_in_teardown_suite/setup_suite.bash b/test/fixtures/suite_setup_teardown/error_in_teardown_suite/setup_suite.bash index 393927f1cf..b3b4302c66 100644 --- a/test/fixtures/suite_setup_teardown/error_in_teardown_suite/setup_suite.bash +++ b/test/fixtures/suite_setup_teardown/error_in_teardown_suite/setup_suite.bash @@ -1,7 +1,7 @@ setup_suite() { - : + : } teardown_suite() { - call-to-undefined-command -} \ No newline at end of file + call-to-undefined-command +} diff --git a/test/fixtures/suite_setup_teardown/error_in_teardown_suite/test.bats b/test/fixtures/suite_setup_teardown/error_in_teardown_suite/test.bats index 6c9a238ea3..581252daa9 100644 --- a/test/fixtures/suite_setup_teardown/error_in_teardown_suite/test.bats +++ b/test/fixtures/suite_setup_teardown/error_in_teardown_suite/test.bats @@ -1 +1 @@ -@test test { :; } \ No newline at end of file +@test test { :; } diff --git a/test/fixtures/suite_setup_teardown/exported_vars/setup_suite.bash b/test/fixtures/suite_setup_teardown/exported_vars/setup_suite.bash index 5bc7e2248a..e4334fdd82 100644 --- a/test/fixtures/suite_setup_teardown/exported_vars/setup_suite.bash +++ b/test/fixtures/suite_setup_teardown/exported_vars/setup_suite.bash @@ -1,3 +1,3 @@ setup_suite() { - export EXPORTED_VAR="${EXPECTED_VALUE?}" -} \ No newline at end of file + export EXPORTED_VAR="${EXPECTED_VALUE?}" +} diff --git a/test/fixtures/suite_setup_teardown/exported_vars/test.bats b/test/fixtures/suite_setup_teardown/exported_vars/test.bats index 17acc27498..42ea96d90f 100644 --- a/test/fixtures/suite_setup_teardown/exported_vars/test.bats +++ b/test/fixtures/suite_setup_teardown/exported_vars/test.bats @@ -1,11 +1,11 @@ setup_file() { - [ "$EXPORTED_VAR" = "$EXPECTED_VALUE" ] + [ "$EXPORTED_VAR" = "$EXPECTED_VALUE" ] } setup() { - [ "$EXPORTED_VAR" = "$EXPECTED_VALUE" ] + [ "$EXPORTED_VAR" = "$EXPECTED_VALUE" ] } @test test { - [ "$EXPORTED_VAR" = "$EXPECTED_VALUE" ] -} \ No newline at end of file + [ "$EXPORTED_VAR" = "$EXPECTED_VALUE" ] +} diff --git a/test/fixtures/suite_setup_teardown/failure_in_setup_suite/setup_suite.bash b/test/fixtures/suite_setup_teardown/failure_in_setup_suite/setup_suite.bash index 0ec42913c2..42c24cfde4 100644 --- a/test/fixtures/suite_setup_teardown/failure_in_setup_suite/setup_suite.bash +++ b/test/fixtures/suite_setup_teardown/failure_in_setup_suite/setup_suite.bash @@ -1,9 +1,9 @@ setup_suite() { - echo "setup_suite before" >&2 - false - echo "setup_suite after" >&2 + echo "setup_suite before" >&2 + false + echo "setup_suite after" >&2 } teardown_suite() { - echo "teardown_suite" >&2 -} \ No newline at end of file + echo "teardown_suite" >&2 +} diff --git a/test/fixtures/suite_setup_teardown/failure_in_setup_suite/test.bats b/test/fixtures/suite_setup_teardown/failure_in_setup_suite/test.bats index 6c9a238ea3..581252daa9 100644 --- a/test/fixtures/suite_setup_teardown/failure_in_setup_suite/test.bats +++ b/test/fixtures/suite_setup_teardown/failure_in_setup_suite/test.bats @@ -1 +1 @@ -@test test { :; } \ No newline at end of file +@test test { :; } diff --git a/test/fixtures/suite_setup_teardown/failure_in_teardown_suite/setup_suite.bash b/test/fixtures/suite_setup_teardown/failure_in_teardown_suite/setup_suite.bash index 3c8d1a708c..d8c3397c54 100644 --- a/test/fixtures/suite_setup_teardown/failure_in_teardown_suite/setup_suite.bash +++ b/test/fixtures/suite_setup_teardown/failure_in_teardown_suite/setup_suite.bash @@ -1,9 +1,9 @@ setup_suite() { - : + : } teardown_suite() { - echo "teardown_suite before" >&2 - false - echo "teardown_suite after" >&2 -} \ No newline at end of file + echo "teardown_suite before" >&2 + false + echo "teardown_suite after" >&2 +} diff --git a/test/fixtures/suite_setup_teardown/failure_in_teardown_suite/test.bats b/test/fixtures/suite_setup_teardown/failure_in_teardown_suite/test.bats index 6c9a238ea3..581252daa9 100644 --- a/test/fixtures/suite_setup_teardown/failure_in_teardown_suite/test.bats +++ b/test/fixtures/suite_setup_teardown/failure_in_teardown_suite/test.bats @@ -1 +1 @@ -@test test { :; } \ No newline at end of file +@test test { :; } diff --git a/test/fixtures/suite_setup_teardown/no_failure_no_output/setup_suite.bash b/test/fixtures/suite_setup_teardown/no_failure_no_output/setup_suite.bash index ff280fb6f6..7c31b7e91f 100644 --- a/test/fixtures/suite_setup_teardown/no_failure_no_output/setup_suite.bash +++ b/test/fixtures/suite_setup_teardown/no_failure_no_output/setup_suite.bash @@ -1,7 +1,7 @@ setup_suite() { - echo setup_suite + echo setup_suite } teardown_suite() { - echo teardown_suite -} \ No newline at end of file + echo teardown_suite +} diff --git a/test/fixtures/suite_setup_teardown/no_failure_no_output/test.bats b/test/fixtures/suite_setup_teardown/no_failure_no_output/test.bats index d2a7628f6c..23670ca12a 100644 --- a/test/fixtures/suite_setup_teardown/no_failure_no_output/test.bats +++ b/test/fixtures/suite_setup_teardown/no_failure_no_output/test.bats @@ -1,3 +1,3 @@ @test passing { - : -} \ No newline at end of file + : +} diff --git a/test/fixtures/suite_setup_teardown/no_setup_suite_function/setup_suite.bash b/test/fixtures/suite_setup_teardown/no_setup_suite_function/setup_suite.bash index 2894c97549..f7e517c5ee 100644 --- a/test/fixtures/suite_setup_teardown/no_setup_suite_function/setup_suite.bash +++ b/test/fixtures/suite_setup_teardown/no_setup_suite_function/setup_suite.bash @@ -1,3 +1,3 @@ teardown_suite() { - : -} \ No newline at end of file + : +} diff --git a/test/fixtures/suite_setup_teardown/no_setup_suite_function/test.bats b/test/fixtures/suite_setup_teardown/no_setup_suite_function/test.bats index ff320b68bd..8c40677f50 100644 --- a/test/fixtures/suite_setup_teardown/no_setup_suite_function/test.bats +++ b/test/fixtures/suite_setup_teardown/no_setup_suite_function/test.bats @@ -1,3 +1,3 @@ @test test { - : -} \ No newline at end of file + : +} diff --git a/test/fixtures/suite_setup_teardown/non_default_name/setup_suite_non_default.bash b/test/fixtures/suite_setup_teardown/non_default_name/setup_suite_non_default.bash index dfff9e2ef7..f6baf0fa3b 100644 --- a/test/fixtures/suite_setup_teardown/non_default_name/setup_suite_non_default.bash +++ b/test/fixtures/suite_setup_teardown/non_default_name/setup_suite_non_default.bash @@ -1,7 +1,7 @@ setup_suite() { - echo setup_suite non_default >> "$LOGFILE" + echo setup_suite non_default >>"$LOGFILE" } teardown_suite() { - echo teardown_suite non_default >> "$LOGFILE" -} \ No newline at end of file + echo teardown_suite non_default >>"$LOGFILE" +} diff --git a/test/fixtures/suite_setup_teardown/non_default_name/test.bats b/test/fixtures/suite_setup_teardown/non_default_name/test.bats index d2a7628f6c..23670ca12a 100644 --- a/test/fixtures/suite_setup_teardown/non_default_name/test.bats +++ b/test/fixtures/suite_setup_teardown/non_default_name/test.bats @@ -1,3 +1,3 @@ @test passing { - : -} \ No newline at end of file + : +} diff --git a/test/fixtures/suite_setup_teardown/output_with_failure/setup_suite.bash b/test/fixtures/suite_setup_teardown/output_with_failure/setup_suite.bash index 4dcf1c5d59..df9ee78210 100644 --- a/test/fixtures/suite_setup_teardown/output_with_failure/setup_suite.bash +++ b/test/fixtures/suite_setup_teardown/output_with_failure/setup_suite.bash @@ -1,8 +1,8 @@ setup_suite() { - echo setup_suite - false + echo setup_suite + false } teardown_suite() { - echo teardown_suite -} \ No newline at end of file + echo teardown_suite +} diff --git a/test/fixtures/suite_setup_teardown/output_with_failure/test.bats b/test/fixtures/suite_setup_teardown/output_with_failure/test.bats index d2a7628f6c..23670ca12a 100644 --- a/test/fixtures/suite_setup_teardown/output_with_failure/test.bats +++ b/test/fixtures/suite_setup_teardown/output_with_failure/test.bats @@ -1,3 +1,3 @@ @test passing { - : -} \ No newline at end of file + : +} diff --git a/test/fixtures/suite_setup_teardown/pick_up_toplevel/folder1/test.bats b/test/fixtures/suite_setup_teardown/pick_up_toplevel/folder1/test.bats index d2a7628f6c..23670ca12a 100644 --- a/test/fixtures/suite_setup_teardown/pick_up_toplevel/folder1/test.bats +++ b/test/fixtures/suite_setup_teardown/pick_up_toplevel/folder1/test.bats @@ -1,3 +1,3 @@ @test passing { - : -} \ No newline at end of file + : +} diff --git a/test/fixtures/suite_setup_teardown/pick_up_toplevel/folder2/test.bats b/test/fixtures/suite_setup_teardown/pick_up_toplevel/folder2/test.bats index d2a7628f6c..23670ca12a 100644 --- a/test/fixtures/suite_setup_teardown/pick_up_toplevel/folder2/test.bats +++ b/test/fixtures/suite_setup_teardown/pick_up_toplevel/folder2/test.bats @@ -1,3 +1,3 @@ @test passing { - : -} \ No newline at end of file + : +} diff --git a/test/fixtures/suite_setup_teardown/pick_up_toplevel/setup_suite.bash b/test/fixtures/suite_setup_teardown/pick_up_toplevel/setup_suite.bash index e5f142c91c..72f3527335 100644 --- a/test/fixtures/suite_setup_teardown/pick_up_toplevel/setup_suite.bash +++ b/test/fixtures/suite_setup_teardown/pick_up_toplevel/setup_suite.bash @@ -1,7 +1,7 @@ setup_suite() { - echo "${BASH_SOURCE[0]}" setup_suite >> "$LOGFILE" + echo "${BASH_SOURCE[0]}" setup_suite >>"$LOGFILE" } teardown_suite() { - echo "${BASH_SOURCE[0]}" teardown_suite >> "$LOGFILE" -} \ No newline at end of file + echo "${BASH_SOURCE[0]}" teardown_suite >>"$LOGFILE" +} diff --git a/test/fixtures/suite_setup_teardown/pick_up_toplevel/test.bats b/test/fixtures/suite_setup_teardown/pick_up_toplevel/test.bats index d2a7628f6c..23670ca12a 100644 --- a/test/fixtures/suite_setup_teardown/pick_up_toplevel/test.bats +++ b/test/fixtures/suite_setup_teardown/pick_up_toplevel/test.bats @@ -1,3 +1,3 @@ @test passing { - : -} \ No newline at end of file + : +} diff --git a/test/fixtures/suite_setup_teardown/return_nonzero_in_teardown_suite/setup_suite.bash b/test/fixtures/suite_setup_teardown/return_nonzero_in_teardown_suite/setup_suite.bash index 8d6a8b3864..8a1a18aec5 100644 --- a/test/fixtures/suite_setup_teardown/return_nonzero_in_teardown_suite/setup_suite.bash +++ b/test/fixtures/suite_setup_teardown/return_nonzero_in_teardown_suite/setup_suite.bash @@ -1,9 +1,9 @@ setup_suite() { - : + : } teardown_suite() { - echo "teardown_suite before" >&2 - return 1 - echo "teardown_suite after" >&2 -} \ No newline at end of file + echo "teardown_suite before" >&2 + return 1 + echo "teardown_suite after" >&2 +} diff --git a/test/fixtures/suite_setup_teardown/return_nonzero_in_teardown_suite/test.bats b/test/fixtures/suite_setup_teardown/return_nonzero_in_teardown_suite/test.bats index 6c9a238ea3..581252daa9 100644 --- a/test/fixtures/suite_setup_teardown/return_nonzero_in_teardown_suite/test.bats +++ b/test/fixtures/suite_setup_teardown/return_nonzero_in_teardown_suite/test.bats @@ -1 +1 @@ -@test test { :; } \ No newline at end of file +@test test { :; } diff --git a/test/fixtures/suite_setup_teardown/stderr_in_setup_teardown_suite/setup_suite.bash b/test/fixtures/suite_setup_teardown/stderr_in_setup_teardown_suite/setup_suite.bash index 41cdc4b6a1..2a3ec9f4e3 100644 --- a/test/fixtures/suite_setup_teardown/stderr_in_setup_teardown_suite/setup_suite.bash +++ b/test/fixtures/suite_setup_teardown/stderr_in_setup_teardown_suite/setup_suite.bash @@ -1,10 +1,10 @@ setup_suite() { - echo setup_suite stdout - echo setup_suite stderr >&2 + echo setup_suite stdout + echo setup_suite stderr >&2 } teardown_suite() { - echo teardown_suite stdout - echo teardown_suite stderr >&2 - false -} \ No newline at end of file + echo teardown_suite stdout + echo teardown_suite stderr >&2 + false +} diff --git a/test/fixtures/suite_setup_teardown/stderr_in_setup_teardown_suite/test.bats b/test/fixtures/suite_setup_teardown/stderr_in_setup_teardown_suite/test.bats index ff320b68bd..8c40677f50 100644 --- a/test/fixtures/suite_setup_teardown/stderr_in_setup_teardown_suite/test.bats +++ b/test/fixtures/suite_setup_teardown/stderr_in_setup_teardown_suite/test.bats @@ -1,3 +1,3 @@ @test test { - : -} \ No newline at end of file + : +} diff --git a/test/fixtures/suite_setup_teardown/syntax_error/test.bats b/test/fixtures/suite_setup_teardown/syntax_error/test.bats index 6c9a238ea3..581252daa9 100644 --- a/test/fixtures/suite_setup_teardown/syntax_error/test.bats +++ b/test/fixtures/suite_setup_teardown/syntax_error/test.bats @@ -1 +1 @@ -@test test { :; } \ No newline at end of file +@test test { :; } diff --git a/test/fixtures/tagging/invalid_tags.bats b/test/fixtures/tagging/invalid_tags.bats index 86c31cb0b7..fe8d228e7e 100644 --- a/test/fixtures/tagging/invalid_tags.bats +++ b/test/fixtures/tagging/invalid_tags.bats @@ -4,5 +4,5 @@ # bats test_tags=,bc # bats test_tags=a+b @test test { - : -} \ No newline at end of file + : +} diff --git a/test/fixtures/tagging/tagged.bats b/test/fixtures/tagging/tagged.bats index ef2f3c304a..9e6bfb2872 100644 --- a/test/fixtures/tagging/tagged.bats +++ b/test/fixtures/tagging/tagged.bats @@ -1,25 +1,25 @@ @test "No tags" { - : + : } # bats file_tags=file:tag:1 @test "Only file tags" { - : + : } # bats test_tags=test:tag:1 @test "File and test tags" { - : + : } # bats test_tags=test:tag:2 @test "File and other test tags" { - : + : } # bats file_tags= # bats test_tags=test:tag:3 @test "Only test tags" { - : + : } diff --git a/test/fixtures/tagging/trimming.bats b/test/fixtures/tagging/trimming.bats index ff4ad694ff..bd94b1cbd1 100644 --- a/test/fixtures/tagging/trimming.bats +++ b/test/fixtures/tagging/trimming.bats @@ -1,5 +1,5 @@ # bats test_tags= test:trim , test:me # bats file_tags= file:trim , file:me @test test { - : -} \ No newline at end of file + : +} diff --git a/test/fixtures/timeout/sleep2.bats b/test/fixtures/timeout/sleep2.bats index 328fe76870..5ad1db0983 100644 --- a/test/fixtures/timeout/sleep2.bats +++ b/test/fixtures/timeout/sleep2.bats @@ -1,5 +1,3 @@ - @test "my sleep ${SLEEP}" { - sleep "${SLEEP?}" + sleep "${SLEEP?}" } - diff --git a/test/fixtures/warnings/BW01.bats b/test/fixtures/warnings/BW01.bats index b914aca39e..3776626b8c 100644 --- a/test/fixtures/warnings/BW01.bats +++ b/test/fixtures/warnings/BW01.bats @@ -1,5 +1,5 @@ @test 'Trigger BW01' { - # shellcheck disable=SC2283,SC1068 - run =0 actually-intended-command with some args # see issue #578 - # no $status check because that should be done above (but isn't!) -} \ No newline at end of file + # shellcheck disable=SC2283,SC1068 + run =0 actually-intended-command with some args # see issue #578 + # no $status check because that should be done above (but isn't!) +} diff --git a/test/fixtures/warnings/BW01_check_exit_code_is_127.bats b/test/fixtures/warnings/BW01_check_exit_code_is_127.bats index 9ce261846a..3ff635862e 100644 --- a/test/fixtures/warnings/BW01_check_exit_code_is_127.bats +++ b/test/fixtures/warnings/BW01_check_exit_code_is_127.bats @@ -1,4 +1,4 @@ @test "Don't trigger BW01 with checked exit code 127" { - bats_require_minimum_version 1.5.0 - run -127 =0 actually-intended-command with some args -} \ No newline at end of file + bats_require_minimum_version 1.5.0 + run -127 =0 actually-intended-command with some args +} diff --git a/test/fixtures/warnings/BW01_no_exit_code_check_no_exit_code_127.bats b/test/fixtures/warnings/BW01_no_exit_code_check_no_exit_code_127.bats index 2ea49539d9..e9b721478a 100644 --- a/test/fixtures/warnings/BW01_no_exit_code_check_no_exit_code_127.bats +++ b/test/fixtures/warnings/BW01_no_exit_code_check_no_exit_code_127.bats @@ -1,3 +1,3 @@ @test "Don't trigger BW01 with exit code !=127 and no check" { - run exit 1 -} \ No newline at end of file + run exit 1 +} diff --git a/test/fixtures/warnings/BW02.bats b/test/fixtures/warnings/BW02.bats index 8b8f29e278..8e14c61822 100644 --- a/test/fixtures/warnings/BW02.bats +++ b/test/fixtures/warnings/BW02.bats @@ -1,3 +1,3 @@ @test "Trigger BW02" { - run --keep-empty-lines true -} \ No newline at end of file + run --keep-empty-lines true +} diff --git a/test/fixtures/warnings/BW03/define_setup_suite_in_wrong_file.bats b/test/fixtures/warnings/BW03/define_setup_suite_in_wrong_file.bats index 26e8cf28a3..fa8042f293 100644 --- a/test/fixtures/warnings/BW03/define_setup_suite_in_wrong_file.bats +++ b/test/fixtures/warnings/BW03/define_setup_suite_in_wrong_file.bats @@ -1,7 +1,7 @@ setup_suite() { - : + : } @test test { - : -} \ No newline at end of file + : +} diff --git a/test/fixtures/warnings/BW03/non_default_setup_suite.bash b/test/fixtures/warnings/BW03/non_default_setup_suite.bash index 6cf26178ab..cacaef2340 100644 --- a/test/fixtures/warnings/BW03/non_default_setup_suite.bash +++ b/test/fixtures/warnings/BW03/non_default_setup_suite.bash @@ -1,3 +1,3 @@ setup_suite() { - : -} \ No newline at end of file + : +} diff --git a/test/fixtures/warnings/BW03/suppress_warning.bats b/test/fixtures/warnings/BW03/suppress_warning.bats index fda1e44c12..70a8fd3c82 100644 --- a/test/fixtures/warnings/BW03/suppress_warning.bats +++ b/test/fixtures/warnings/BW03/suppress_warning.bats @@ -1,10 +1,10 @@ setup_suite() { - : + : } # shellcheck disable=SC2034 BATS_SETUP_SUITE_COMPLETED='suppress BW03' @test test { - : -} \ No newline at end of file + : +} diff --git a/test/formatter.bats b/test/formatter.bats index 284a8b64d9..a87f8bfe40 100644 --- a/test/formatter.bats +++ b/test/formatter.bats @@ -81,14 +81,14 @@ EOF } @test "absolute paths load external formatters" { - bats_require_minimum_version 1.5.0 - reentrant_run -0 bats "$FIXTURE_ROOT/passing.bats" --formatter "$FIXTURE_ROOT/dummy-formatter" - [ "$output" = "Dummy Formatter!" ] + bats_require_minimum_version 1.5.0 + reentrant_run -0 bats "$FIXTURE_ROOT/passing.bats" --formatter "$FIXTURE_ROOT/dummy-formatter" + [ "$output" = "Dummy Formatter!" ] } @test "specifying nonexistent external formatter is an error" { bats_require_minimum_version 1.5.0 - reentrant_run -1 bats "$FIXTURE_ROOT/passing.bats" --formatter "$FIXTURE_ROOT/non-existing-file" + reentrant_run -1 bats "$FIXTURE_ROOT/passing.bats" --formatter "$FIXTURE_ROOT/non-existing-file" [ "$output" = "ERROR: Formatter '$FIXTURE_ROOT/non-existing-file' is not readable!" ] } @@ -96,6 +96,6 @@ EOF bats_require_minimum_version 1.5.0 local non_executable="$BATS_TEST_TMPDIR/non-executable" touch "$non_executable" - reentrant_run -1 bats "$FIXTURE_ROOT/passing.bats" --formatter "$non_executable" + reentrant_run -1 bats "$FIXTURE_ROOT/passing.bats" --formatter "$non_executable" [ "$output" = "ERROR: Formatter '$non_executable' is not executable!" ] -} \ No newline at end of file +} diff --git a/test/junit-formatter.bats b/test/junit-formatter.bats index f73e2908c7..62e2477ba1 100644 --- a/test/junit-formatter.bats +++ b/test/junit-formatter.bats @@ -12,7 +12,7 @@ TESTSUITES_REGEX="" echo "$output" [[ $status -eq 0 ]] [[ "${lines[0]}" == '' ]] - + [[ "${lines[1]}" =~ $TESTSUITES_REGEX ]] TESTSUITE_REGEX="" @@ -29,25 +29,25 @@ TESTSUITES_REGEX="" [[ "${lines[6]}" =~ $TESTCASE_REGEX ]] [[ "${lines[7]}" == *"a reason"* ]] [[ "${lines[8]}" == *""* ]] - + [[ "${lines[9]}" == *""* ]] [[ "${lines[10]}" == *""* ]] } @test "junit formatter: escapes xml special chars" { case $OSTYPE in - linux*|darwin) - # their CI can handle special chars on filename - TEST_FILE_NAME="xml-escape-\"<>'&.bats" - ESCAPED_TEST_FILE_NAME="xml-escape-"<>'&.bats" - TEST_FILE_PATH="$BATS_TEST_TMPDIR/$TEST_FILE_NAME" - cp "$FIXTURE_ROOT/xml-escape.bats" "$TEST_FILE_PATH" + linux* | darwin) + # their CI can handle special chars on filename + TEST_FILE_NAME="xml-escape-\"<>'&.bats" + ESCAPED_TEST_FILE_NAME="xml-escape-"<>'&.bats" + TEST_FILE_PATH="$BATS_TEST_TMPDIR/$TEST_FILE_NAME" + cp "$FIXTURE_ROOT/xml-escape.bats" "$TEST_FILE_PATH" ;; - *) - # use the filename without special chars - TEST_FILE_NAME="xml-escape.bats" - ESCAPED_TEST_FILE_NAME="$TEST_FILE_NAME" - TEST_FILE_PATH="$FIXTURE_ROOT/$TEST_FILE_NAME" + *) + # use the filename without special chars + TEST_FILE_NAME="xml-escape.bats" + ESCAPED_TEST_FILE_NAME="$TEST_FILE_NAME" + TEST_FILE_PATH="$FIXTURE_ROOT/$TEST_FILE_NAME" ;; esac reentrant_run bats --formatter junit "$TEST_FILE_PATH" @@ -157,4 +157,4 @@ TESTSUITES_REGEX="" local stderr='' # silence shellcheck reentrant_run -1 --separate-stderr bats --formatter junit "$FIXTURE_ROOT/../file_setup_teardown/setup_file_failed.bats" [ "${stderr}" == "" ] -} \ No newline at end of file +} diff --git a/test/load.bats b/test/load.bats index 481324727c..75934b46f4 100644 --- a/test/load.bats +++ b/test/load.bats @@ -82,7 +82,7 @@ setup() { mkdir -p "$path_dir/on_path" cp "${FIXTURE_ROOT}/test_helper.bash" "${path_dir}/on_path/load.bash" # shellcheck disable=SC2030,SC2031 - export BATS_LIB_PATH="${path_dir}" HELPER_NAME="on_path" + export BATS_LIB_PATH="${path_dir}" HELPER_NAME="on_path" reentrant_run ! bats "$FIXTURE_ROOT/load.bats" reentrant_run -0 bats "$FIXTURE_ROOT/bats_load_library.bats" } @@ -92,7 +92,7 @@ setup() { { echo "plain_variable='value of plain variable'" echo "plain_array=(test me hard)" - } > "${helper}" + } >"${helper}" load "${helper}" # shellcheck disable=SC2154 @@ -111,13 +111,13 @@ setup() { echo "declare -i an_integer=0x7e4" echo "declare -a an_array=(test me hard)" echo "declare -x exported_variable='value of exported variable'" - } > "${helper}" + } >"${helper}" load "${helper}" [ "${declared_variable:-}" != 'value of declared variable' ] [ "${a_constant:-}" != 'constant value' ] - (( "${an_integer:-2019}" != 2020 )) + (("${an_integer:-2019}" != 2020)) [ "${an_array[2]:-}" != 'hard' ] [ "${exported_variable:-}" != 'value of exported variable' ] @@ -129,7 +129,7 @@ setup() { mkdir -p "$path_dir" cp "${FIXTURE_ROOT}/test_helper.bash" "${path_dir}/on_path" # shellcheck disable=SC2030,SC2031 - export PATH="${path_dir}:$PATH" HELPER_NAME="on_path" + export PATH="${path_dir}:$PATH" HELPER_NAME="on_path" reentrant_run -0 bats "$FIXTURE_ROOT/load.bats" } @@ -147,8 +147,8 @@ setup() { @test "bats_load_library supports libraries with loaders on the BATS_LIB_PATH with multiple libraries" { path_dir="$BATS_TEST_TMPDIR/libraries/" for lib in liba libb libc; do - mkdir -p "$path_dir/$lib" - cp "${FIXTURE_ROOT}/exit1.bash" "$path_dir/$lib/load.bash" + mkdir -p "$path_dir/$lib" + cp "${FIXTURE_ROOT}/exit1.bash" "$path_dir/$lib/load.bash" done mkdir -p "$path_dir/$BATS_TEST_NAME" cp "${FIXTURE_ROOT}/test_helper.bash" "$path_dir/$BATS_TEST_NAME/load.bash" @@ -161,8 +161,8 @@ setup() { @test "bats_load_library can handle whitespaces in BATS_LIB_PATH" { path_dir="$BATS_TEST_TMPDIR/libraries with spaces/" for lib in liba libb libc; do - mkdir -p "$path_dir/$lib" - cp "${FIXTURE_ROOT}/exit1.bash" "$path_dir/$lib/load.bash" + mkdir -p "$path_dir/$lib" + cp "${FIXTURE_ROOT}/exit1.bash" "$path_dir/$lib/load.bash" done mkdir -p "$path_dir/$BATS_TEST_NAME" cp "${FIXTURE_ROOT}/test_helper.bash" "$path_dir/$BATS_TEST_NAME/load.bash" diff --git a/test/parallel.bats b/test/parallel.bats index d0866431ea..8d140caad2 100644 --- a/test/parallel.bats +++ b/test/parallel.bats @@ -18,15 +18,15 @@ check_parallel_tests() { # started_tests=0 read_lines=0 while IFS= read -r line; do - (( ++read_lines )) + ((++read_lines)) case "$line" in - "start "*) - if (( ++started_tests > max_parallel_tests )); then - max_parallel_tests="$started_tests" - fi + "start "*) + if ((++started_tests > max_parallel_tests)); then + max_parallel_tests="$started_tests" + fi ;; - "stop "*) - (( started_tests-- )) + "stop "*) + ((started_tests--)) ;; esac done <"$FILE_MARKER" @@ -46,7 +46,7 @@ check_parallel_tests() { # # shellcheck disable=SC2030 export PARALLELITY=3 reentrant_run bats --jobs $PARALLELITY "$FIXTURE_ROOT/parallel.bats" - + [ "$status" -eq 0 ] # Make sure the lines are in-order. [[ "${lines[0]}" == "1..3" ]] @@ -74,7 +74,7 @@ check_parallel_tests() { # # file parallelization is needed for maximum parallelity! # If we got over the skip (if no GNU parallel) in setup() we can reenable it safely! - unset BATS_NO_PARALLELIZE_ACROSS_FILES + unset BATS_NO_PARALLELIZE_ACROSS_FILES reentrant_run bash -c "bats --jobs $PARALLELITY \"${FIXTURE_ROOT}/suite/\" 2> >(grep -v '^parallel: Warning: ')" echo "$output" @@ -102,11 +102,14 @@ check_parallel_tests() { # # file parallelization is needed for this test! # If we got over the skip (if no GNU parallel) in setup() we can reenable it safely! - unset BATS_NO_PARALLELIZE_ACROSS_FILES + unset BATS_NO_PARALLELIZE_ACROSS_FILES # run 4 files with parallelity of 2 -> serialize 2 reentrant_run bats --jobs $PARALLELITY "$FIXTURE_ROOT/setup_file" - [[ $status -eq 0 ]] || (echo "$output"; false) + [[ $status -eq 0 ]] || ( + echo "$output" + false + ) cat "$FILE_MARKER" @@ -132,20 +135,20 @@ check_parallel_tests() { # bats --jobs $PARALLELITY "$FIXTURE_ROOT/parallel_factor.bats" local current_parallel_count=0 maximum_parallel_count=0 total_count=0 while read -r line; do - case "$line" in - setup*) - ((++current_parallel_count)) - ((++total_count)) + case "$line" in + setup*) + ((++current_parallel_count)) + ((++total_count)) + ;; + teardown*) + ((current_parallel_count--)) ;; - teardown*) - ((current_parallel_count--)) - ;; esac - if (( current_parallel_count > maximum_parallel_count )); then + if ((current_parallel_count > maximum_parallel_count)); then maximum_parallel_count=$current_parallel_count fi - done < "$MARKER_FILE" - + done <"$MARKER_FILE" + cat "$MARKER_FILE" # for debugging purposes [[ "$maximum_parallel_count" -eq $PARALLELITY ]] [[ "$current_parallel_count" -eq 0 ]] diff --git a/test/pretty-formatter.bats b/test/pretty-formatter.bats index 15892eb844..a345e86d86 100644 --- a/test/pretty-formatter.bats +++ b/test/pretty-formatter.bats @@ -6,8 +6,8 @@ setup() { } @test "Timing printout shows milliseconds" { - format_example_stream() { - filter_control_sequences bats-format-pretty -T < /usr/bin/bar (relative executable) + # - /usr/bin/foo => /usr/bin/bar (relative executable) ln -s bar usr/bin/foo -# - /usr/bin/bar => /opt/bats/bin0/bar (absolute executable) + # - /usr/bin/bar => /opt/bats/bin0/bar (absolute executable) ln -s "$BATS_TEST_TMPDIR/opt/bats/bin0/bar" usr/bin/bar -# - /opt/bats/bin0 => /opt/bats/bin1 (relative directory) + # - /opt/bats/bin0 => /opt/bats/bin1 (relative directory) ln -s bin1 opt/bats/bin0 -# - /opt/bats/bin1 => /opt/bats/bin2 (absolute directory) + # - /opt/bats/bin1 => /opt/bats/bin2 (absolute directory) ln -s "$BATS_TEST_TMPDIR/opt/bats/bin2" opt/bats/bin1 -# - /opt/bats/bin2/bar => /opt/bats-core/bin/bar (absolute executable) + # - /opt/bats/bin2/bar => /opt/bats-core/bin/bar (absolute executable) ln -s "$BATS_TEST_TMPDIR/opt/bats-core/bin/bar" opt/bats/bin2/bar -# - /opt/bats-core/bin/bar => /opt/bats-core/bin/baz (relative executable) + # - /opt/bats-core/bin/bar => /opt/bats-core/bin/baz (relative executable) ln -s baz opt/bats-core/bin/bar -# - /opt/bats-core/bin/baz => /opt/bats-core/bin/bats (relative executable) + # - /opt/bats-core/bin/baz => /opt/bats-core/bin/bats (relative executable) ln -s bats opt/bats-core/bin/baz # shellcheck disable=SC2103,SC2164 diff --git a/test/run.bats b/test/run.bats index 6511e9117a..10a0595249 100644 --- a/test/run.bats +++ b/test/run.bats @@ -3,84 +3,84 @@ fixtures run bats_require_minimum_version 1.5.0 @test "run --keep-empty-lines preserves leading empty lines" { - run --keep-empty-lines -- echo -n $'\na' - printf "'%s'\n" "${lines[@]}" - [ "${lines[0]}" == '' ] - [ "${lines[1]}" == a ] - [ ${#lines[@]} -eq 2 ] + run --keep-empty-lines -- echo -n $'\na' + printf "'%s'\n" "${lines[@]}" + [ "${lines[0]}" == '' ] + [ "${lines[1]}" == a ] + [ ${#lines[@]} -eq 2 ] } @test "run --keep-empty-lines preserves inner empty lines" { - run --keep-empty-lines -- echo -n $'a\n\nb' - printf "'%s'\n" "${lines[@]}" - [ "${lines[0]}" == a ] - [ "${lines[1]}" == '' ] - [ "${lines[2]}" == b ] - [ ${#lines[@]} -eq 3 ] + run --keep-empty-lines -- echo -n $'a\n\nb' + printf "'%s'\n" "${lines[@]}" + [ "${lines[0]}" == a ] + [ "${lines[1]}" == '' ] + [ "${lines[2]}" == b ] + [ ${#lines[@]} -eq 3 ] } @test "run --keep-empty-lines preserves trailing empty lines" { - run --keep-empty-lines -- echo -n $'a\n' - printf "'%s'\n" "${lines[@]}" - [ "${lines[0]}" == a ] - [ "${lines[1]}" == '' ] - [ ${#lines[@]} -eq 2 ] + run --keep-empty-lines -- echo -n $'a\n' + printf "'%s'\n" "${lines[@]}" + [ "${lines[0]}" == a ] + [ "${lines[1]}" == '' ] + [ ${#lines[@]} -eq 2 ] } @test "run --keep-empty-lines preserves multiple trailing empty lines" { - run --keep-empty-lines -- echo -n $'a\n\n' - printf "'%s'\n" "${lines[@]}" - [ "${lines[0]}" == a ] - [ "${lines[1]}" == '' ] - [ "${lines[2]}" == '' ] - [ ${#lines[@]} -eq 3 ] + run --keep-empty-lines -- echo -n $'a\n\n' + printf "'%s'\n" "${lines[@]}" + [ "${lines[0]}" == a ] + [ "${lines[1]}" == '' ] + [ "${lines[2]}" == '' ] + [ ${#lines[@]} -eq 3 ] } @test "run --keep-empty-lines preserves non-empty trailing line" { - run --keep-empty-lines -- echo -n $'a\nb' - printf "'%s'\n" "${lines[@]}" - [ "${lines[0]}" == a ] - [ "${lines[1]}" == b ] - [ ${#lines[@]} -eq 2 ] + run --keep-empty-lines -- echo -n $'a\nb' + printf "'%s'\n" "${lines[@]}" + [ "${lines[0]}" == a ] + [ "${lines[1]}" == b ] + [ ${#lines[@]} -eq 2 ] } @test "--keep-empty-lines has zero lines for empty output (see #573)" { - run --keep-empty-lines true - printf "'%s'\n" "${lines[@]}" - [ ${#lines[@]} -eq 0 ] + run --keep-empty-lines true + printf "'%s'\n" "${lines[@]}" + [ ${#lines[@]} -eq 0 ] } print-stderr-stdout() { - printf stdout - printf stderr >&2 + printf stdout + printf stderr >&2 } @test "run --separate-stderr splits output" { - local stderr stderr_lines # silence shellcheck - run --separate-stderr -- print-stderr-stdout - echo "output='$output' stderr='$stderr'" - [ "$output" = stdout ] - [ ${#lines[@]} -eq 1 ] + local stderr stderr_lines # silence shellcheck + run --separate-stderr -- print-stderr-stdout + echo "output='$output' stderr='$stderr'" + [ "$output" = stdout ] + [ ${#lines[@]} -eq 1 ] - [ "$stderr" = stderr ] - [ ${#stderr_lines[@]} -eq 1 ] + [ "$stderr" = stderr ] + [ ${#stderr_lines[@]} -eq 1 ] } @test "run does not change set flags" { - old_flags="$-" - run true - echo -- "$-" == "$old_flags" - [ "$-" == "$old_flags" ] + old_flags="$-" + run true + echo -- "$-" == "$old_flags" + [ "$-" == "$old_flags" ] } # Positive assertions: each of these should succeed @test "basic return-code checking" { - run true - run -0 true - run '!' false - run -1 false - run -3 exit 3 - run -5 exit 5 + run true + run -0 true + run '!' false + run -1 false + run -3 exit 3 + run -5 exit 5 run -111 exit 111 run -255 exit 255 run -127 /no/such/command diff --git a/test/suite.bats b/test/suite.bats index 3a65119a72..31f9fa502b 100755 --- a/test/suite.bats +++ b/test/suite.bats @@ -77,9 +77,9 @@ setup() { regex="ok 1 truth in [0-9]+ms" [[ "${lines[1]}" =~ $regex ]] regex="ok 2 more truth in [0-9]+ms" - [[ "${lines[2]}" =~ $regex ]] + [[ "${lines[2]}" =~ $regex ]] regex="not ok 3 quasi-truth in [0-9]+ms" - [[ "${lines[3]}" =~ $regex ]] + [[ "${lines[3]}" =~ $regex ]] } @test "extended timing syntax in suite" { diff --git a/test/suite_setup_teardown.bats b/test/suite_setup_teardown.bats index 5893e01cf5..235549fb36 100644 --- a/test/suite_setup_teardown.bats +++ b/test/suite_setup_teardown.bats @@ -3,144 +3,143 @@ fixtures suite_setup_teardown bats_require_minimum_version 1.5.0 setup() { - export LOGFILE="$BATS_TEST_TMPDIR/log" + export LOGFILE="$BATS_TEST_TMPDIR/log" } @test "setup_suite.bash is picked up in toplevel folder of suite" { - reentrant_run -0 bats -r "$FIXTURE_ROOT/pick_up_toplevel" - run cat "$LOGFILE" + reentrant_run -0 bats -r "$FIXTURE_ROOT/pick_up_toplevel" + run cat "$LOGFILE" - [ "${lines[0]}" = "$FIXTURE_ROOT/pick_up_toplevel/setup_suite.bash setup_suite" ] - [ "${lines[1]}" = "$FIXTURE_ROOT/pick_up_toplevel/setup_suite.bash teardown_suite" ] + [ "${lines[0]}" = "$FIXTURE_ROOT/pick_up_toplevel/setup_suite.bash setup_suite" ] + [ "${lines[1]}" = "$FIXTURE_ROOT/pick_up_toplevel/setup_suite.bash teardown_suite" ] } @test "setup_suite.bash is picked up in folder of first test file" { - reentrant_run -0 bats "$FIXTURE_ROOT/pick_up_toplevel/folder1/test.bats" "$FIXTURE_ROOT/pick_up_toplevel/folder2/test.bats" - run cat "$LOGFILE" + reentrant_run -0 bats "$FIXTURE_ROOT/pick_up_toplevel/folder1/test.bats" "$FIXTURE_ROOT/pick_up_toplevel/folder2/test.bats" + run cat "$LOGFILE" - [ "${lines[0]}" = "$FIXTURE_ROOT/pick_up_toplevel/folder1/setup_suite.bash setup_suite" ] - [ "${lines[1]}" = "$FIXTURE_ROOT/pick_up_toplevel/folder1/setup_suite.bash teardown_suite" ] + [ "${lines[0]}" = "$FIXTURE_ROOT/pick_up_toplevel/folder1/setup_suite.bash setup_suite" ] + [ "${lines[1]}" = "$FIXTURE_ROOT/pick_up_toplevel/folder1/setup_suite.bash teardown_suite" ] } @test "setup_suite is not picked up from wrongly named file" { - reentrant_run -0 bats "$FIXTURE_ROOT/non_default_name/" - run cat "$LOGFILE" - [[ "${output}" != *"setup_suite"* ]] || false - [[ "${output}" != *"teardown_suite"* ]] || false + reentrant_run -0 bats "$FIXTURE_ROOT/non_default_name/" + run cat "$LOGFILE" + [[ "${output}" != *"setup_suite"* ]] || false + [[ "${output}" != *"teardown_suite"* ]] || false } @test "setup_suite is picked up from --setup-suite-file" { - reentrant_run -0 bats "$FIXTURE_ROOT/non_default_name/" \ - --setup-suite-file "$FIXTURE_ROOT/non_default_name/setup_suite_non_default.bash" - run cat "$LOGFILE" - [ "${lines[0]}" == "setup_suite non_default" ] - [ "${lines[1]}" == "teardown_suite non_default" ] + reentrant_run -0 bats "$FIXTURE_ROOT/non_default_name/" \ + --setup-suite-file "$FIXTURE_ROOT/non_default_name/setup_suite_non_default.bash" + run cat "$LOGFILE" + [ "${lines[0]}" == "setup_suite non_default" ] + [ "${lines[1]}" == "teardown_suite non_default" ] } @test "--setup-suite-file takes precedence over convention" { - reentrant_run -0 bats "$FIXTURE_ROOT/default_name/" \ - --setup-suite-file "$FIXTURE_ROOT/non_default_name/setup_suite_non_default.bash" - run cat "$LOGFILE" - [ "${lines[0]}" == "setup_suite non_default" ] - [ "${lines[1]}" == "teardown_suite non_default" ] + reentrant_run -0 bats "$FIXTURE_ROOT/default_name/" \ + --setup-suite-file "$FIXTURE_ROOT/non_default_name/setup_suite_non_default.bash" + run cat "$LOGFILE" + [ "${lines[0]}" == "setup_suite non_default" ] + [ "${lines[1]}" == "teardown_suite non_default" ] } @test "passing a nonexisting file to --setup-suite-file prints an error message" { - reentrant_run -1 bats "$FIXTURE_ROOT/default_name/" \ - --setup-suite-file "/non-existing/setup_suite.bash" - [ "${lines[0]}" == "Error: --setup-suite-file /non-existing/setup_suite.bash does not exist!" ] + reentrant_run -1 bats "$FIXTURE_ROOT/default_name/" \ + --setup-suite-file "/non-existing/setup_suite.bash" + [ "${lines[0]}" == "Error: --setup-suite-file /non-existing/setup_suite.bash does not exist!" ] } @test "setup_suite.bash without setup_suite() is an error" { - reentrant_run ! bats "$FIXTURE_ROOT/no_setup_suite_function/" - [ "${lines[0]}" == "1..1" ] - [ "${lines[1]}" == "not ok 1 setup_suite" ] - [ "${lines[2]}" == "# $FIXTURE_ROOT/no_setup_suite_function/setup_suite.bash does not define \`setup_suite()\`" ] - [ "${#lines[@]}" -eq 3 ] + reentrant_run ! bats "$FIXTURE_ROOT/no_setup_suite_function/" + [ "${lines[0]}" == "1..1" ] + [ "${lines[1]}" == "not ok 1 setup_suite" ] + [ "${lines[2]}" == "# $FIXTURE_ROOT/no_setup_suite_function/setup_suite.bash does not define \`setup_suite()\`" ] + [ "${#lines[@]}" -eq 3 ] } @test "exported variables from setup_suite are visible in setup_file, setup and @test" { - unset EXPORTED_VAR - EXPECTED_VALUE=exported_var reentrant_run -0 bats "$FIXTURE_ROOT/exported_vars/" + unset EXPORTED_VAR + EXPECTED_VALUE=exported_var reentrant_run -0 bats "$FIXTURE_ROOT/exported_vars/" } @test "syntax errors in setup_suite.bash are reported and lead to non zero exit code" { - LANG=C reentrant_run ! bats --setup-suite-file "$FIXTURE_ROOT/syntax_error/setup_suite_no_shellcheck" "$FIXTURE_ROOT/syntax_error/" - [ "${lines[1]}" == "$FIXTURE_ROOT/syntax_error/setup_suite_no_shellcheck: line 2: syntax error: unexpected end of file" ] + LANG=C reentrant_run ! bats --setup-suite-file "$FIXTURE_ROOT/syntax_error/setup_suite_no_shellcheck" "$FIXTURE_ROOT/syntax_error/" + [ "${lines[1]}" == "$FIXTURE_ROOT/syntax_error/setup_suite_no_shellcheck: line 2: syntax error: unexpected end of file" ] } @test "errors in setup_suite.bash's free code reported correctly" { - LANG=C reentrant_run ! bats "$FIXTURE_ROOT/error_in_free_code/" - [ "${lines[1]}" == "$FIXTURE_ROOT/error_in_free_code/setup_suite.bash: line 1: call-to-undefined-command: command not found" ] + LANG=C reentrant_run ! bats "$FIXTURE_ROOT/error_in_free_code/" + [ "${lines[1]}" == "$FIXTURE_ROOT/error_in_free_code/setup_suite.bash: line 1: call-to-undefined-command: command not found" ] } @test "errors in setup_suite reported correctly" { - LANG=C reentrant_run ! bats "$FIXTURE_ROOT/error_in_setup_suite/" - [ "${lines[4]}" == "# $FIXTURE_ROOT/error_in_setup_suite/setup_suite.bash: line 2: call-to-undefined-command: command not found" ] + LANG=C reentrant_run ! bats "$FIXTURE_ROOT/error_in_setup_suite/" + [ "${lines[4]}" == "# $FIXTURE_ROOT/error_in_setup_suite/setup_suite.bash: line 2: call-to-undefined-command: command not found" ] } @test "errors in teardown_suite reported correctly" { - LANG=C reentrant_run ! bats "$FIXTURE_ROOT/error_in_teardown_suite/" - [ "${lines[5]}" == "# $FIXTURE_ROOT/error_in_teardown_suite/setup_suite.bash: line 6: call-to-undefined-command: command not found" ] + LANG=C reentrant_run ! bats "$FIXTURE_ROOT/error_in_teardown_suite/" + [ "${lines[5]}" == "# $FIXTURE_ROOT/error_in_teardown_suite/setup_suite.bash: line 6: call-to-undefined-command: command not found" ] } @test "failure in setup_suite skips further setup and suite but runs teardown_suite" { - reentrant_run ! bats "$FIXTURE_ROOT/failure_in_setup_suite/" - [ "${lines[0]}" == "1..1" ] - # get a nice error message - [ "${lines[1]}" == "not ok 1 setup_suite" ] - [ "${lines[2]}" == "# (from function \`setup_suite' in test file $RELATIVE_FIXTURE_ROOT/failure_in_setup_suite/setup_suite.bash, line 3)" ] - [ "${lines[3]}" == "# \`false' failed" ] - [ "${lines[4]}" == "# setup_suite before" ] # <- only setup_suite code before failure is run - [ "${lines[5]}" == "# teardown_suite" ] # <- teardown is run - [ ${#lines[@]} -eq 6 ] + reentrant_run ! bats "$FIXTURE_ROOT/failure_in_setup_suite/" + [ "${lines[0]}" == "1..1" ] + # get a nice error message + [ "${lines[1]}" == "not ok 1 setup_suite" ] + [ "${lines[2]}" == "# (from function \`setup_suite' in test file $RELATIVE_FIXTURE_ROOT/failure_in_setup_suite/setup_suite.bash, line 3)" ] + [ "${lines[3]}" == "# \`false' failed" ] + [ "${lines[4]}" == "# setup_suite before" ] # <- only setup_suite code before failure is run + [ "${lines[5]}" == "# teardown_suite" ] # <- teardown is run + [ ${#lines[@]} -eq 6 ] } @test "midway failure in teardown_suite does not fail test suite, remaining code is executed" { - reentrant_run -0 bats --show-output-of-passing-tests "$FIXTURE_ROOT/failure_in_teardown_suite/" - [ "${lines[2]}" == "# teardown_suite before" ] - [ "${lines[3]}" == "# teardown_suite after" ] - [ "${#lines[@]}" -eq 4 ] + reentrant_run -0 bats --show-output-of-passing-tests "$FIXTURE_ROOT/failure_in_teardown_suite/" + [ "${lines[2]}" == "# teardown_suite before" ] + [ "${lines[3]}" == "# teardown_suite after" ] + [ "${#lines[@]}" -eq 4 ] } @test "nonzero return in teardown_suite does fails test suite" { - reentrant_run -1 bats "$FIXTURE_ROOT/return_nonzero_in_teardown_suite/" - [ "${lines[0]}" == "1..1" ] - [ "${lines[1]}" == "ok 1 test" ] - [ "${lines[2]}" == "not ok 2 teardown_suite" ] - [ "${lines[3]}" == "# (from function \`teardown_suite' in test file $RELATIVE_FIXTURE_ROOT/return_nonzero_in_teardown_suite/setup_suite.bash, line 7)" ] - [ "${lines[4]}" == "# \`return 1' failed" ] - [ "${lines[5]}" == "# teardown_suite before" ] - [ "${lines[6]}" == "# bats warning: Executed 2 instead of expected 1 tests" ] - [ "${#lines[@]}" -eq 7 ] + reentrant_run -1 bats "$FIXTURE_ROOT/return_nonzero_in_teardown_suite/" + [ "${lines[0]}" == "1..1" ] + [ "${lines[1]}" == "ok 1 test" ] + [ "${lines[2]}" == "not ok 2 teardown_suite" ] + [ "${lines[3]}" == "# (from function \`teardown_suite' in test file $RELATIVE_FIXTURE_ROOT/return_nonzero_in_teardown_suite/setup_suite.bash, line 7)" ] + [ "${lines[4]}" == "# \`return 1' failed" ] + [ "${lines[5]}" == "# teardown_suite before" ] + [ "${lines[6]}" == "# bats warning: Executed 2 instead of expected 1 tests" ] + [ "${#lines[@]}" -eq 7 ] } @test "stderr from setup/teardown_suite does not overtake stdout" { - reentrant_run -1 --separate-stderr bats "$FIXTURE_ROOT/stderr_in_setup_teardown_suite/" - [[ "$output" == *$'setup_suite stdout\n'*'setup_suite stderr'* ]] || false - [[ "$output" == *$'teardown_suite stdout\n'*'teardown_suite stderr'* ]] || false + reentrant_run -1 --separate-stderr bats "$FIXTURE_ROOT/stderr_in_setup_teardown_suite/" + [[ "$output" == *$'setup_suite stdout\n'*'setup_suite stderr'* ]] || false + [[ "$output" == *$'teardown_suite stdout\n'*'teardown_suite stderr'* ]] || false } @test "load is available in setup_suite" { - reentrant_run -0 bats "$FIXTURE_ROOT/call_load/" - [ "${lines[0]}" = "1..1" ] - [ "${lines[1]}" = "ok 1 passing" ] - [ "${#lines[@]}" -eq 2 ] + reentrant_run -0 bats "$FIXTURE_ROOT/call_load/" + [ "${lines[0]}" = "1..1" ] + [ "${lines[1]}" = "ok 1 passing" ] + [ "${#lines[@]}" -eq 2 ] } @test "output frorm setup_suite is only visible on failure" { - reentrant_run -0 bats "$FIXTURE_ROOT/default_name/" - [ "${lines[0]}" = "1..1" ] - [ "${lines[1]}" = "ok 1 passing" ] - [ "${#lines[@]}" -eq 2 ] - - - reentrant_run -1 bats "$FIXTURE_ROOT/output_with_failure/" - [ "${lines[0]}" = "1..1" ] - [ "${lines[1]}" = "not ok 1 setup_suite" ] - [ "${lines[2]}" = "# (from function \`setup_suite' in test file $RELATIVE_FIXTURE_ROOT/output_with_failure/setup_suite.bash, line 3)" ] - [ "${lines[3]}" = "# \`false' failed" ] - [ "${lines[4]}" = "# setup_suite" ] - [ "${lines[5]}" = "# teardown_suite" ] - [ "${#lines[@]}" -eq 6 ] -} \ No newline at end of file + reentrant_run -0 bats "$FIXTURE_ROOT/default_name/" + [ "${lines[0]}" = "1..1" ] + [ "${lines[1]}" = "ok 1 passing" ] + [ "${#lines[@]}" -eq 2 ] + + reentrant_run -1 bats "$FIXTURE_ROOT/output_with_failure/" + [ "${lines[0]}" = "1..1" ] + [ "${lines[1]}" = "not ok 1 setup_suite" ] + [ "${lines[2]}" = "# (from function \`setup_suite' in test file $RELATIVE_FIXTURE_ROOT/output_with_failure/setup_suite.bash, line 3)" ] + [ "${lines[3]}" = "# \`false' failed" ] + [ "${lines[4]}" = "# setup_suite" ] + [ "${lines[5]}" = "# teardown_suite" ] + [ "${#lines[@]}" -eq 6 ] +} diff --git a/test/tagging.bats b/test/tagging.bats index f634c0ba4c..b8f027e1a3 100644 --- a/test/tagging.bats +++ b/test/tagging.bats @@ -3,73 +3,73 @@ bats_require_minimum_version 1.5.0 setup() { - load test_helper - fixtures tagging + load test_helper + fixtures tagging } @test "No tag filter runs all tests" { - run -0 bats "$FIXTURE_ROOT/tagged.bats" - [ "${lines[0]}" == "1..5" ] - [ "${lines[1]}" == "ok 1 No tags" ] - [ "${lines[2]}" == "ok 2 Only file tags" ] - [ "${lines[3]}" == "ok 3 File and test tags" ] - [ "${lines[4]}" == "ok 4 File and other test tags" ] - [ "${lines[5]}" == "ok 5 Only test tags" ] - [ ${#lines[@]} -eq 6 ] + run -0 bats "$FIXTURE_ROOT/tagged.bats" + [ "${lines[0]}" == "1..5" ] + [ "${lines[1]}" == "ok 1 No tags" ] + [ "${lines[2]}" == "ok 2 Only file tags" ] + [ "${lines[3]}" == "ok 3 File and test tags" ] + [ "${lines[4]}" == "ok 4 File and other test tags" ] + [ "${lines[5]}" == "ok 5 Only test tags" ] + [ ${#lines[@]} -eq 6 ] } @test "Empty tag filter runs tests without tag" { - run -0 bats --filter-tags '' "$FIXTURE_ROOT/tagged.bats" - [ "${lines[0]}" == "1..1" ] - [ "${lines[1]}" == "ok 1 No tags" ] - [ ${#lines[@]} -eq 2 ] + run -0 bats --filter-tags '' "$FIXTURE_ROOT/tagged.bats" + [ "${lines[0]}" == "1..1" ] + [ "${lines[1]}" == "ok 1 No tags" ] + [ ${#lines[@]} -eq 2 ] } @test "--filter-tags (also) selects tests that contain additional tags" { - run -0 bats --filter-tags 'file:tag:1' "$FIXTURE_ROOT/tagged.bats" - [ "${lines[0]}" == "1..3" ] - [ "${lines[1]}" == "ok 1 Only file tags" ] - [ "${lines[2]}" == "ok 2 File and test tags" ] - [ "${lines[3]}" == "ok 3 File and other test tags" ] - [ ${#lines[@]} -eq 4 ] + run -0 bats --filter-tags 'file:tag:1' "$FIXTURE_ROOT/tagged.bats" + [ "${lines[0]}" == "1..3" ] + [ "${lines[1]}" == "ok 1 Only file tags" ] + [ "${lines[2]}" == "ok 2 File and test tags" ] + [ "${lines[3]}" == "ok 3 File and other test tags" ] + [ ${#lines[@]} -eq 4 ] } @test "--filter-tags only selects tests that match all tags (logic and)" { - run -0 bats --filter-tags 'test:tag:1,file:tag:1' "$FIXTURE_ROOT/tagged.bats" - [ "${lines[0]}" == "1..1" ] - [ "${lines[1]}" == "ok 1 File and test tags" ] - [ ${#lines[@]} -eq 2 ] + run -0 bats --filter-tags 'test:tag:1,file:tag:1' "$FIXTURE_ROOT/tagged.bats" + [ "${lines[0]}" == "1..1" ] + [ "${lines[1]}" == "ok 1 File and test tags" ] + [ ${#lines[@]} -eq 2 ] } @test "multiple --filter-tags work as logical or" { - run -0 bats --filter-tags 'test:tag:1,file:tag:1' --filter-tags 'test:tag:2,file:tag:1' "$FIXTURE_ROOT/tagged.bats" - [ "${lines[0]}" == "1..2" ] - [ "${lines[1]}" == "ok 1 File and test tags" ] - [ "${lines[2]}" == "ok 2 File and other test tags" ] - [ ${#lines[@]} -eq 3 ] + run -0 bats --filter-tags 'test:tag:1,file:tag:1' --filter-tags 'test:tag:2,file:tag:1' "$FIXTURE_ROOT/tagged.bats" + [ "${lines[0]}" == "1..2" ] + [ "${lines[1]}" == "ok 1 File and test tags" ] + [ "${lines[2]}" == "ok 2 File and other test tags" ] + [ ${#lines[@]} -eq 3 ] } @test "--filter-tags order of tags does not matter" { - # note the reversed order in comparison to test above - run -0 bats --filter-tags 'file:tag:1,test:tag:1' "$FIXTURE_ROOT/tagged.bats" - [ "${lines[0]}" == "1..1" ] - [ "${lines[1]}" == "ok 1 File and test tags" ] - [ ${#lines[@]} -eq 2 ] + # note the reversed order in comparison to test above + run -0 bats --filter-tags 'file:tag:1,test:tag:1' "$FIXTURE_ROOT/tagged.bats" + [ "${lines[0]}" == "1..1" ] + [ "${lines[1]}" == "ok 1 File and test tags" ] + [ ${#lines[@]} -eq 2 ] } @test "exit with error on invalid tags in .bats file" { - run -1 bats "$FIXTURE_ROOT/invalid_tags.bats" - [ "${lines[0]}" = "1..1" ] - [ "${lines[1]}" = "$FIXTURE_ROOT/invalid_tags.bats:1: Error: Invalid file_tags: ',bc'. Tags must not be empty. Please remove redundant commas!" ] - [ "${lines[2]}" = "$FIXTURE_ROOT/invalid_tags.bats:2: Error: Invalid file_tags: 'a+b'. Valid tags must match [-_:[:alnum:]]+ and be separated with comma (and optional spaces)" ] - [ "${lines[3]}" = "$FIXTURE_ROOT/invalid_tags.bats:4: Error: Invalid test_tags: ',bc'. Tags must not be empty. Please remove redundant commas!" ] - [ "${lines[4]}" = "$FIXTURE_ROOT/invalid_tags.bats:5: Error: Invalid test_tags: 'a+b'. Valid tags must match [-_:[:alnum:]]+ and be separated with comma (and optional spaces)" ] + run -1 bats "$FIXTURE_ROOT/invalid_tags.bats" + [ "${lines[0]}" = "1..1" ] + [ "${lines[1]}" = "$FIXTURE_ROOT/invalid_tags.bats:1: Error: Invalid file_tags: ',bc'. Tags must not be empty. Please remove redundant commas!" ] + [ "${lines[2]}" = "$FIXTURE_ROOT/invalid_tags.bats:2: Error: Invalid file_tags: 'a+b'. Valid tags must match [-_:[:alnum:]]+ and be separated with comma (and optional spaces)" ] + [ "${lines[3]}" = "$FIXTURE_ROOT/invalid_tags.bats:4: Error: Invalid test_tags: ',bc'. Tags must not be empty. Please remove redundant commas!" ] + [ "${lines[4]}" = "$FIXTURE_ROOT/invalid_tags.bats:5: Error: Invalid test_tags: 'a+b'. Valid tags must match [-_:[:alnum:]]+ and be separated with comma (and optional spaces)" ] } @test "--filter-tags allows for negation via !" { - run -0 bats --filter-tags '!file:tag:1' "$FIXTURE_ROOT/tagged.bats" - [ "${lines[0]}" = '1..2' ] - [ "${lines[1]}" = 'ok 1 No tags' ] - [ "${lines[2]}" = 'ok 2 Only test tags' ] - [ "${#lines[@]}" -eq 3 ] + run -0 bats --filter-tags '!file:tag:1' "$FIXTURE_ROOT/tagged.bats" + [ "${lines[0]}" = '1..2' ] + [ "${lines[1]}" = 'ok 1 No tags' ] + [ "${lines[2]}" = 'ok 2 Only test tags' ] + [ "${#lines[@]}" -eq 3 ] } diff --git a/test/tap13-formatter.bats b/test/tap13-formatter.bats index 0d77deac1b..075c8a8fc9 100644 --- a/test/tap13-formatter.bats +++ b/test/tap13-formatter.bats @@ -2,52 +2,52 @@ load 'test_helper' fixtures bats # reuse bats fixtures @test "passing test" { - reentrant_run bats --formatter tap13 "${FIXTURE_ROOT}/passing.bats" - - [ "${lines[0]}" == 'TAP version 13' ] - [ "${lines[1]}" == '1..1' ] - [ "${lines[2]}" == 'ok 1 a passing test' ] - [ "${#lines[@]}" -eq 3 ] + reentrant_run bats --formatter tap13 "${FIXTURE_ROOT}/passing.bats" + + [ "${lines[0]}" == 'TAP version 13' ] + [ "${lines[1]}" == '1..1' ] + [ "${lines[2]}" == 'ok 1 a passing test' ] + [ "${#lines[@]}" -eq 3 ] } @test "failing test" { - reentrant_run bats --formatter tap13 "${FIXTURE_ROOT}/failing.bats" - - [ "${lines[0]}" == 'TAP version 13' ] - [ "${lines[1]}" == '1..1' ] - [ "${lines[2]}" == 'not ok 1 a failing test' ] - [ "${lines[3]}" == ' ---' ] - [ "${lines[4]}" == ' message: |' ] - [ "${lines[5]}" == " (in test file ${RELATIVE_FIXTURE_ROOT}/failing.bats, line 4)" ] - [ "${lines[6]}" == " \`eval \"( exit \${STATUS:-1} )\"' failed" ] - [ "${lines[7]}" == ' ...' ] - [ "${#lines[@]}" -eq 8 ] + reentrant_run bats --formatter tap13 "${FIXTURE_ROOT}/failing.bats" + + [ "${lines[0]}" == 'TAP version 13' ] + [ "${lines[1]}" == '1..1' ] + [ "${lines[2]}" == 'not ok 1 a failing test' ] + [ "${lines[3]}" == ' ---' ] + [ "${lines[4]}" == ' message: |' ] + [ "${lines[5]}" == " (in test file ${RELATIVE_FIXTURE_ROOT}/failing.bats, line 4)" ] + [ "${lines[6]}" == " \`eval \"( exit \${STATUS:-1} )\"' failed" ] + [ "${lines[7]}" == ' ...' ] + [ "${#lines[@]}" -eq 8 ] } @test "passing test with timing" { - reentrant_run bats --formatter tap13 --timing "${FIXTURE_ROOT}/passing.bats" - - [ "${lines[0]}" == 'TAP version 13' ] - [ "${lines[1]}" == '1..1' ] - [ "${lines[2]}" == 'ok 1 a passing test' ] - [ "${lines[3]}" == ' ---' ] - [ "${lines[4]::15}" == ' duration_ms: ' ] - [ "${lines[5]}" == ' ...' ] - - [ "${#lines[@]}" -eq 6 ] + reentrant_run bats --formatter tap13 --timing "${FIXTURE_ROOT}/passing.bats" + + [ "${lines[0]}" == 'TAP version 13' ] + [ "${lines[1]}" == '1..1' ] + [ "${lines[2]}" == 'ok 1 a passing test' ] + [ "${lines[3]}" == ' ---' ] + [ "${lines[4]::15}" == ' duration_ms: ' ] + [ "${lines[5]}" == ' ...' ] + + [ "${#lines[@]}" -eq 6 ] } @test "failing test with timing" { - reentrant_run bats --formatter tap13 --timing "${FIXTURE_ROOT}/failing.bats" - - [ "${lines[0]}" == 'TAP version 13' ] - [ "${lines[1]}" == '1..1' ] - [ "${lines[2]}" == 'not ok 1 a failing test' ] - [ "${lines[3]}" == ' ---' ] - [ "${lines[4]::15}" == ' duration_ms: ' ] - [ "${lines[5]}" == ' message: |' ] - [ "${lines[6]}" == " (in test file ${RELATIVE_FIXTURE_ROOT}/failing.bats, line 4)" ] - [ "${lines[7]}" == " \`eval \"( exit \${STATUS:-1} )\"' failed" ] - [ "${lines[8]}" == ' ...' ] - [ "${#lines[@]}" -eq 9 ] -} \ No newline at end of file + reentrant_run bats --formatter tap13 --timing "${FIXTURE_ROOT}/failing.bats" + + [ "${lines[0]}" == 'TAP version 13' ] + [ "${lines[1]}" == '1..1' ] + [ "${lines[2]}" == 'not ok 1 a failing test' ] + [ "${lines[3]}" == ' ---' ] + [ "${lines[4]::15}" == ' duration_ms: ' ] + [ "${lines[5]}" == ' message: |' ] + [ "${lines[6]}" == " (in test file ${RELATIVE_FIXTURE_ROOT}/failing.bats, line 4)" ] + [ "${lines[7]}" == " \`eval \"( exit \${STATUS:-1} )\"' failed" ] + [ "${lines[8]}" == ' ...' ] + [ "${#lines[@]}" -eq 9 ] +} diff --git a/test/test_helper.bash b/test/test_helper.bash index ec322b9d56..4b46ad3a69 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -66,4 +66,4 @@ reentrant_run() { # pre_command_args+=(execute_with_unset_bats_vars) run "${pre_command_args[@]}" "$@" -} \ No newline at end of file +} diff --git a/test/timeout.bats b/test/timeout.bats index f283828a2c..1932c21e4c 100644 --- a/test/timeout.bats +++ b/test/timeout.bats @@ -4,22 +4,22 @@ fixtures timeout bats_require_minimum_version 1.5.0 @test "test faster than timeout" { - SECONDS=0 - TIMEOUT=10 - reentrant_run -0 env BATS_TEST_TIMEOUT=$TIMEOUT SLEEP=1 bats -T "$FIXTURE_ROOT" - [ "${lines[0]}" == '1..1' ] - [[ "${lines[1]}" == 'ok 1 my sleep 1 in '*'ms' ]] || false - [ "${#lines[@]}" -eq 2 ] - # the timeout background process should not hold up execution - (( SECONDS < TIMEOUT )) || false + SECONDS=0 + TIMEOUT=10 + reentrant_run -0 env BATS_TEST_TIMEOUT=$TIMEOUT SLEEP=1 bats -T "$FIXTURE_ROOT" + [ "${lines[0]}" == '1..1' ] + [[ "${lines[1]}" == 'ok 1 my sleep 1 in '*'ms' ]] || false + [ "${#lines[@]}" -eq 2 ] + # the timeout background process should not hold up execution + ((SECONDS < TIMEOUT)) || false } @test "test longer than timeout" { - SECONDS=0 - reentrant_run ! env BATS_TEST_TIMEOUT=1 SLEEP=10 bats -T "$FIXTURE_ROOT" - [ "${lines[0]}" == '1..1' ] - [[ "${lines[1]}" == 'not ok 1 my sleep 10 in '*'ms # timeout after 1s' ]] || false - [ "${lines[2]}" == "# (in test file $RELATIVE_FIXTURE_ROOT/sleep2.bats, line 3)" ] - [ "${lines[3]}" == "# \`sleep \"\${SLEEP?}\"' failed due to timeout" ] - (( SECONDS < 10 )) || false -} \ No newline at end of file + SECONDS=0 + reentrant_run ! env BATS_TEST_TIMEOUT=1 SLEEP=10 bats -T "$FIXTURE_ROOT" + [ "${lines[0]}" == '1..1' ] + [[ "${lines[1]}" == 'not ok 1 my sleep 10 in '*'ms # timeout after 1s' ]] || false + [ "${lines[2]}" == "# (in test file $RELATIVE_FIXTURE_ROOT/sleep2.bats, line 2)" ] + [ "${lines[3]}" == "# \`sleep \"\${SLEEP?}\"' failed due to timeout" ] + ((SECONDS < 10)) || false +} diff --git a/test/trace.bats b/test/trace.bats index b82e93ec9c..b32a5e5933 100644 --- a/test/trace.bats +++ b/test/trace.bats @@ -1,8 +1,8 @@ #!/usr/bin/env bats bats_require_minimum_version 1.5.0 setup() { - load test_helper - fixtures trace + load test_helper + fixtures trace } @test "no --trace doesn't show anything on failure" { @@ -16,69 +16,69 @@ setup() { } @test "--trace recurses into functions but not into run" { - reentrant_run -1 bats --trace "$FIXTURE_ROOT/failing_recursive.bats" - - [ "${lines[0]}" = '1..1' ] - [ "${lines[1]}" = 'not ok 1 a recursive failing test' ] - [ "${lines[2]}" = "# (in test file $RELATIVE_FIXTURE_ROOT/failing_recursive.bats, line 12)" ] - [ "${lines[3]}" = "# \`false' failed" ] - [ "${lines[4]}" = '# $ [failing_recursive.bats:9]' ] - [ "${lines[5]}" = '# $ echo Outer' ] - [ "${lines[6]}" = '# Outer' ] - [ "${lines[7]}" = '# $ fun 2' ] - [ "${lines[8]}" = '# $$ [failing_recursive.bats:2]' ] - # shellcheck disable=SC2016 - [ "${lines[9]}" = '# $$ echo "$1"' ] - [ "${lines[10]}" = '# 2' ] - # shellcheck disable=SC2016 - [ "${lines[11]}" = '# $$ [[ $1 -gt 0 ]]' ] - # shellcheck disable=SC2016 - [ "${lines[12]}" = '# $$ fun $(($1 - 1))' ] - [ "${lines[13]}" = '# $$$ [failing_recursive.bats:2]' ] - # shellcheck disable=SC2016 - [ "${lines[14]}" = '# $$$ echo "$1"' ] - [ "${lines[15]}" = '# 1' ] - # shellcheck disable=SC2016 - [ "${lines[16]}" = '# $$$ [[ $1 -gt 0 ]]' ] - # shellcheck disable=SC2016 - [ "${lines[17]}" = '# $$$ fun $(($1 - 1))' ] - [ "${lines[18]}" = '# $$$$ [failing_recursive.bats:2]' ] - # shellcheck disable=SC2016 - [ "${lines[19]}" = '# $$$$ echo "$1"' ] - [ "${lines[20]}" = '# 0' ] - # shellcheck disable=SC2016 - [ "${lines[21]}" = '# $$$$ [[ $1 -gt 0 ]]' ] - [ "${lines[22]}" = '# $ [failing_recursive.bats:11]' ] - [ "${lines[23]}" = '# $ run fun 2' ] - [ "${lines[24]}" = '# $ false' ] + reentrant_run -1 bats --trace "$FIXTURE_ROOT/failing_recursive.bats" - # the trace on return from a function differs between bash versions - check_bash_5() { - [ ${#lines[@]} -eq 25 ] - } + [ "${lines[0]}" = '1..1' ] + [ "${lines[1]}" = 'not ok 1 a recursive failing test' ] + [ "${lines[2]}" = "# (in test file $RELATIVE_FIXTURE_ROOT/failing_recursive.bats, line 12)" ] + [ "${lines[3]}" = "# \`false' failed" ] + [ "${lines[4]}" = '# $ [failing_recursive.bats:9]' ] + [ "${lines[5]}" = '# $ echo Outer' ] + [ "${lines[6]}" = '# Outer' ] + [ "${lines[7]}" = '# $ fun 2' ] + [ "${lines[8]}" = '# $$ [failing_recursive.bats:2]' ] + # shellcheck disable=SC2016 + [ "${lines[9]}" = '# $$ echo "$1"' ] + [ "${lines[10]}" = '# 2' ] + # shellcheck disable=SC2016 + [ "${lines[11]}" = '# $$ [[ $1 -gt 0 ]]' ] + # shellcheck disable=SC2016 + [ "${lines[12]}" = '# $$ fun $(($1 - 1))' ] + [ "${lines[13]}" = '# $$$ [failing_recursive.bats:2]' ] + # shellcheck disable=SC2016 + [ "${lines[14]}" = '# $$$ echo "$1"' ] + [ "${lines[15]}" = '# 1' ] + # shellcheck disable=SC2016 + [ "${lines[16]}" = '# $$$ [[ $1 -gt 0 ]]' ] + # shellcheck disable=SC2016 + [ "${lines[17]}" = '# $$$ fun $(($1 - 1))' ] + [ "${lines[18]}" = '# $$$$ [failing_recursive.bats:2]' ] + # shellcheck disable=SC2016 + [ "${lines[19]}" = '# $$$$ echo "$1"' ] + [ "${lines[20]}" = '# 0' ] + # shellcheck disable=SC2016 + [ "${lines[21]}" = '# $$$$ [[ $1 -gt 0 ]]' ] + [ "${lines[22]}" = '# $ [failing_recursive.bats:11]' ] + [ "${lines[23]}" = '# $ run fun 2' ] + [ "${lines[24]}" = '# $ false' ] - # "alias" same behavior to have single point of truth - check_bash_4_4() { check_bash_5; } - check_bash_4_3() { check_bash_5; } - check_bash_4_2() { check_bash_4_0; } - check_bash_4_1() { check_bash_4_0; } + # the trace on return from a function differs between bash versions + check_bash_5() { + [ ${#lines[@]} -eq 25 ] + } - check_bash_4_0() { - # bash bug: the lineno from the debug_trap spills over -> ignore it - [ "${lines[25]}" = '# $ false' ] - [ ${#lines[@]} -eq 26 ] - } + # "alias" same behavior to have single point of truth + check_bash_4_4() { check_bash_5; } + check_bash_4_3() { check_bash_5; } + check_bash_4_2() { check_bash_4_0; } + check_bash_4_1() { check_bash_4_0; } - check_bash_3_2() { - # lineno from function definition - [ "${lines[25]}" = '# $ false' ] - [ ${#lines[@]} -eq 26 ] - } + check_bash_4_0() { + # bash bug: the lineno from the debug_trap spills over -> ignore it + [ "${lines[25]}" = '# $ false' ] + [ ${#lines[@]} -eq 26 ] + } - IFS=. read -r -a bash_version <<< "${BASH_VERSION}" - check_func="check_bash_${bash_version[0]}" - if [[ $(type -t "$check_func") != function ]]; then - check_func="check_bash_${bash_version[0]}_${bash_version[1]}" - fi - $check_func -} \ No newline at end of file + check_bash_3_2() { + # lineno from function definition + [ "${lines[25]}" = '# $ false' ] + [ ${#lines[@]} -eq 26 ] + } + + IFS=. read -r -a bash_version <<<"${BASH_VERSION}" + check_func="check_bash_${bash_version[0]}" + if [[ $(type -t "$check_func") != function ]]; then + check_func="check_bash_${bash_version[0]}_${bash_version[1]}" + fi + $check_func +} diff --git a/test/warnings.bats b/test/warnings.bats index dbb88c095f..ef94e7618d 100644 --- a/test/warnings.bats +++ b/test/warnings.bats @@ -3,79 +3,79 @@ bats_require_minimum_version 1.5.0 setup() { - load test_helper - fixtures warnings - if [[ $BATS_ROOT == "$BATS_CWD" ]]; then - RELATIVE_BATS_ROOT='' - else - RELATIVE_BATS_ROOT=${BATS_ROOT#"$BATS_CWD"/} - fi - if [[ -n "$RELATIVE_BATS_ROOT" && "$RELATIVE_BATS_ROOT" != */ ]]; then - RELATIVE_BATS_ROOT+=/ - fi - echo "RELATIVE_BATS_ROOT=$RELATIVE_BATS_ROOT" "BATS_ROOT=$BATS_ROOT" "BATS_CWD=$BATS_CWD" + load test_helper + fixtures warnings + if [[ $BATS_ROOT == "$BATS_CWD" ]]; then + RELATIVE_BATS_ROOT='' + else + RELATIVE_BATS_ROOT=${BATS_ROOT#"$BATS_CWD"/} + fi + if [[ -n "$RELATIVE_BATS_ROOT" && "$RELATIVE_BATS_ROOT" != */ ]]; then + RELATIVE_BATS_ROOT+=/ + fi + echo "RELATIVE_BATS_ROOT=$RELATIVE_BATS_ROOT" "BATS_ROOT=$BATS_ROOT" "BATS_CWD=$BATS_CWD" } @test "invalid warning is an error" { - REENTRANT_RUN_PRESERVE+=(BATS_WARNING_SHORT_DESCS) - reentrant_run -1 bats_generate_warning invalid-number - [[ "$output" == "Invalid Bats warning number 'invalid-number'. It must be an integer between 1 and "* ]] + REENTRANT_RUN_PRESERVE+=(BATS_WARNING_SHORT_DESCS) + reentrant_run -1 bats_generate_warning invalid-number + [[ "$output" == "Invalid Bats warning number 'invalid-number'. It must be an integer between 1 and "* ]] } @test "BW01 is printed when \`run\`ing a (non-existant) command with exit code 127 without exit code check" { - reentrant_run -0 bats "$FIXTURE_ROOT/BW01.bats" - [ "${lines[0]}" == "1..1" ] - [ "${lines[1]}" == "ok 1 Trigger BW01" ] - [ "${lines[2]}" == "The following warnings were encountered during tests:" ] - [ "${lines[3]}" == "BW01: \`run\`'s command \`=0 actually-intended-command with some args\` exited with code 127, indicating 'Command not found'. Use run's return code checks, e.g. \`run -127\`, to fix this message." ] - [[ "${lines[4]}" == " (from function \`run' in file ${RELATIVE_BATS_ROOT}lib/bats-core/test_functions.bash, line"* ]] - [ "${lines[5]}" == " in test file $RELATIVE_FIXTURE_ROOT/BW01.bats, line 3)" ] + reentrant_run -0 bats "$FIXTURE_ROOT/BW01.bats" + [ "${lines[0]}" == "1..1" ] + [ "${lines[1]}" == "ok 1 Trigger BW01" ] + [ "${lines[2]}" == "The following warnings were encountered during tests:" ] + [ "${lines[3]}" == "BW01: \`run\`'s command \`=0 actually-intended-command with some args\` exited with code 127, indicating 'Command not found'. Use run's return code checks, e.g. \`run -127\`, to fix this message." ] + [[ "${lines[4]}" == " (from function \`run' in file ${RELATIVE_BATS_ROOT}lib/bats-core/test_functions.bash, line"* ]] + [ "${lines[5]}" == " in test file $RELATIVE_FIXTURE_ROOT/BW01.bats, line 3)" ] } @test "BW01 is not printed when \`run\`ing a (non-existant) command with exit code 127 with exit code check" { - reentrant_run -0 bats "$FIXTURE_ROOT/BW01_check_exit_code_is_127.bats" - [ "${lines[0]}" == "1..1" ] - [ "${lines[1]}" == "ok 1 Don't trigger BW01 with checked exit code 127" ] - [ "${#lines[@]}" -eq 2 ] + reentrant_run -0 bats "$FIXTURE_ROOT/BW01_check_exit_code_is_127.bats" + [ "${lines[0]}" == "1..1" ] + [ "${lines[1]}" == "ok 1 Don't trigger BW01 with checked exit code 127" ] + [ "${#lines[@]}" -eq 2 ] } @test "BW01 is not printed when \`run\`ing a command with exit code !=127 without exit code check" { - reentrant_run -0 bats "$FIXTURE_ROOT/BW01_no_exit_code_check_no_exit_code_127.bats" - [ "${lines[0]}" == "1..1" ] - [ "${lines[1]}" == "ok 1 Don't trigger BW01 with exit code !=127 and no check" ] - [ "${#lines[@]}" -eq 2 ] + reentrant_run -0 bats "$FIXTURE_ROOT/BW01_no_exit_code_check_no_exit_code_127.bats" + [ "${lines[0]}" == "1..1" ] + [ "${lines[1]}" == "ok 1 Don't trigger BW01 with exit code !=127 and no check" ] + [ "${#lines[@]}" -eq 2 ] } @test "BW02 is printed when run uses parameters without guaranteed version >= 1.5.0" { - reentrant_run -0 bats "$FIXTURE_ROOT/BW02.bats" - [ "${lines[0]}" == "1..1" ] - [ "${lines[1]}" == "ok 1 Trigger BW02" ] - [ "${lines[2]}" == "The following warnings were encountered during tests:" ] - [ "${lines[3]}" == "BW02: Using flags on \`run\` requires at least BATS_VERSION=1.5.0. Use \`bats_require_minimum_version 1.5.0\` to fix this message." ] - [[ "${lines[4]}" == " (from function \`bats_warn_minimum_guaranteed_version' in file ${RELATIVE_BATS_ROOT}lib/bats-core/warnings.bash, line "* ]] - [[ "${lines[5]}" == " from function \`run' in file ${RELATIVE_BATS_ROOT}lib/bats-core/test_functions.bash, line"* ]] - [ "${lines[6]}" == " in test file $RELATIVE_FIXTURE_ROOT/BW02.bats, line 2)" ] + reentrant_run -0 bats "$FIXTURE_ROOT/BW02.bats" + [ "${lines[0]}" == "1..1" ] + [ "${lines[1]}" == "ok 1 Trigger BW02" ] + [ "${lines[2]}" == "The following warnings were encountered during tests:" ] + [ "${lines[3]}" == "BW02: Using flags on \`run\` requires at least BATS_VERSION=1.5.0. Use \`bats_require_minimum_version 1.5.0\` to fix this message." ] + [[ "${lines[4]}" == " (from function \`bats_warn_minimum_guaranteed_version' in file ${RELATIVE_BATS_ROOT}lib/bats-core/warnings.bash, line "* ]] + [[ "${lines[5]}" == " from function \`run' in file ${RELATIVE_BATS_ROOT}lib/bats-core/test_functions.bash, line"* ]] + [ "${lines[6]}" == " in test file $RELATIVE_FIXTURE_ROOT/BW02.bats, line 2)" ] } @test "BW03 is printed when a test file defines setup_suite and setup_suite is not defined" { - reentrant_run -0 bats "$FIXTURE_ROOT/BW03/define_setup_suite_in_wrong_file.bats" - [ "${lines[0]}" == "1..1" ] - [ "${lines[1]}" == "ok 1 test" ] - [ "${lines[2]}" == "The following warnings were encountered during tests:" ] - [ "${lines[3]}" == "BW03: \`setup_suite\` is visible to test file '${FIXTURE_ROOT}/BW03/define_setup_suite_in_wrong_file.bats', but was not executed. It belongs into 'setup_suite.bash' to be picked up automatically." ] - [ "${#lines[@]}" -eq 4 ] + reentrant_run -0 bats "$FIXTURE_ROOT/BW03/define_setup_suite_in_wrong_file.bats" + [ "${lines[0]}" == "1..1" ] + [ "${lines[1]}" == "ok 1 test" ] + [ "${lines[2]}" == "The following warnings were encountered during tests:" ] + [ "${lines[3]}" == "BW03: \`setup_suite\` is visible to test file '${FIXTURE_ROOT}/BW03/define_setup_suite_in_wrong_file.bats', but was not executed. It belongs into 'setup_suite.bash' to be picked up automatically." ] + [ "${#lines[@]}" -eq 4 ] } @test "BW03 is not printed when a test file defines setup_suite but setup_suite was completed" { - reentrant_run -0 bats "$FIXTURE_ROOT/BW03/define_setup_suite_in_wrong_file.bats" --setup-suite-file "$FIXTURE_ROOT/BW03/non_default_setup_suite.bash" - [ "${lines[0]}" == "1..1" ] - [ "${lines[1]}" == "ok 1 test" ] - [ "${#lines[@]}" -eq 2 ] + reentrant_run -0 bats "$FIXTURE_ROOT/BW03/define_setup_suite_in_wrong_file.bats" --setup-suite-file "$FIXTURE_ROOT/BW03/non_default_setup_suite.bash" + [ "${lines[0]}" == "1..1" ] + [ "${lines[1]}" == "ok 1 test" ] + [ "${#lines[@]}" -eq 2 ] } @test "BW03 can be suppressed by setting BATS_SETUP_SUITE_COMPLETED" { - reentrant_run -0 bats "$FIXTURE_ROOT/BW03/suppress_warning.bats" - [ "${lines[0]}" == "1..1" ] - [ "${lines[1]}" == "ok 1 test" ] - [ "${#lines[@]}" -eq 2 ] -} \ No newline at end of file + reentrant_run -0 bats "$FIXTURE_ROOT/BW03/suppress_warning.bats" + [ "${lines[0]}" == "1..1" ] + [ "${lines[1]}" == "ok 1 test" ] + [ "${#lines[@]}" -eq 2 ] +} From 32f088a93bd4e26f824875ab4baea9adc4059628 Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Sun, 18 Sep 2022 08:59:20 +0200 Subject: [PATCH 3/6] Exclude files that don't work with shellcheck --- .editorconfig | 3 +++ test/fixtures/bats/single_line_no_shellcheck.bats | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.editorconfig b/.editorconfig index f8e831d647..457107ead5 100644 --- a/.editorconfig +++ b/.editorconfig @@ -30,3 +30,6 @@ tab_width = 4 # trailing spaces indicates word wrap trim_trailing_spaces = false trim_trailing_whitespace = false + +[test/fixtures/bats/*_no_shellcheck.bats] +ignore = true \ No newline at end of file diff --git a/test/fixtures/bats/single_line_no_shellcheck.bats b/test/fixtures/bats/single_line_no_shellcheck.bats index ea8df787dd..060d77224f 100644 --- a/test/fixtures/bats/single_line_no_shellcheck.bats +++ b/test/fixtures/bats/single_line_no_shellcheck.bats @@ -1,4 +1,4 @@ -@test "empty" {; } +@test "empty" { } @test "passing" { true; } From 60b4c4f1e686209a3222ea5259b0e799362209ee Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Sun, 18 Sep 2022 09:01:23 +0200 Subject: [PATCH 4/6] CI: Enforce shfmt format --- .github/workflows/tests.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 45bba18d8c..93dc609c6a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -14,6 +14,13 @@ jobs: grep "#${{github.event.pull_request.number}}" docs/CHANGELOG.md fi if: ${{github.event.pull_request}} + + shfmt: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + - run: shfmt --diff . + shellcheck: runs-on: ubuntu-20.04 steps: From c5816925e9a81fd804e503e6ab0fba6e79002f16 Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Sun, 18 Sep 2022 12:59:54 +0200 Subject: [PATCH 5/6] Download current shfmt --- .github/workflows/tests.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 93dc609c6a..0a6471685a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -19,7 +19,10 @@ jobs: runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - - run: shfmt --diff . + - run: | + curl https://github.com/mvdan/sh/releases/download/v3.5.1/shfmt_v3.5.1_linux_amd64 -o shfmt + chmod a+x shfmt + - run: ./shfmt --diff . shellcheck: runs-on: ubuntu-20.04 From def9ee0228fc3ad08b61ec5f7789c2f4267d66d3 Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Sun, 18 Sep 2022 13:01:36 +0200 Subject: [PATCH 6/6] Add changelog entry for #651 --- docs/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 3f4f074a86..a349419305 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -10,6 +10,10 @@ The format is based on [Keep a Changelog][kac] and this project adheres to ## [Unreleased] +### Fixed + +* `shfmt` all files and enforce via CI (#651) + ## [1.8.0] - 2022-09-15 ### Added