From 842cd572b8bd6b681f909d28b90704cda58c482b Mon Sep 17 00:00:00 2001 From: Chemaclass Date: Thu, 16 Jul 2026 05:02:23 +0200 Subject: [PATCH] perf(runner): list functions with compgen builtin, not declare -F | awk Three call sites captured the defined-function list by piping 'declare -F' through an awk fork. 'compgen -A function' is a bash builtin producing the identical name-per-line output (both alphabetical), so the capture costs only its subshell. 5 -> 3 awk forks per test file; the remainder are the per-file file scans (provider map x2, duplicate check). No behaviour change. --- CHANGELOG.md | 1 + src/helpers.sh | 2 +- src/runner.sh | 8 ++--- tests/acceptance/bashunit_run_forks_test.sh | 34 +++++++++++++++++++++ 4 files changed, 40 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b7239cdd..03777d97 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ - `--jobs auto` / `-j auto` caps parallel concurrency at the CPU core count (portable across Linux/macOS/BSD); the default stays unlimited (#766) ### Changed +- Faster test runs: listing all defined functions uses the `compgen -A function` builtin instead of forking `declare -F | awk` (three call sites; 5 -> 3 `awk` forks per test file). No behaviour change - Faster test runs: ordering a file's test functions by definition line is pure bash now instead of an `awk | sort | awk` pipeline that ran twice per file, and the duplicate-function check sorts its (usually empty) result inside awk instead of piping through `sort` (9 -> 5 forks per test file). No behaviour change - Faster failure rendering: the "Source:" assert-line context of a failing test reads the test-function body in a single pass instead of forking `sed` per line and `grep` per line to find the closing brace (a 20-line body dropped from ~46 to ~2 forks here). No behaviour change - Faster test runs: each test's subshell result payload is emitted with `printf` (a builtin) instead of a `cat <> \"$count_file\"" + echo "exec \"$real_awk\" \"\$@\"" + } >"$dir/awk" + chmod +x "$dir/awk" + + local fixture="$dir/awk_budget_test.sh" + printf 'function test_ok() { assert_true true; }\n' >"$fixture" + + PATH="$dir:$PATH" ./bashunit --no-parallel "$fixture" >/dev/null 2>&1 + + local awk_forks=0 + if [ -f "$count_file" ]; then + awk_forks="$(grep -c . "$count_file" || true)" + fi + + assert_less_or_equal_than 3 "$awk_forks" +}