Skip to content

Commit 4f11e82

Browse files
committed
fix: unique test-specific prefixes to temporary file and directory creation
1 parent 73d0718 commit 4f11e82

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

src/globals.sh

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,29 @@ function random_str() {
4040
function temp_file() {
4141
local prefix=${1:-bashunit}
4242
mkdir -p /tmp/bashunit/tmp && chmod -R 777 /tmp/bashunit/tmp
43-
mktemp /tmp/bashunit/tmp/"$prefix".XXXXXXX
43+
local test_prefix=""
44+
if [[ -n "${BASHUNIT_CURRENT_TEST_ID:-}" ]]; then
45+
test_prefix="${BASHUNIT_CURRENT_TEST_ID}_"
46+
fi
47+
mktemp /tmp/bashunit/tmp/"${test_prefix}${prefix}".XXXXXXX
4448
}
4549

4650
function temp_dir() {
4751
local prefix=${1:-bashunit}
4852
mkdir -p /tmp/bashunit/tmp && chmod -R 777 /tmp/bashunit/tmp
49-
mktemp -d /tmp/bashunit/tmp/"$prefix".XXXXXXX
53+
local test_prefix=""
54+
if [[ -n "${BASHUNIT_CURRENT_TEST_ID:-}" ]]; then
55+
test_prefix="${BASHUNIT_CURRENT_TEST_ID}_"
56+
fi
57+
mktemp -d /tmp/bashunit/tmp/"${test_prefix}${prefix}".XXXXXXX
5058
}
5159

5260
function cleanup_temp_files() {
53-
rm -rf /tmp/bashunit/tmp/*
61+
if [[ -n "${BASHUNIT_CURRENT_TEST_ID:-}" ]]; then
62+
rm -rf /tmp/bashunit/tmp/"${BASHUNIT_CURRENT_TEST_ID}"_*
63+
else
64+
rm -rf /tmp/bashunit/tmp/*
65+
fi
5466
}
5567

5668
# shellcheck disable=SC2145

0 commit comments

Comments
 (0)