logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git
commit: 4d35492396ed5095667db243da663f77394dce4f
parent a3a4ff8fc4b9f267ca1081ebb92e5d07152d6863
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Sat, 28 Sep 2024 13:11:57 +0200

test-cmd/mktemp.sh: test -u option

Diffstat:

Mtest-cmd/mktemp.sh18+++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/test-cmd/mktemp.sh b/test-cmd/mktemp.sh @@ -3,7 +3,7 @@ # SPDX-License-Identifier: MPL-2.0 target="$(dirname "$0")/../cmd/mktemp" -plans=8 +plans=12 . "$(dirname "$0")/tap.sh" t_mktemp() @@ -72,3 +72,19 @@ t_mkdtemp dir_tmpdir '-dt' t --exit=1 templ2 'foo bar' 'mktemp: error: Only one template argument is supported, got 2 ' + +cmd_mktemp_u() { + if tmpfile=$("$target" "$@"); then + if test -e "$tmpfile"; then + printf '# Unexpectedly created a file: %s\n' "$tmpfile" + return 1 + fi + return 0 + else + return 1 + fi +} +t_cmd unsafe:file '' cmd_mktemp_u -u +t_cmd unsafe:file_template '' cmd_mktemp_u -u template.XXXXXX +t_cmd unsafe:dir '' cmd_mktemp_u -u -d +t_cmd unsafe:dir_template '' cmd_mktemp_u -u -d template.XXXXXX