Skip to content

Commit 57ee9ef

Browse files
committed
add test utility tempfile_name()
1 parent 04d8aa4 commit 57ee9ef

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

test/tools/libtest.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,20 @@ tty_reset()
138138
fi
139139
}
140140

141+
tempfile_name()
142+
{
143+
temp_base="${1:-tempfile}"
144+
if which mktemp >/dev/null 2>&1; then
145+
temp_file="$(mktemp "$tmp_dir/${temp_base}.XXXXXX")"
146+
else
147+
temp_file="$tmp_dir/${temp_base}.$$"
148+
while [ -e "$temp_file" ]; do
149+
temp_file="${temp_file}.alt"
150+
done
151+
fi
152+
printf '%s\n' "$temp_file"
153+
}
154+
141155
file() {
142156
path="$1"; shift
143157

0 commit comments

Comments
 (0)