Skip to content

Commit

Permalink
Merge pull request sstephenson#244 from martin-schulze-vireso/feature…
Browse files Browse the repository at this point in the history
…/add_once_per_file_setup_and_teardown

feat: add once-per-file setup and teardown
  • Loading branch information
sublimino authored Apr 27, 2020
2 parents 805650e + 10b0daf commit 9af36a0
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 8 additions & 8 deletions libexec/bats-core/bats
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,14 @@ if [[ "${#arguments[@]}" -eq 0 ]]; then
abort 'Must specify at least one <test>'
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'
Expand All @@ -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[@]}"
2 changes: 2 additions & 0 deletions shellcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ done < <(
)

LC_ALL=C.UTF-8 shellcheck "${targets[@]}"

exit $?
9 changes: 5 additions & 4 deletions test/parallell.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand All @@ -68,4 +69,4 @@ setup() {
[[ $duration -ge 6 ]]
# parallelization should at least get rid of 1/4th the total runtime
[[ $duration -lt 9 ]]
}
}

0 comments on commit 9af36a0

Please sign in to comment.