fix(kyberforge): make bats dispatcher bash-3.2 safe
run-bats.sh's new bounded parallel dispatcher used nproc/wait -n, which are bash 4.3+/GNU-only and silently drop the concurrency cap on macOS's stock bash 3.2 (the wait -n error is swallowed by `|| true`). Its sibling tests/run-tests.sh, changed in the same PR and explicitly bash-3.2-safe, already solves this with getconf + a batched wait. Ported that same pattern here for consistency and to actually meet the compatibility goal. Refs: #95
This commit is contained in:
@@ -39,11 +39,12 @@ fi
|
|||||||
SCRATCH_ROOT="$(mktemp -d)"
|
SCRATCH_ROOT="$(mktemp -d)"
|
||||||
trap 'rm -rf "$SCRATCH_ROOT"' EXIT
|
trap 'rm -rf "$SCRATCH_ROOT"' EXIT
|
||||||
|
|
||||||
# A failing test is the normal case a CI runner must handle, and a failing
|
# Batches (not a rolling pool) because a bounded rolling pool needs `wait -n`,
|
||||||
# background job makes `wait`/`wait -n` return non-zero -- under `set -e` that
|
# which is bash 4.3+ and this script is explicitly bash-3.2-safe like
|
||||||
# would abort the script right here, before the per-file report below ever
|
# run-tests.sh; plain `wait` -- waiting for every job in the current batch --
|
||||||
# runs. Every wait in this dispatcher is therefore explicitly guarded.
|
# is available since ancient bash. `getconf` over `nproc` for the same
|
||||||
JOBS="$(nproc 2>/dev/null || echo 4)"
|
# reason: `nproc` doesn't exist on macOS.
|
||||||
|
JOBS="$(getconf _NPROCESSORS_ONLN 2>/dev/null || echo 4)"
|
||||||
running=0
|
running=0
|
||||||
i=0
|
i=0
|
||||||
for f in "${TEST_FILES[@]}"; do
|
for f in "${TEST_FILES[@]}"; do
|
||||||
@@ -51,11 +52,11 @@ for f in "${TEST_FILES[@]}"; do
|
|||||||
( "$BATS" "$f" >"$SCRATCH_ROOT/$i.log" 2>&1; echo $? >"$SCRATCH_ROOT/$i.status" ) &
|
( "$BATS" "$f" >"$SCRATCH_ROOT/$i.log" 2>&1; echo $? >"$SCRATCH_ROOT/$i.status" ) &
|
||||||
running=$((running + 1))
|
running=$((running + 1))
|
||||||
if [[ "$running" -ge "$JOBS" ]]; then
|
if [[ "$running" -ge "$JOBS" ]]; then
|
||||||
wait -n || true
|
wait
|
||||||
running=$((running - 1))
|
running=0
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
wait || true
|
wait
|
||||||
|
|
||||||
FAIL=0
|
FAIL=0
|
||||||
TOTAL_OK=0
|
TOTAL_OK=0
|
||||||
|
|||||||
Reference in New Issue
Block a user