commit: 19fa609e5fe79fcc4bf9da25083ea3e70a915021
parent 527aa1b98bffb7e3414cf51e45f2bdb42ae7349e
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Sat, 8 Mar 2025 05:58:56 +0100
test-cmd/mktemp.sh: don't split args in t_mktemp and t_mkdtemp
Diffstat:
1 file changed, 22 insertions(+), 18 deletions(-)
diff --git a/test-cmd/mktemp.sh b/test-cmd/mktemp.sh
@@ -9,11 +9,12 @@ plans=12
t_mktemp()
{
count=$((count+1))
+ name="$1" ; shift
# Append a final slash so sh(1) doesn't trims final newlines
- out="$("${target?}" $2 2>&1;r=$?;printf %s /;exit $r)"
- ret="$?"
- out="${out%/}"
+ out=$("${target?}" "$@" 2>&1;r=$?;printf %s /;exit $r)
+ ret=$?
+ out=${out%/}
test -f "${out%
}"
@@ -23,9 +24,9 @@ t_mktemp()
}"
if [ "$ret" = 0 ] && [ "$test_ret" = 0 ]; then
- printf 'ok %d - %s\n' "$count" "$1"
+ printf 'ok %d - %s\n' "$count" "$name"
else
- printf 'not ok %d - %s\n' "$count" "$1"
+ printf 'not ok %d - %s\n' "$count" "$name"
printf '# exit code: %d\n' "$ret"
printf '# test -f => %d\n' "$test_ret"
err=1
@@ -36,11 +37,12 @@ t_mktemp()
t_mkdtemp()
{
count=$((count+1))
+ name="$1" ; shift
# Append a final slash so sh(1) doesn't trims final newlines
- out="$("${target?}" $2 2>&1;r=$?;printf %s /;exit $r)"
- ret="$?"
- out="${out%/}"
+ out=$("${target?}" "$@" 2>&1;r=$?;printf %s /;exit $r)
+ ret=$?
+ out=${out%/}
test -d "${out%
}"
@@ -50,9 +52,9 @@ t_mkdtemp()
}"
if [ "$ret" = 0 ] && [ "$test_ret" = 0 ]; then
- printf 'ok %d - %s\n' "$count" "$1"
+ printf 'ok %d - %s\n' "$count" "$name"
else
- printf 'not ok %d - %s\n' "$count" "$1"
+ printf 'not ok %d - %s\n' "$count" "$name"
printf '# exit code: %d\n' "$ret"
printf '# test -d => %d\n' "$test_ret"
err=1
@@ -62,13 +64,13 @@ t_mkdtemp()
# TODO: Figure a way to do harsher tests, for example testing patterns, directory contents, …
-t_mktemp noargs ''
-t_mktemp template 'template.XXXXXX'
-t_mktemp tmpdir '-t'
-t_mktemp tmpdir '-t template.XXXXXX'
-t_mkdtemp dir '-d'
-t_mkdtemp dir_template '-d template.XXXXXX'
-t_mkdtemp dir_tmpdir '-dt'
+t_mktemp noargs
+t_mktemp template template.XXXXXX
+t_mktemp tmpdir -t
+t_mktemp tmpdir -t template.XXXXXX
+t_mkdtemp dir -d
+t_mkdtemp dir_template -d template.XXXXXX
+t_mkdtemp dir_tmpdir -dt
t --exit=1 templ2 'foo bar' 'mktemp: error: Only one template argument is supported, got 2
'
@@ -76,7 +78,9 @@ t --exit=1 templ2 'foo bar' 'mktemp: error: Only one template argument is suppor
cmd_mktemp_u() {
if tmpfile=$("$target" "$@"); then
if test -e "$tmpfile"; then
- printf '# Unexpectedly created a file: %s\n' "$tmpfile"
+ printf '# Unexpectedly created a file:\n' "$tmpfile"
+ ls -l "$tmpfile" 2>&1 | sed 's;^;# ;'
+ rm -fr "$tmpfile" 2>&1 | sed 's;^;# ;'
return 1
fi
return 0