commit: e4803c94a407974c8edcda4c4d23b65e4afdbd6b
parent dc6923434f5a5eeaea8c429321ecbfd47e5e27fe
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Sat, 12 Apr 2025 20:15:50 +0200
test-cmd/seq: add tests for -w (constant width)
Diffstat:
M | test-cmd/seq.sh | 85 | ++++++++++++++++++++++++++++++++++++------------------------------------------- |
1 file changed, 39 insertions(+), 46 deletions(-)
diff --git a/test-cmd/seq.sh b/test-cmd/seq.sh
@@ -2,55 +2,48 @@
# SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
# SPDX-License-Identifier: MPL-2.0
-seq="$(dirname "$0")/../cmd/seq"
-
-t ()
-{
- # $1 -> $test expression
- # $2 -> expected output
-
- count=$((count+1))
- out="$("$seq" -s, -- $1 2>&1)"
- ret="$?"
- if [ "$?" != 0 ]; then
- printf 'not ok %s - %s\n' "$count $1" "$out"
- elif [ "$out" != "$2" ]; then
- printf 'not ok %s - (%s != %s)\n' "$count $1" "$out" "$2"
- else
- printf 'ok %s\n' "$count $1"
- fi
-}
-
-count=0
-
-echo '1..20'
+WD="$(dirname "$0")/../"
+target="${WD}/cmd/seq"
+plans=27
+. "${WD}/test-cmd/tap.sh"
# One arg
-t 1 '1'
-t 5 '1,2,3,4,5'
-t -1 '1,0,-1'
-t -5 '1,0,-1,-2,-3,-4,-5'
+t_args 1 '1' -s, -t '' 1
+t_args 5 '1,2,3,4,5' -s, -t '' 5
+t_args n1 '1,0,-1' -s, -t '' -- -1
+t_args n5 '1,0,-1,-2,-3,-4,-5' -s, -t '' -- -5
# Two args
-t '0 1' '0,1'
-t '0 5' '0,1,2,3,4,5'
-t '10 15' '10,11,12,13,14,15'
-t '2 -2' '2,1,0,-1,-2'
-t '-2 2' '-2,-1,0,1,2'
+t_args 0_1 '0,1' -s, -t '' 0 1
+t_args 0_5 '0,1,2,3,4,5' -s, -t '' 0 5
+t_args 10_15 '10,11,12,13,14,15' -s, -t '' 10 15
+t_args 2_n2 '2,1,0,-1,-2' -s, -t '' 2 -2
+t_args n2_2 '-2,-1,0,1,2' -s, -t '' -- -2 2
# Three args
-t '0 1 1' '0,1'
-t '0 1 5' '0,1,2,3,4,5'
-t '10 1 15' '10,11,12,13,14,15'
-
-t '0 2 5' '0,2,4'
-t '10 2 15' '10,12,14'
-
-t '0 1 -1' '0,-1'
-t '0 1 -5' '0,-1,-2,-3,-4,-5'
-t '-10 1 -15' '-10,-11,-12,-13,-14,-15'
-
-t '0 -1 -1' '0,-1'
-
-t '0 2 -5' '0,-2,-4'
-t '-10 2 -15' '-10,-12,-14'
+t_args 0_1_1 '0,1' -s, -t '' 0 1 1
+t_args 0_1_5 '0,1,2,3,4,5' -s, -t '' 0 1 5
+t_args 10_1_15 '10,11,12,13,14,15' -s, -t '' 10 1 15
+
+t_args 0_2_5 '0,2,4' -s, -t '' 0 2 5
+t_args 10_2_15 '10,12,14' -s, -t '' 10 2 15
+
+t_args 0_1_n1 '0,-1' -s, -t '' 0 1 -1
+t_args 0_1_n5 '0,-1,-2,-3,-4,-5' -s, -t '' 0 1 -5
+t_args n10_1_n15 '-10,-11,-12,-13,-14,-15' -s, -t '' -- -10 1 -15
+
+t_args 0_n1_n1 '0,-1' -s, -t '' 0 -1 -1
+
+t_args 0_2_n5 '0,-2,-4' -s, -t '' 0 2 -5
+t_args n10_2_n15 '-10,-12,-14' -s, -t '' -- -10 2 -15
+
+# == constant width ==
+t_args w:1 '1' -s, -t '' -w 1
+t_args w:5 '01,00,-1,-2,-3,-4,-5' -s, -t '' -w -- -5
+# -w two args
+t_args w:0_5 '0,1,2,3,4,5' -s, -t '' -w 0 5
+t_args w:2_n2 '02,01,00,-1,-2' -s, -t '' -w 2 -2
+# -w three args
+t_args w:0_1_5 '0,1,2,3,4,5' -s, -t '' -w 0 1 5
+t_args w:0_2_n5 '00,-2,-4' -s, -t '' -w 0 2 -5
+t_args w:n10_2_n15 '-10,-12,-14' -s, -t '' -w -- -10 2 -15