Skip to content

programs.sh: BSD date and stat on macOS - #278

Merged
jonathanperis merged 5 commits into
jonathanperis:mainfrom
filipnavara:fix/run-sh-bash32
Nov 27, 2026
Merged

jonathanperis merged 5 commits into
jonathanperis:mainfrom
filipnavara:fix/run-sh-bash32

Conversation

@filipnavara

@filipnavara filipnavara commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #198.

macOS ships /bin/bash 3.2 and BSD userland, which break the test scripts in three ways:

  1. Empty arrays under set -u. "${arr[@]}" of an empty array is an "unbound variable" error. A native run leaves TARGET_FLAGS, test_env, pin and RUN_PREFIX empty, so every sample failed on a stock Mac, and tests/size.sh stopped at once. ${arr[@]+"${arr[@]}"} expands to nothing for an empty array on every bash version and keeps per-element quoting otherwise. Every array expansion now uses it in run.sh, size.sh, programs.sh, projects.sh, debuginfo.sh, check-oracle.sh and slicer.sh. il-main-check.sh needs bash 4's associative arrays and runs on Linux, so it is untouched.
  2. CSHARPC_JOBS=N relied on wait -n (bash 4.3+). On 3.2 it fails at once, so the running count dropped without any job ending and every sample ran at the same time. Bash before 4.3 now polls the jobs' pids (kill -0, 50 ms); 4.3+ keeps wait -n.
  3. GNU-only date +%s%N and stat -c %s in programs.sh. macOS's date prints a literal N (a shell arithmetic error) and its stat has no -c. The size now comes from wc -c, and timing falls back to perl's Time::HiRes where date has no %N.

Checked on macOS 27 arm64 with /bin/bash 3.2.57:

… bash 3.2)

macOS ships /bin/bash 3.2, where "${arr[@]}" of an empty array is an
'unbound variable' error under set -u. TARGET_FLAGS, test_env, pin and
RUN_PREFIX are empty for a native run, so every sample failed there.
${arr[@]+"${arr[@]}"} expands to nothing for an empty array on every
bash version and keeps the quoting otherwise.

Fixes jonathanperis#198.
CSHARPC_JOBS=N reaped jobs with wait -n, which bash 3.2 doesn't have: it
failed at once, so the running count dropped without a job ending and
every sample ran at the same time. Bash before 4.3 now polls the jobs'
pids instead.
…d stat)

The same empty-array expansion as tests/run.sh broke tests/size.sh
(TARGET_FLAGS) and would break the other suites with optional arrays:
size, programs, projects, debuginfo, check-oracle and slicer now expand
${arr[@]+"${arr[@]}"}. tests/programs.sh also timed builds with
date +%s%N and sized them with stat -c %s, both GNU-only: macOS's date
prints a literal N and its stat has no -c. It now uses wc -c, and perl's
Time::HiRes where date has no %N.
@filipnavara filipnavara changed the title tests/run.sh: run on macOS's /bin/bash 3.2 (empty arrays under set -u) Test scripts: run on macOS (bash 3.2 empty arrays, wait -n, BSD date/stat) Nov 10, 2026
main now re-runs every set -u test script under bash 4.4+ (jonathanperis#498, which
closed jonathanperis#198), so the empty-array expansions and the wait -n fallback are no
longer needed. programs.sh still called GNU-only date +%s%N and stat -c,
which the re-run does not change on a Mac without coreutils.
@jonathanperis jonathanperis changed the title Test scripts: run on macOS (bash 3.2 empty arrays, wait -n, BSD date/stat) programs.sh: BSD date and stat on macOS Nov 27, 2026
@jonathanperis
jonathanperis marked this pull request as ready for review November 27, 2026 13:44
@jonathanperis

Copy link
Copy Markdown
Owner

Thanks, @filipnavara. #198 was fixed on main by #498 another way: every set -u test script now re-runs itself under Homebrew's bash 4.4+ when started from macOS's bash 3.2. So the empty-array expansions and the wait -n fallback here are no longer needed, and I've dropped them.

One part still applies after the re-run: programs.sh calls GNU-only date +%s%N and stat -c %s, which fail on a Mac without coreutils. I've reduced this PR to that part, on top of current main (d9f66b0): your now_ms (perl Time::HiRes where date has no %N) and wc -c for the size. I've marked it ready for review, and it merges when CI is green.

@jonathanperis
jonathanperis merged commit 9f8be27 into jonathanperis:main Nov 27, 2026
28 of 33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tests/run.sh fails on macOS's /bin/bash 3.2: empty arrays under set -u ('TARGET_FLAGS[@]: unbound variable')

2 participants