Skip to content

Commit e3bd116

Browse files
Merge pull request #657 from marc-hb/fix-infinite-j
Fix infinite wait when invoking "bats -j5" instead of "bats -j 5"
2 parents c0d2ca1 + 58fa597 commit e3bd116

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

docs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ The format is based on [Keep a Changelog][kac] and this project adheres to
1414

1515
* `shfmt` all files and enforce via CI (#651)
1616
* avoid kernel warning flood/hang with CTRL+C on Bash 5.2 RC (#656)
17+
* Fix infinite wait with (invalid) `-j<n>` (without space) (#657)
1718

1819
## [1.8.0] - 2022-09-15
1920

libexec/bats-core/bats-exec-file

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,11 @@ bats_read_tests_list_file() {
285285
bats_run_tests() {
286286
bats_exec_file_status=0
287287

288+
if [[ "$num_jobs" -lt 1 ]]; then
289+
printf 'Invalid number of jobs: %s\n' "$num_jobs" >&2
290+
exit 1
291+
fi
292+
288293
if [[ "$num_jobs" != 1 && "${BATS_NO_PARALLELIZE_WITHIN_FILE-False}" == False ]]; then
289294
export BATS_SEMAPHORE_NUMBER_OF_SLOTS="$num_jobs"
290295
bats_run_tests_in_parallel "$BATS_RUN_TMPDIR/parallel_output" || bats_exec_file_status=1

test/parallel.bats

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ bats_require_minimum_version 1.5.0
55
load test_helper
66
fixtures parallel
77

8+
# shellcheck disable=SC2034
9+
BATS_TEST_TIMEOUT=10 # only intended for the "short form ..."" test
10+
811
setup() {
912
type -p parallel &>/dev/null || skip "--jobs requires GNU parallel"
1013
(type -p flock &>/dev/null || type -p shlock &>/dev/null) || skip "--jobs requires flock/shlock"
@@ -208,3 +211,10 @@ check_parallel_tests() { # <expected maximum parallelity>
208211
@test "BATS_NO_PARALLELIZE_WITHIN_FILE does not work from inside test function" {
209212
DISABLE_IN_TEST_FUNCTION=1 reentrant_run ! bats --jobs 2 "$FIXTURE_ROOT/must_not_parallelize_within_file.bats"
210213
}
214+
215+
@test "Short form typo does not run endlessly" {
216+
unset BATS_NO_PARALLELIZE_ACROSS_FILES
217+
run bats -j2 "$FIXTURE_ROOT/../bats/passing.bats"
218+
(( SECONDS < 5 ))
219+
[ "${lines[1]}" = 'Invalid number of jobs: -2' ]
220+
}

test/timeout.bats

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,7 @@ bats_require_minimum_version 1.5.0
2323
[ "${lines[3]}" == "# \`sleep \"\${SLEEP?}\"' failed due to timeout" ]
2424
((SECONDS < 10)) || false
2525
}
26+
27+
@test "sleep in run" {
28+
run sleep 10
29+
}

0 commit comments

Comments
 (0)