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
fix: make array iteration safe for strict mode (set -u)
When bashunit runs with BASHUNIT_STRICT_MODE=true (set -u), iterating
over arrays could trigger "unbound variable" errors. This fix implements
safe array iteration patterns:
- For value iteration: Use "${array[@]+"${array[@]}"}" pattern which
expands to nothing when array is empty, preventing unbound errors
- For indexed iteration: Check array size before loop with
[ "${#array[@]}" -gt 0 ] to avoid iterating over empty arrays
- Add default values (:-) when accessing array elements to handle
unset elements gracefully
Changes affect:
- src/benchmark.sh: Safe iteration over benchmark result arrays
- src/env.sh: Safe iteration over environment variable keys
- src/helpers.sh: Safe iteration over function names
- src/main.sh: Safe iteration over command-line arguments
- src/parallel.sh: Safe iteration over result files
- src/reports.sh: Safe iteration over test results
- src/runner.sh: Safe iteration over test files and functions
- src/test_doubles.sh: Safe iteration over mocked functions
All tests passing locally (738 passed, 3 skipped, 7 incomplete).
Fixes strict mode compatibility without breaking existing functionality.
0 commit comments