Skip to content

Commit fa7076e

Browse files
authored
Merge pull request #448 from drupol/push-lwszrnosxpxr
fix: prevent writing in source directory during tests
2 parents b814e83 + 67afb9c commit fa7076e

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

tests/unit/assert_snapshot_test.sh

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,27 +89,29 @@ function test_assert_match_snapshot_with_placeholder() {
8989
if check_os::is_alpine; then
9090
skip "not supported on alpine" && return
9191
fi
92-
local snapshot_path
93-
snapshot_path=tests/unit/snapshots/assert_snapshot_test_sh.test_assert_match_snapshot_with_placeholder.snapshot
94-
mkdir -p tests/unit/snapshots
92+
93+
local temp_dir
94+
temp_dir=$(mktemp -d)
95+
local snapshot_path="$temp_dir/assert_snapshot_test_sh.test_assert_match_snapshot_with_placeholder.snapshot"
9596
echo 'Run at ::ignore::' > "$snapshot_path"
9697

97-
assert_empty "$(assert_match_snapshot "Run at $(date)")"
98+
assert_empty "$(assert_match_snapshot "Run at $(date)" "$snapshot_path")"
9899

99-
rm "$snapshot_path"
100+
rm -rf "$temp_dir"
100101
}
101102

102103
function test_assert_match_snapshot_with_custom_placeholder() {
103104
if check_os::is_alpine; then
104105
skip "not supported on alpine" && return
105106
fi
106-
local snapshot_path
107-
snapshot_path=tests/unit/snapshots/assert_snapshot_test_sh.test_assert_match_snapshot_with_custom_placeholder.snapshot
108-
mkdir -p tests/unit/snapshots
107+
108+
local temp_dir
109+
temp_dir=$(mktemp -d)
110+
local snapshot_path="$temp_dir/assert_snapshot_test_sh.test_assert_match_snapshot_with_custom_placeholder.snapshot"
109111
echo 'Value __ANY__' > "$snapshot_path"
110112

111113
export BASHUNIT_SNAPSHOT_PLACEHOLDER='__ANY__'
112-
assert_empty "$(assert_match_snapshot "Value 42")"
114+
assert_empty "$(assert_match_snapshot "Value 42" "$snapshot_path")"
113115

114-
rm "$snapshot_path"
116+
rm -rf "$temp_dir"
115117
}

0 commit comments

Comments
 (0)