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)"
|
||||
trap 'rm -rf "$SCRATCH_ROOT"' EXIT
|
||||
|
||||
# A failing test is the normal case a CI runner must handle, and a failing
|
||||
# background job makes `wait`/`wait -n` return non-zero -- under `set -e` that
|
||||
# would abort the script right here, before the per-file report below ever
|
||||
# runs. Every wait in this dispatcher is therefore explicitly guarded.
|
||||
JOBS="$(nproc 2>/dev/null || echo 4)"
|
||||
# Batches (not a rolling pool) because a bounded rolling pool needs `wait -n`,
|
||||
# which is bash 4.3+ and this script is explicitly bash-3.2-safe like
|
||||
# run-tests.sh; plain `wait` -- waiting for every job in the current batch --
|
||||
# is available since ancient bash. `getconf` over `nproc` for the same
|
||||
# reason: `nproc` doesn't exist on macOS.
|
||||
JOBS="$(getconf _NPROCESSORS_ONLN 2>/dev/null || echo 4)"
|
||||
running=0
|
||||
i=0
|
||||
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" ) &
|
||||
running=$((running + 1))
|
||||
if [[ "$running" -ge "$JOBS" ]]; then
|
||||
wait -n || true
|
||||
running=$((running - 1))
|
||||
wait
|
||||
running=0
|
||||
fi
|
||||
done
|
||||
wait || true
|
||||
wait
|
||||
|
||||
FAIL=0
|
||||
TOTAL_OK=0
|
||||
|
||||
Reference in New Issue
Block a user