about summary refs log tree commit diff
path: root/t
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2017-11-01 17:43:44 +0100
committerLeah Neukirchen <leah@vuxu.org>2017-11-01 17:43:44 +0100
commit2afc62578a26989713acebe085bbdcb8616069d6 (patch)
tree208d1f2aafd6e8f9070509df987f31a7c1357cb1 /t
parent478beee7c496dee2b21cfa22c7d984e376954f7b (diff)
downloadxe-2afc62578a26989713acebe085bbdcb8616069d6.tar.gz
xe-2afc62578a26989713acebe085bbdcb8616069d6.tar.xz
xe-2afc62578a26989713acebe085bbdcb8616069d6.zip
convert test suite to tap3 and split into multiple files
Diffstat (limited to 't')
-rwxr-xr-xt/errors.t104
-rwxr-xr-xt/limits.t24
-rwxr-xr-xt/percent.t110
-rwxr-xr-xt/regressions.t14
-rwxr-xr-xt/simple.t269
-rwxr-xr-xt/slow.t43
6 files changed, 564 insertions, 0 deletions
diff --git a/t/errors.t b/t/errors.t
new file mode 100755
index 0000000..c2ecd5e
--- /dev/null
+++ b/t/errors.t
@@ -0,0 +1,104 @@
+#!/bin/sh
+export "PATH=.:$PATH"
+
+printf '1..13\n'
+printf '# error handling\n'
+
+tap3 'exit code on success' <<'EOF'
+xe
+>>>= 0
+EOF
+
+tap3 'exit code on other error' <<'EOF'
+true | xe -j NaN
+>>>= 1
+EOF
+
+tap3 'exit code on when command fails with 1-125' <<'EOF'
+xe -s 'exit 42'
+<<<
+a
+>>>= 123
+EOF
+
+tap3 'exit code on when command fails with 255' <<'EOF'
+xe -s 'exit 255'
+<<<
+a
+>>>= 124
+EOF
+
+tap3 'exit code when process was killed' <<'EOF'
+xe perl -e 'kill "KILL", $$'
+<<<
+a
+>>>= 125
+EOF
+
+# possible false positive result when exec returns ENOENT instead of ENOTDIR here
+tap3 'exit code when command cannot be run' <<'EOF'
+xe /dev/null/calc.exe
+<<<
+a
+>>>= 126
+EOF
+
+tap3 'exit code when command was not found' <<'EOF'
+xe /bin/calc.exe
+<<<
+a
+>>>= 127
+EOF
+
+tap3 'exit code on empty input when run with -R' <<'EOF'
+xe -R echo a
+>>>= 122
+EOF
+
+tap3 'doesn'\''t stop on errors by default' <<'EOF'
+xe -s 'if [ b = $1 ]; then false; else echo $1; fi'
+<<<
+a
+b
+c
+>>>
+a
+c
+>>>= 123
+EOF
+
+tap3 'stops on first error with -F' <<'EOF'
+xe -F -s 'if [ b = $1 ]; then false; else echo $1; fi'
+<<<
+a
+b
+c
+>>>
+a
+>>>= 123
+EOF
+
+tap3 'should close stdin when arguments were read from it' <<'EOF'
+xe -s 'sed q'
+<<<
+a
+b
+c
+>>>
+EOF
+
+tap3 'should not close stdin when arguments were read from command line' <<'EOF'
+yes | xe -a -s "sed q" -- 1 2 3
+>>>
+y
+y
+y
+EOF
+
+tap3 'should not close stdin when arguments were read from file' <<'EOF'
+yes | xe -f NEWS.md -s 'sed q' 2>&1 | sed 3q
+>>>
+y
+y
+y
+EOF
diff --git a/t/limits.t b/t/limits.t
new file mode 100755
index 0000000..8692a2e
--- /dev/null
+++ b/t/limits.t
@@ -0,0 +1,24 @@
+#!/bin/sh
+export "PATH=.:$PATH"
+
+printf '1..2\n'
+printf '# limit checks, expecting maximal POSIX limits available\n'
+
+tap3 'argscap check' <<'EOF'
+dd if=/dev/zero bs=1 count=17711 2>/dev/null |
+	tr "\0" "\012" |
+	xe -N0 -s 'echo $#'
+>>>
+8187
+8187
+1337
+EOF
+
+tap3 'argslen check' <<'EOF'
+perl -e 'print "x"x8000, "\n" for 1..42' |
+	xe -N0 -s 'echo $#'
+>>>
+16
+16
+10
+EOF
diff --git a/t/percent.t b/t/percent.t
new file mode 100755
index 0000000..c3b97b7
--- /dev/null
+++ b/t/percent.t
@@ -0,0 +1,110 @@
+#!/bin/sh
+export "PATH=.:$PATH"
+
+printf '1..13\n'
+printf '# percent rules\n'
+
+tap3 'literal matches' <<'EOF'
+xe -ap bcd echo found -- abc bcd defg
+>>>
+found
+EOF
+
+tap3 'multiple patterns' <<'EOF'
+xe -ap one echo 1 + two echo 2 + three echo 3 -- zero one two three four five
+>>>
+1
+2
+3
+EOF
+
+tap3 '{} expansion' <<'EOF'
+xe -ap bcd echo {} -- abc bcd defg
+>>>
+bcd
+EOF
+
+tap3 '% expansion' <<'EOF'
+xe -ap bcd echo % -- abc bcd defg
+>>>
+bcd
+EOF
+
+tap3 'dirnames' <<'EOF'
+xe -ap bcd echo % -- abc bcd /tmp/bcd /tmp/abc
+>>>
+bcd
+/tmp/bcd
+EOF
+
+tap3 '? glob' <<'EOF'
+xe -ap "b?d" echo % -- abc bcd b3d defg
+>>>
+bcd
+b3d
+EOF
+
+tap3 '* glob' <<'EOF'
+xe -ap "b*d" echo % -- bd bed bad bugged bx zbd b/d
+>>>
+bd
+bed
+bad
+bugged
+EOF
+
+tap3 'multiple * glob' <<'EOF'
+xe -ap "b*g*d" echo % -- bd bed bugged bx zbd bagdad badger ba/gd/ad
+>>>
+bugged
+bagdad
+EOF
+
+tap3 'multiple ** glob' <<'EOF'
+xe -ap "b**g**d" echo % -- bd bed bugged bx zbd bagdad badger ba/gd/ad
+>>>
+bugged
+bagdad
+ba/gd/ad
+EOF
+
+tap3 '/ slash' <<'EOF'
+xe -ap a/b echo 1 + c///d echo 2 + "*" echo 3 -- a/b a//b a/ b c/d /c////d
+>>>
+1
+1
+3
+3
+2
+3
+EOF
+
+tap3 '[] ranges' <<'EOF'
+xe -ap "[abc]" echo "1%" + "[d-g]" echo "2%" + "[^xyz-]" echo "3%" + "[!-vw]" echo "4%" + % echo "5%" -- a c d e g h w x -
+>>>
+1a
+1c
+2d
+2e
+2g
+3h
+3w
+4x
+5-
+EOF
+
+tap3 '{} alternation' <<'EOF'
+xe -ap "{a,bc,def*}" echo % -- x a abc bc bcd def defx xdef
+>>>
+a
+bc
+def
+defx
+EOF
+
+tap3 '% match' <<'EOF'
+xe -ap %.c echo obj/%.o -- foo.c bar.cc meh/quux.c
+>>>
+obj/foo.o
+meh/obj/quux.o
+EOF
diff --git a/t/regressions.t b/t/regressions.t
new file mode 100755
index 0000000..9b50585
--- /dev/null
+++ b/t/regressions.t
@@ -0,0 +1,14 @@
+#!/bin/sh
+export "PATH=.:$PATH"
+
+printf '1..1\n'
+printf '# regressions\n'
+
+tap3 '0fb64a4 quoting of empty strings' <<'EOF'
+xe -N2 -v true
+<<<
+foo
+
+>>>2
+true foo ''
+EOF
diff --git a/t/simple.t b/t/simple.t
new file mode 100755
index 0000000..b418d39
--- /dev/null
+++ b/t/simple.t
@@ -0,0 +1,269 @@
+#!/bin/sh
+export "PATH=.:$PATH"
+
+printf '1..27\n'
+printf '# simple tests\n'
+
+tap3 'single argument run' <<'EOF'
+xe echo
+<<<
+1
+2
+3
+>>>
+1
+2
+3
+EOF
+
+tap3 'dual argument run' <<'EOF'
+xe -N2 echo
+<<<
+1
+2
+3
+4
+5
+>>>
+1 2
+3 4
+5
+EOF
+
+tap3 'unlimited argument run' <<'EOF'
+xe -N0 echo
+<<<
+1
+2
+3
+4
+5
+>>>
+1 2 3 4 5
+EOF
+
+tap3 'empty input run' <<'EOF'
+true | xe echo a
+>>>
+EOF
+
+tap3 'dry run' <<'EOF'
+xe -n echo x
+<<<
+a
+b
+c
+>>>2
+echo x a
+echo x b
+echo x c
+EOF
+
+tap3 'dry run quoting' <<'EOF'
+xe -n echo x
+<<<
+a
+b b
+c
+>>>2
+echo x a
+echo x 'b b'
+echo x c
+EOF
+
+tap3 'verbose run' <<'EOF'
+xe -v echo x
+<<<
+a
+b
+c
+>>>
+x a
+x b
+x c
+>>>2
+echo x a
+echo x b
+echo x c
+EOF
+
+tap3 'with no command' <<'EOF'
+xe -N2
+<<<
+1
+2
+3
+>>>
+1
+2
+3
+EOF
+
+tap3 'using {}' <<'EOF'
+xe echo a {} x
+<<<
+1
+2
+3
+>>>
+a 1 x
+a 2 x
+a 3 x
+EOF
+
+tap3 'using {} twice' <<'EOF'
+xe echo {} x {}
+<<<
+1
+2
+3
+>>>
+1 x {}
+2 x {}
+3 x {}
+EOF
+
+tap3 'using -I%' <<'EOF'
+xe -I% echo {} x %
+<<<
+1
+2
+3
+>>>
+{} x 1
+{} x 2
+{} x 3
+EOF
+
+tap3 'using -I "" to disable' <<'EOF'
+xe -I "" echo {} x %
+<<<
+1
+2
+3
+>>>
+{} x % 1
+{} x % 2
+{} x % 3
+EOF
+
+tap3 'using {} with multiple arguments' <<'EOF'
+xe -N2 echo a {} x {}
+<<<
+1
+2
+3
+>>>
+a 1 2 x {}
+a 3 x {}
+EOF
+
+tap3 'using -0' <<'EOF'
+printf "foo\0bar\0quux" | xe -0 echo
+>>>
+foo
+bar
+quux
+EOF
+
+tap3 'using -a' <<'EOF'
+xe -a echo -- 1 2 3
+>>>
+1
+2
+3
+EOF
+
+tap3 'using -a with no arguments' <<'EOF'
+xe -a echo
+>>>
+EOF
+
+tap3 'using -a with no command' <<'EOF'
+xe -N2 -a -- 1 2 3
+>>>
+1
+2
+3
+EOF
+
+tap3 'using -A%' <<'EOF'
+xe -A% echo -- % 1 2 3
+>>>
+-- 1
+-- 2
+-- 3
+EOF
+
+tap3 'using -A% with no arguments' <<'EOF'
+xe -A% echo
+>>>2
+xe: '-A %' used but no separator '%' found in command line.
+EOF
+
+tap3 'using -A% with no command' <<'EOF'
+xe -N2 -A% % 1 2 3
+>>>
+1
+2
+3
+EOF
+
+tap3 'using -f' <<'EOF'
+echo notme | xe -f Makefile echo
+>>> /DESTDIR/
+EOF
+
+tap3 'using -s' <<'EOF'
+xe -s 'echo x$1'
+<<<
+1
+2
+3
+>>>
+x1
+x2
+x3
+EOF
+
+tap3 'using -s with -N0' <<'EOF'
+xe -N0 -s 'echo x$@'
+<<<
+1
+2
+3
+>>>
+x1 2 3
+EOF
+
+tap3 'using -s with -a' <<'EOF'
+xe -s 'echo x$@' -a 1 2 3
+>>>
+x1
+x2
+x3
+EOF
+
+tap3 'using -s with -a' <<'EOF'
+xe -a -s 'echo x$@' 1 2 3
+>>>
+x1
+x2
+x3
+EOF
+
+tap3 'using -s with -a' <<'EOF'
+xe -a -s 'echo x$@' -- 1 2 3
+>>>
+x1
+x2
+x3
+EOF
+
+tap3 'with ITER' <<'EOF'
+xe -a -s 'echo $ITER' -- a b c
+>>>
+1
+2
+3
+EOF
diff --git a/t/slow.t b/t/slow.t
new file mode 100755
index 0000000..74ba2e9
--- /dev/null
+++ b/t/slow.t
@@ -0,0 +1,43 @@
+#!/bin/sh
+export "PATH=.:$PATH"
+
+printf '1..4\n'
+printf '# slow tests\n'
+
+tap3 'is eager' <<'EOF'
+{ { echo 1; sleep 1; echo 11 >/dev/stderr; echo 2; } | xe echo; } 2>&1
+>>>
+1
+11
+2
+EOF
+
+tap3 'using -L' <<'EOF'
+{ echo 1; sleep 1;
+  echo 2; sleep 1;
+  echo 3; } |
+	xe -j2 -L -s 'printf $1; sleep 1; echo $1'
+>>>
+11
+22
+33
+EOF
+
+tap3 'using -LL' <<'EOF'
+{ echo 1; sleep 1;
+  echo 2; sleep 1;
+  echo 3; } |
+	xe -j2 -LL -s 'printf $1; sleep 1; echo $1'
+>>>
+0001= 11
+0002= 22
+0003= 33
+EOF
+
+tap3 'using -vvL' <<'EOF'
+{ echo 1; sleep 1;
+  echo 2; sleep 1;
+  echo 3; } |
+	xe -j2 -vvL -s 'printf %s $1; sleep 1; echo $1' | wc -l
+>>> /\s*9$/
+EOF