@@ -5,11 +5,15 @@ function runner::load_test_files() {
55 local filter=$1
66 shift
77 local files=(" ${@ } " )
8+ local scripts_ids=()
89
910 for test_file in " ${files[@]} " ; do
1011 if [[ ! -f $test_file ]]; then
1112 continue
1213 fi
14+ unset BASHUNIT_CURRENT_TEST_ID
15+ export BASHUNIT_CURRENT_SCRIPT_ID=" $( helper::generate_id " ${test_file} " ) "
16+ scripts_ids+=(" ${BASHUNIT_CURRENT_SCRIPT_ID} " )
1317 internal_log " Loading file" " $test_file "
1418 # shellcheck source=/dev/null
1519 source " $test_file "
@@ -21,6 +25,9 @@ function runner::load_test_files() {
2125 fi
2226 runner::run_tear_down_after_script
2327 runner::clean_set_up_and_tear_down_after_script
28+ if ! parallel::is_enabled; then
29+ cleanup_script_temp_files
30+ fi
2431 internal_log " Finished file" " $test_file "
2532 done
2633
@@ -32,6 +39,10 @@ function runner::load_test_files() {
3239 # Kill the spinner once the aggregation finishes
3340 disown " $spinner_pid " && kill " $spinner_pid " & > /dev/null
3441 printf " \r " # Clear the spinner output
42+ for script_id in " ${scripts_ids[@]} " ; do
43+ export BASHUNIT_CURRENT_SCRIPT_ID=" ${script_id} "
44+ cleanup_script_temp_files
45+ done
3546 fi
3647}
3748
@@ -42,12 +53,15 @@ function runner::load_bench_files() {
4253
4354 for bench_file in " ${files[@]} " ; do
4455 [[ -f $bench_file ]] || continue
56+ unset BASHUNIT_CURRENT_TEST_ID
57+ export BASHUNIT_CURRENT_SCRIPT_ID=" $( helper::generate_id " ${test_file} " ) "
4558 # shellcheck source=/dev/null
4659 source " $bench_file "
4760 runner::run_set_up_before_script
4861 runner::call_bench_functions " $bench_file " " $filter "
4962 runner::run_tear_down_after_script
5063 runner::clean_set_up_and_tear_down_after_script
64+ cleanup_script_temp_files
5165 done
5266}
5367
@@ -232,17 +246,11 @@ function runner::run_test() {
232246 local fn_name=" $1 "
233247 shift
234248
249+ internal_log " Running test" " $fn_name " " $* "
235250 # Export a unique test identifier so that test doubles can
236251 # create temporary files scoped per test run. This prevents
237252 # race conditions when running tests in parallel.
238- local sanitized_fn_name
239- sanitized_fn_name=" $( helper::normalize_variable_name " $fn_name " ) "
240- internal_log " Running test" " $fn_name " " $* "
241- if env::is_parallel_run_enabled; then
242- export BASHUNIT_CURRENT_TEST_ID=" ${sanitized_fn_name} _$$ _$( random_str 6) "
243- else
244- export BASHUNIT_CURRENT_TEST_ID=" ${sanitized_fn_name} _$$ "
245- fi
253+ export BASHUNIT_CURRENT_TEST_ID=" $( helper::generate_id " $fn_name " ) "
246254
247255 state::reset_test_title
248256
@@ -265,6 +273,7 @@ function runner::run_test() {
265273 state::set_test_exit_code "$exit_code"
266274 runner::run_tear_down
267275 runner::clear_mocks
276+ cleanup_testcase_temp_files
268277 state::export_subshell_context
269278 ' EXIT
270279 state::initialize_assertions_count
0 commit comments