File tree Expand file tree Collapse file tree 2 files changed +36
-1
lines changed
Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change 1- BATS_MOCK_TMPDIR=" ${BATS_RUN_TMPDIR } "
1+ BATS_MOCK_TMPDIR=" ${BATS_TEST_TMPDIR } "
22BATS_MOCK_BINDIR=" ${BATS_MOCK_TMPDIR} /bin"
33
44BATS_MOCK_REAL_mkdir=$( which mkdir)
Original file line number Diff line number Diff line change 1+ load ' ../stub'
2+
3+ # Generates a temporary test file with the specified number of tests.
4+ # Each test stubs the SAME command and then unstubs to validate.
5+ generate_stubbed_test_file () {
6+ local num_tests=" $1 "
7+ local cmd_to_stub=" $2 "
8+ local output_file=" $3 "
9+ local bats_test_placeholder=" @test"
10+ echo " load '$( cd " ${BATS_TEST_DIRNAME} /.." && echo " $( pwd) /stub" ) '" > " ${output_file} "
11+
12+ local test_number
13+ for test_number in $( seq 1 " ${num_tests} " ) ; do
14+ cat >> " ${output_file} " << EOF
15+ ${bats_test_placeholder} "concurrent stub '${cmd_to_stub} ${test_number} '" {
16+ stub ${cmd_to_stub} "${test_number} : echo '${cmd_to_stub} called with arg ${test_number} "
17+
18+ run ${cmd_to_stub} ${test_number}
19+
20+ unstub '${cmd_to_stub} '
21+ }
22+
23+ EOF
24+ done
25+ }
26+
27+ @test " stubs do not interfere with each other when using 'bats --jobs'" {
28+ local test_file_to_run=" ${BATS_TEST_TMPDIR} /concurrent_stub_tests.bats"
29+ generate_stubbed_test_file 10 ' mycommand' " ${test_file_to_run} "
30+
31+ run bats --jobs 4 " ${test_file_to_run} "
32+
33+ [ " ${status} " -eq 0 ]
34+ [[ ! " ${output} " =~ " unstub 'mycommand'' failed" ]]
35+ }
You can’t perform that action at this time.
0 commit comments