You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
bashunit::runner::call_test_functions calls bashunit::helper::get_provider_data "$fn_name" "$script" for every test function (src/runner.sh:778-782). get_provider_data (src/helpers.sh:295-319) runs grep -B 2 -E ... "$script" | sed -nE ... — two external forks plus a full re-read of the test file from disk — just to discover whether a # @data_provider annotation exists above the function. For the overwhelming majority of tests there is no provider.
Measured cost: ~3.3ms per test on macOS bash 3.2, ~4s across the suite, compounding inside the 258 nested ./bashunit acceptance runs.
Task
Scan each test file once (when its functions are enumerated in call_test_functions, src/runner.sh:757 area) and build a test-function -> provider-function map for that file; per-test lookup becomes pure bash.
Implementation sketch (Bash 3.0 compatible — no associative arrays):
One grep/awk pass per file extracting pairs of (annotation provider name, following test function name). Must match the same things the current probe matches: # data_provider fn and # @data_provider fn (see sed pattern at src/helpers.sh:313), annotation up to 2 lines above a function defined either as function test_x or test_x().
Store as a newline-delimited global string of test_fn provider_fn records (or two parallel indexed arrays); reset it per file. Lookup with a plain loop or case match.
Keep bashunit::helper::execute_function_if_exists behavior for missing provider functions.
get_provider_data can remain as a thin wrapper over the cache so its unit tests keep passing, or be replaced — follow whichever keeps the public surface unchanged.
Tests first (TDD)
Existing provider behavior tests: tests/functional/provider_test.sh must pass unchanged (both sequential and --parallel).
Part of #761.
Problem
bashunit::runner::call_test_functionscallsbashunit::helper::get_provider_data "$fn_name" "$script"for every test function (src/runner.sh:778-782).get_provider_data(src/helpers.sh:295-319) runsgrep -B 2 -E ... "$script" | sed -nE ...— two external forks plus a full re-read of the test file from disk — just to discover whether a# @data_providerannotation exists above the function. For the overwhelming majority of tests there is no provider.Measured cost: ~3.3ms per test on macOS bash 3.2, ~4s across the suite, compounding inside the 258 nested
./bashunitacceptance runs.Task
Scan each test file once (when its functions are enumerated in
call_test_functions,src/runner.sh:757area) and build a test-function -> provider-function map for that file; per-test lookup becomes pure bash.Implementation sketch (Bash 3.0 compatible — no associative arrays):
grep/awkpass per file extracting pairs of (annotation provider name, following test function name). Must match the same things the current probe matches:# data_provider fnand# @data_provider fn(seesedpattern atsrc/helpers.sh:313), annotation up to 2 lines above a function defined either asfunction test_xortest_x().test_fn provider_fnrecords (or two parallel indexed arrays); reset it per file. Lookup with a plain loop orcasematch.bashunit::helper::execute_function_if_existsbehavior for missing provider functions.set_up_before_script#529 fallback: if the script path is not readable, retry with$BASHUNIT_WORKING_DIR/$script(src/helpers.sh:301-303), and return no providers if still unreadable.get_provider_datacan remain as a thin wrapper over the cache so its unit tests keep passing, or be replaced — follow whichever keeps the public surface unchanged.Tests first (TDD)
tests/functional/provider_test.shmust pass unchanged (both sequential and--parallel).@and without, annotation 2 lines above the function, two functions sharing one provider, file with none, unreadable path (issue Data providers don't work when changing directory inset_up_before_script#529 case).Constraints
declare -A, no[[ ]], no${var,,}, no negative array indexing, no&>>..claude/rules/bash-style.md— no new$(...)per-test call.Acceptance criteria
./bashunit tests/and./bashunit --parallel tests/pass.make sa,make lintpass;shfmt -w .produces no diff.grep+sedpair replaced by at most one scan per file.Line references valid at commit 4d80e7c.