skip/test.sh

120 lines
2.5 KiB
Bash
Raw Normal View History

2022-01-01 15:49:17 +00:00
#!/usr/bin/env bash
set -e
SKIP="./zig-out/bin/skip"
2022-01-15 14:38:26 +00:00
DIFF="diff -u --color"
if test ! -x $SKIP ; then
echo "File missing: $SKIP - try 'zig build'"
exit 1
fi
2022-01-01 15:49:17 +00:00
echo "> skip a line when reading from stdin"
INPUT=$(cat<<EOF
line 1
line 2
EOF
)
echo "line 2" > test.expect
echo "$INPUT" | $SKIP 1 > test.out
$DIFF test.expect test.out
rm test.expect test.out
2022-01-01 15:49:17 +00:00
echo "> skip a line when reading from a file"
cat<<EOF > test.in
line 1
line 2
EOF
echo "line 2" > test.expect
$SKIP 1 test.in > test.out
$DIFF test.expect test.out
rm test.expect test.out
2022-01-01 15:49:17 +00:00
echo "> skip until 2 matching lines seen"
cat<<EOF > test.in
alpha
beta
alpha
2022-01-01 16:19:44 +00:00
alpha
2022-01-01 15:49:17 +00:00
gamma
2022-01-01 16:19:44 +00:00
alpha
EOF
cat<<EOF > test.expect
alpha
gamma
alpha
2022-01-01 15:49:17 +00:00
EOF
$SKIP 2 test.in --line alpha > test.out
$DIFF test.expect test.out
rm test.in test.expect test.out
2022-01-01 15:49:17 +00:00
echo "> skip lines until 2 tokens seen"
cat<<EOF > test.in
Lorem ipsum dolor sit amet,
consectetur adipiscing elit,
sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua.
Ut enim ad minim veniam,
quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea
commodo consequat.
EOF
cat<<EOF > test.expect
Ut enim ad minim veniam,
quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea
commodo consequat.
EOF
$SKIP 2 test.in --token dolor > test.out 2
$DIFF test.expect test.out
rm test.in test.expect test.out
2022-01-01 15:49:17 +00:00
echo "> handle unknown parameter with simple error message"
cat<<EOF > test.expect.err
Invalid argument '--foo'
EOF
cat<<EOF > test.expect
EOF
touch test.out test.err
$SKIP --foo > test.out 2> test.err
$DIFF test.expect test.out
$DIFF test.expect.err test.err
rm test.expect test.out
rm test.expect.err test.err
2022-01-14 07:48:47 +00:00
echo "> handle ignore-extra when token is missing"
cat<<EOF > test.expect.err
Error: --ignore-extras requires --token
EOF
cat<<EOF > test.expect
EOF
touch test.out test.err
$SKIP --ignore-extras > test.out 2> test.err
$DIFF test.expect test.out
$DIFF test.expect.err test.err
2022-01-14 07:48:47 +00:00
rm test.expect test.out
rm test.expect.err test.err
2022-01-14 08:01:59 +00:00
echo "> skip lines until 4 tokens seen - ignored extra tokens on same line"
2022-01-14 07:06:08 +00:00
cat<<EOF > test.in
Lorem ipsum dolor sit amet,
consectetur adipiscing elit,
sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua.
Ut enim ad minim veniam,
quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea
commodo consequat.
EOF
cat<<EOF > test.expect
quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea
commodo consequat.
EOF
$SKIP 4 test.in --token m --ignore-extras > test.out
$DIFF test.expect test.out
rm test.in test.expect test.out
2022-01-01 15:49:17 +00:00
echo done