From 10b0daf53a888044b3f7b9de3581d58fe436ec9f Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Tue, 13 Aug 2019 21:50:10 +0200 Subject: [PATCH] feat: add setup_file and teardown_file note: most of this was merged under https://github.com/bats-core/bats-core/pull/246 - Avoid messing with internal variable BATS_ROOT - Don't let teardown errors stop exit output - add helpers in lib/bats-core and add to install - Move parallelization into exec-file but parallelize across files - allow for preserving environment when running in parallel - Unify output into bats run specific tmp dir - Validate the test count in bin/bats: This tests what is actually written and not what we wanted to run. The latter is even more problematic in the parallel test cases, as we can't easily retrieve the count from the subshells. - add devcontainer for simplified development in VS Code containers - Cleanup for shellcheck - Cleanup BATS_RUN_TMPDIR after run: this should avoid colissions between successive runs Error when the run dir is reused --- Dockerfile | 2 +- README.md | 2 +- libexec/bats-core/bats | 16 ++++++++-------- shellcheck.sh | 2 ++ test/parallell.bats | 9 +++++---- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/Dockerfile b/Dockerfile index e3aa928e..35b89922 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ FROM bash:${bashver} # Install parallel and accept the citation notice (we aren't using this in a # context where it make sense to cite GNU Parallel). -RUN apk add --no-cache parallel && \ +RUN apk add --no-cache parallel ncurses && \ mkdir -p ~/.parallel && touch ~/.parallel/will-cite RUN ln -s /opt/bats/bin/bats /usr/sbin/bats diff --git a/README.md b/README.md index acf51332..1741715e 100644 --- a/README.md +++ b/README.md @@ -572,7 +572,7 @@ There was an initial [call for maintainers][call-maintain] for the original Bats ## Copyright -© 2017-2018 bats-core organization +© 2017-2020 bats-core organization © 2011-2016 Sam Stephenson diff --git a/libexec/bats-core/bats b/libexec/bats-core/bats index 1716f46f..8817591f 100755 --- a/libexec/bats-core/bats +++ b/libexec/bats-core/bats @@ -224,6 +224,14 @@ if [[ "${#arguments[@]}" -eq 0 ]]; then abort 'Must specify at least one ' fi + +if [[ -n "$output" ]]; then + if [[ ! -w "${output}" ]]; then + abort "Output path ${output} is not writeable" + fi + export BATS_REPORT_OUTPUT_PATH="$output" +fi + filenames=() for filename in "${arguments[@]}"; do expand_path "$filename" 'filename' @@ -248,13 +256,5 @@ done # shellcheck source=lib/bats-core/validator.bash source "$BATS_ROOT/lib/bats-core/validator.bash" -if [[ -n "$output" ]]; then - if [[ ! -w "${output}" ]]; then - printf "Error: output path %s is not writeable\n" "${output}" >&2 - exit 1 - fi - export BATS_REPORT_OUTPUT_PATH="$output" -fi - set -o pipefail execfail exec bats-exec-suite "${flags[@]}" "${filenames[@]}" | bats_test_count_validator | "bats-format-${formatter}" "${formatter_flags[@]}" diff --git a/shellcheck.sh b/shellcheck.sh index 2adf23bc..ac343a56 100755 --- a/shellcheck.sh +++ b/shellcheck.sh @@ -16,3 +16,5 @@ done < <( ) LC_ALL=C.UTF-8 shellcheck "${targets[@]}" + +exit $? diff --git a/test/parallell.bats b/test/parallell.bats index 5207aef4..80dcb713 100644 --- a/test/parallell.bats +++ b/test/parallell.bats @@ -51,10 +51,11 @@ setup() { [[ "${lines[$i]}" == "ok $i slow test $t" ]] done done - # In theory it should take 3s, but let's give it bit of extra time instead. - # also check that parallelization happens accross all files instead of + # In theory it should take 3s, but let's give it bit of extra time for load tolerance. + # (Since there is no limit to load, we cannot totally avoid erronous failures by limited tolerance.) + # Also check that parallelization happens accross all files instead of # linearizing between files, which requires at least 12s - [[ "$duration" -lt 12 ]] + [[ "$duration" -lt 12 ]] || (echo "If this fails on Travis, make sure the failure is repeatable and not due to heavy load."; false) } @test "setup_file is not over parallelized" { @@ -68,4 +69,4 @@ setup() { [[ $duration -ge 6 ]] # parallelization should at least get rid of 1/4th the total runtime [[ $duration -lt 9 ]] -} \ No newline at end of file +}