Skip to content

Commit 9af36a0

Browse files
authored
Merge pull request sstephenson#244 from martin-schulze-vireso/feature/add_once_per_file_setup_and_teardown
feat: add once-per-file setup and teardown
2 parents 805650e + 10b0daf commit 9af36a0

File tree

5 files changed

+17
-14
lines changed

5 files changed

+17
-14
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ FROM bash:${bashver}
44

55
# Install parallel and accept the citation notice (we aren't using this in a
66
# context where it make sense to cite GNU Parallel).
7-
RUN apk add --no-cache parallel && \
7+
RUN apk add --no-cache parallel ncurses && \
88
mkdir -p ~/.parallel && touch ~/.parallel/will-cite
99

1010
RUN ln -s /opt/bats/bin/bats /usr/sbin/bats

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ There was an initial [call for maintainers][call-maintain] for the original Bats
572572

573573
## Copyright
574574

575-
© 2017-2018 bats-core organization
575+
© 2017-2020 bats-core organization
576576

577577
© 2011-2016 Sam Stephenson
578578

libexec/bats-core/bats

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,14 @@ if [[ "${#arguments[@]}" -eq 0 ]]; then
224224
abort 'Must specify at least one <test>'
225225
fi
226226

227+
228+
if [[ -n "$output" ]]; then
229+
if [[ ! -w "${output}" ]]; then
230+
abort "Output path ${output} is not writeable"
231+
fi
232+
export BATS_REPORT_OUTPUT_PATH="$output"
233+
fi
234+
227235
filenames=()
228236
for filename in "${arguments[@]}"; do
229237
expand_path "$filename" 'filename'
@@ -248,13 +256,5 @@ done
248256
# shellcheck source=lib/bats-core/validator.bash
249257
source "$BATS_ROOT/lib/bats-core/validator.bash"
250258

251-
if [[ -n "$output" ]]; then
252-
if [[ ! -w "${output}" ]]; then
253-
printf "Error: output path %s is not writeable\n" "${output}" >&2
254-
exit 1
255-
fi
256-
export BATS_REPORT_OUTPUT_PATH="$output"
257-
fi
258-
259259
set -o pipefail execfail
260260
exec bats-exec-suite "${flags[@]}" "${filenames[@]}" | bats_test_count_validator | "bats-format-${formatter}" "${formatter_flags[@]}"

shellcheck.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ done < <(
1616
)
1717

1818
LC_ALL=C.UTF-8 shellcheck "${targets[@]}"
19+
20+
exit $?

test/parallell.bats

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@ setup() {
5151
[[ "${lines[$i]}" == "ok $i slow test $t" ]]
5252
done
5353
done
54-
# In theory it should take 3s, but let's give it bit of extra time instead.
55-
# also check that parallelization happens accross all files instead of
54+
# In theory it should take 3s, but let's give it bit of extra time for load tolerance.
55+
# (Since there is no limit to load, we cannot totally avoid erronous failures by limited tolerance.)
56+
# Also check that parallelization happens accross all files instead of
5657
# linearizing between files, which requires at least 12s
57-
[[ "$duration" -lt 12 ]]
58+
[[ "$duration" -lt 12 ]] || (echo "If this fails on Travis, make sure the failure is repeatable and not due to heavy load."; false)
5859
}
5960

6061
@test "setup_file is not over parallelized" {
@@ -68,4 +69,4 @@ setup() {
6869
[[ $duration -ge 6 ]]
6970
# parallelization should at least get rid of 1/4th the total runtime
7071
[[ $duration -lt 9 ]]
71-
}
72+
}

0 commit comments

Comments
 (0)