From b169de40f6e5f1cd73cd0e3036cb8ee80dc1256c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Bergstro=CC=88m?= Date: Thu, 22 Jan 2026 20:21:44 +0000 Subject: [PATCH] chore(perf): cache output by set in test runner Improve performance in the discovery phase by caching output instead of regenerating it multiple times. --- bash_unit | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bash_unit b/bash_unit index e24f406..b43050b 100755 --- a/bash_unit +++ b/bash_unit @@ -244,14 +244,16 @@ maybe_shuffle() { run_tests() { local failure=0 - local pending_tests=$(set | "$GREP" -E '^(pending|todo).* \(\)' | "$GREP" -E "$test_pattern" | "$SED" -e 's: .*::') + local all_functions=$(set) + + local pending_tests=$(echo "$all_functions" | "$GREP" -E '^(pending|todo).* \(\)' | "$GREP" -E "$test_pattern" | "$SED" -e 's: .*::') if [[ -n "$skip_pattern" ]] then - local skipped_tests=$(set | "$GREP" -E '^test.* \(\)' | "$GREP" -E "$test_pattern" | "$GREP" -E "$skip_pattern" | "$SED" -e 's: .*::') - local tests_to_run="$(set | "$GREP" -E '^test.* \(\)' | "$GREP" -E "$test_pattern" | "$GREP" -v -E "$skip_pattern" | "$SED" -e 's: .*::' | maybe_shuffle)" + local skipped_tests=$(echo "$all_functions" | "$GREP" -E '^test.* \(\)' | "$GREP" -E "$test_pattern" | "$GREP" -E "$skip_pattern" | "$SED" -e 's: .*::') + local tests_to_run="$(echo "$all_functions" | "$GREP" -E '^test.* \(\)' | "$GREP" -E "$test_pattern" | "$GREP" -v -E "$skip_pattern" | "$SED" -e 's: .*::' | maybe_shuffle)" else local skipped_tests="" - local tests_to_run="$(set | "$GREP" -E '^test.* \(\)' | "$GREP" -E "$test_pattern" | "$SED" -e 's: .*::' | maybe_shuffle)" + local tests_to_run="$(echo "$all_functions" | "$GREP" -E '^test.* \(\)' | "$GREP" -E "$test_pattern" | "$SED" -e 's: .*::' | maybe_shuffle)" fi local test_count=$(cat "${TEST_COUNT_FILE}")