test: work with skip in zig-out and show diff on error

This commit is contained in:
Paul Campbell 2022-01-15 14:29:27 +00:00
parent a90d17bb97
commit 2f3bf35b02

40
test.sh
View file

@ -2,6 +2,14 @@
set -e set -e
SKIP="./zig-out/bin/skip"
DIFF="diff -u"
if test ! -x $SKIP ; then
echo "File missing: $SKIP - try 'zig build'"
exit 1
fi
echo "> skip a line when reading from stdin" echo "> skip a line when reading from stdin"
INPUT=$(cat<<EOF INPUT=$(cat<<EOF
line 1 line 1
@ -9,8 +17,8 @@ line 2
EOF EOF
) )
echo "line 2" > test.expect echo "line 2" > test.expect
echo "$INPUT" | ./skip 1 > test.out echo "$INPUT" | $SKIP 1 > test.out
diff --brief test.expect test.out $DIFF test.expect test.out
rm test.expect test.out rm test.expect test.out
echo "> skip a line when reading from a file" echo "> skip a line when reading from a file"
@ -19,8 +27,8 @@ line 1
line 2 line 2
EOF EOF
echo "line 2" > test.expect echo "line 2" > test.expect
./skip 1 test.in > test.out $SKIP 1 test.in > test.out
diff --brief test.expect test.out $DIFF test.expect test.out
rm test.expect test.out rm test.expect test.out
echo "> skip until 2 matching lines seen" echo "> skip until 2 matching lines seen"
@ -37,8 +45,8 @@ alpha
gamma gamma
alpha alpha
EOF EOF
./skip 2 test.in --line alpha > test.out $SKIP 2 test.in --line alpha > test.out
diff --brief test.expect test.out $DIFF test.expect test.out
rm test.in test.expect test.out rm test.in test.expect test.out
echo "> skip lines until 2 tokens seen" echo "> skip lines until 2 tokens seen"
@ -58,8 +66,8 @@ quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea laboris nisi ut aliquip ex ea
commodo consequat. commodo consequat.
EOF EOF
./skip 2 test.in --token dolor > test.out 2 $SKIP 2 test.in --token dolor > test.out 2
diff --brief test.expect test.out $DIFF test.expect test.out
rm test.in test.expect test.out rm test.in test.expect test.out
echo "> handle unknown parameter with simple error message" echo "> handle unknown parameter with simple error message"
@ -69,9 +77,9 @@ EOF
cat<<EOF > test.expect cat<<EOF > test.expect
EOF EOF
touch test.out test.err touch test.out test.err
./skip --foo > test.out 2> test.err $SKIP --foo > test.out 2> test.err
diff --brief test.expect test.out $DIFF test.expect test.out
diff --brief test.expect.err test.err $DIFF test.expect.err test.err
rm test.expect test.out rm test.expect test.out
rm test.expect.err test.err rm test.expect.err test.err
@ -82,9 +90,9 @@ EOF
cat<<EOF > test.expect cat<<EOF > test.expect
EOF EOF
touch test.out test.err touch test.out test.err
./skip --ignore-extras > test.out 2> test.err $SKIP --ignore-extras > test.out 2> test.err
diff --brief test.expect test.out $DIFF test.expect test.out
diff --brief test.expect.err test.err $DIFF test.expect.err test.err
rm test.expect test.out rm test.expect test.out
rm test.expect.err test.err rm test.expect.err test.err
@ -104,8 +112,8 @@ quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea laboris nisi ut aliquip ex ea
commodo consequat. commodo consequat.
EOF EOF
./skip 4 test.in --token m --ignore-extras > test.out $SKIP 4 test.in --token m --ignore-extras > test.out
diff --brief test.expect test.out $DIFF test.expect test.out
rm test.in test.expect test.out rm test.in test.expect test.out
echo done echo done