File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -136,6 +136,13 @@ function runner::run_test() {
136136 local fn_name=" $1 "
137137 shift
138138
139+ # Export a unique test identifier so that test doubles can
140+ # create temporary files scoped per test run. This prevents
141+ # race conditions when running tests in parallel.
142+ local sanitized_fn_name
143+ sanitized_fn_name=" $( helper::normalize_variable_name " $fn_name " ) "
144+ export BASHUNIT_CURRENT_TEST_ID=" ${sanitized_fn_name} _$$ "
145+
139146 local interpolated_fn_name=" $( helper::interpolate_function_name " $fn_name " " $@ " ) "
140147 local current_assertions_failed=" $( state::get_assertions_failed) "
141148 local current_assertions_snapshot=" $( state::get_assertions_snapshot) "
Original file line number Diff line number Diff line change @@ -48,8 +48,9 @@ function spy() {
4848 export " ${variable} _params"
4949
5050 local times_file params_file
51- times_file=$( temp_file " ${variable} _times" )
52- params_file=$( temp_file " ${variable} _params" )
51+ local test_id=" ${BASHUNIT_CURRENT_TEST_ID:- global} "
52+ times_file=$( temp_file " ${test_id} _${variable} _times" )
53+ params_file=$( temp_file " ${test_id} _${variable} _params" )
5354 echo 0 > " $times_file "
5455 : > " $params_file "
5556 export " ${variable} _times_file" =" $times_file "
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+
3+ function test_spy_file1() {
4+ spy date
5+ date
6+ assert_have_been_called_times 1 date
7+ }
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+
3+ function test_spy_file2() {
4+ spy date
5+ date
6+ assert_have_been_called_times 1 date
7+ }
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+ set -euo pipefail
3+
4+ function test_spies_work_in_parallel() {
5+ local file1=tests/acceptance/fixtures/test_parallel_spy_file1.sh
6+ local file2=tests/acceptance/fixtures/test_parallel_spy_file2.sh
7+
8+ ./bashunit --parallel " $file1 " " $file2 "
9+ assert_successful_code
10+ }
You can’t perform that action at this time.
0 commit comments