commit: ed2b045831035e538ae01dbcded9f33e538b8052
parent c2179f305dc26ac781641c314151aed4b6c35d82
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Fri, 13 Sep 2024 03:22:25 +0200
test-cmd: don't split arguments in t_file
Diffstat:
4 files changed, 23 insertions(+), 23 deletions(-)
diff --git a/test-cmd/base64.sh b/test-cmd/base64.sh
@@ -32,13 +32,13 @@ t --input='Zm9vYg==\n' 'rfc4648_decode:Zm9vYg==\n' '-d' 'foob'
t --input='Zm9vYmE=\n' 'rfc4648_decode:Zm9vYmE=\n' '-d' 'fooba'
t --input='Zm9vYmFy\n' 'rfc4648_decode:Zm9vYmFy\n' '-d' 'foobar'
-t_file multiliner_encode "$WD/inputs/all_bytes" "$WD/outputs/base64/all_bytes_w76"
+t_file multiliner_encode "$WD/outputs/base64/all_bytes_w76" "$WD/inputs/all_bytes"
-t_file multiliner_decode "-d $WD/outputs/base64/all_bytes_w76" "$WD/inputs/all_bytes"
+t_file multiliner_decode "$WD/inputs/all_bytes" -d "$WD/outputs/base64/all_bytes_w76"
-t_file oneliner_encode "-w0 $WD/inputs/all_bytes" "$WD/outputs/base64/all_bytes_w0"
+t_file oneliner_encode "$WD/outputs/base64/all_bytes_w0" -w0 "$WD/inputs/all_bytes"
-t_file oneliner_decode "-d -w0 $WD/outputs/base64/all_bytes_w0" "$WD/inputs/all_bytes"
+t_file oneliner_decode "$WD/inputs/all_bytes" -d -w0 "$WD/outputs/base64/all_bytes_w0"
if [ "$(id -u)" = 0 ]
then
diff --git a/test-cmd/cat.sh b/test-cmd/cat.sh
@@ -45,7 +45,7 @@ fi
t --exit=1 enoent /var/empty/e/no/ent 'cat: Error opening ‘/var/empty/e/no/ent’: No such file or directory
'
-t_file doubledash "-- $WD/inputs/all_bytes" "$WD/inputs/all_bytes"
+t_file doubledash "$WD/inputs/all_bytes" -- "$WD/inputs/all_bytes"
t --exit=1 tripledash "--- $WD/inputs/all_bytes" "cat: Error: Unrecognised option: '--'
Usage: cat [-u] [files ...]
diff --git a/test-cmd/strings.sh b/test-cmd/strings.sh
@@ -14,7 +14,7 @@ t --exit=1 usage "-t aa $WD/inputs/all_bytes" "${usage}"
t devnull /dev/null ''
-t_file all_bytes "$WD/inputs/all_bytes" "$WD/outputs/strings/all_bytes"
+t_file all_bytes "$WD/outputs/strings/all_bytes" "$WD/inputs/all_bytes"
t default "${WD}/inputs/strings/length" '___4
____5
@@ -43,19 +43,19 @@ t z8 "-z -n 8 ${WD}/inputs/strings/length" "$(printf '_______8\0________9\0')"
#}
t octal:devnull '-to /dev/null' ''
-t_file octal:all_bytes "-to $WD/inputs/all_bytes" "$WD/outputs/strings/all_bytes_to"
-t_file octal:lengthelf "-to $WD/inputs/strings/length" "$WD/outputs/strings/length_to"
-t_file octal:length8elf "-to -n 8 $WD/inputs/strings/length" "$WD/outputs/strings/length_8_to"
+t_file octal:all_bytes "$WD/outputs/strings/all_bytes_to" -to "$WD/inputs/all_bytes"
+t_file octal:lengthelf "$WD/outputs/strings/length_to" -to "$WD/inputs/strings/length"
+t_file octal:length8elf "$WD/outputs/strings/length_8_to" -to -n 8 "$WD/inputs/strings/length"
t hex:devnull '-tx /dev/null' ''
-t_file hex:all_bytes "-tx $WD/inputs/all_bytes" "$WD/outputs/strings/all_bytes_tx"
-t_file hex:lengthelf "-tx $WD/inputs/strings/length" "$WD/outputs/strings/length_tx"
-t_file hex:length8elf "-tx -n 8 $WD/inputs/strings/length" "$WD/outputs/strings/length_8_tx"
+t_file hex:all_bytes "$WD/outputs/strings/all_bytes_tx" -tx "$WD/inputs/all_bytes"
+t_file hex:lengthelf "$WD/outputs/strings/length_tx" -tx "$WD/inputs/strings/length"
+t_file hex:length8elf "$WD/outputs/strings/length_8_tx" -tx -n 8 "$WD/inputs/strings/length"
t dec:devnull '-td /dev/null' ''
-t_file dec:all_bytes "-td $WD/inputs/all_bytes" "$WD/outputs/strings/all_bytes_td"
-t_file dec:lengthelf "-td $WD/inputs/strings/length" "$WD/outputs/strings/length_td"
-t_file dec:length8elf "-td -n 8 $WD/inputs/strings/length" "$WD/outputs/strings/length_8_td"
+t_file dec:all_bytes "$WD/outputs/strings/all_bytes_td" -td "$WD/inputs/all_bytes"
+t_file dec:lengthelf "$WD/outputs/strings/length_td" -td "$WD/inputs/strings/length"
+t_file dec:length8elf "$WD/outputs/strings/length_8_td" -td -n 8 "$WD/inputs/strings/length"
fmt_t="strings: Unknown format: t
${usage}"
diff --git a/test-cmd/tap.sh b/test-cmd/tap.sh
@@ -125,33 +125,33 @@ t_args() {
fi
}
-# $1 -> name
-# $2 -> arguments
-# $3 -> file to compare output against
+# t_file <test_name> <file_expected> <arguments ...>
+# file_expected is an existing file to compare output against
t_file()
{
exp_ret=0
- file="${3?}"
+ name="$1"; shift
+ file="$1"; shift
command -v mktemp >/dev/null 2>/dev/null || \
skip $1 "t_file requires mktemp(1)"
count=$((count+1))
out="$(mktemp)"
- "${target?}" $2 2>&1 >"$out"
+ "${target?}" "$@" 2>&1 >"$out"
ret="$?"
if [ "$ret" != "$exp_ret" ]; then
- printf 'not ok %d - %s\n' "$count" "$1"
+ printf 'not ok %d - %s\n' "$count" "$name"
printf '# Expected exit code %d, got %d\n' "$exp_ret" "$ret"
printf "$out" | sed -e 's;^;# ;'
err=1
elif ! cmp -s "${out?}" "$file"; then
- printf 'not ok %d - %s\n' "$count" "$1"
+ printf 'not ok %d - %s\n' "$count" "$name"
diff -u "$out" "$file" | sed -e 's;^;# ;'
err=1
else
- printf 'ok %d - %s\n' "$count" "$1"
+ printf 'ok %d - %s\n' "$count" "$name"
rm "$out"
fi
}