2023-03-23 16:05:37 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2024-02-26 10:36:03 +00:00
|
|
|
echo "PWD: $PWD"
|
|
|
|
ls -l
|
|
|
|
ls -l target
|
2024-07-30 07:11:27 +01:00
|
|
|
SKIP="./target/debug/skip"
|
2023-03-23 16:05:37 +00:00
|
|
|
DIFF="diff -u --color"
|
|
|
|
|
2024-07-30 07:11:27 +01:00
|
|
|
if test ! -x $SKIP; then
|
|
|
|
echo "File missing: $SKIP - try 'cargo build'"
|
|
|
|
exit 1
|
2023-03-23 16:05:37 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo "> skip a line when reading from stdin"
|
2024-07-30 07:11:27 +01:00
|
|
|
INPUT=$(
|
|
|
|
cat <<EOF
|
2023-03-23 16:05:37 +00:00
|
|
|
line 1
|
|
|
|
line 2
|
|
|
|
EOF
|
|
|
|
)
|
2024-07-30 07:11:27 +01:00
|
|
|
echo "line 2" >test.expect
|
|
|
|
echo "$INPUT" | $SKIP 1 >test.out
|
2023-03-23 16:05:37 +00:00
|
|
|
$DIFF test.expect test.out
|
|
|
|
rm test.expect test.out
|
|
|
|
|
|
|
|
echo "> skip a line when reading from a file"
|
2024-07-30 07:11:27 +01:00
|
|
|
cat <<EOF >test.in
|
2023-03-23 16:05:37 +00:00
|
|
|
line 1
|
|
|
|
line 2
|
|
|
|
EOF
|
2024-07-30 07:11:27 +01:00
|
|
|
echo "line 2" >test.expect
|
|
|
|
$SKIP 1 test.in >test.out
|
2023-03-23 16:05:37 +00:00
|
|
|
$DIFF test.expect test.out
|
|
|
|
rm test.expect test.out
|
|
|
|
|
|
|
|
echo "> skip until 2 matching lines seen"
|
2024-07-30 07:11:27 +01:00
|
|
|
cat <<EOF >test.in
|
2023-03-23 16:05:37 +00:00
|
|
|
alpha
|
|
|
|
beta
|
|
|
|
alpha
|
|
|
|
alpha
|
|
|
|
gamma
|
|
|
|
alpha
|
|
|
|
EOF
|
2024-07-30 07:11:27 +01:00
|
|
|
cat <<EOF >test.expect
|
2023-03-23 16:05:37 +00:00
|
|
|
alpha
|
|
|
|
gamma
|
|
|
|
alpha
|
|
|
|
EOF
|
2024-07-30 07:11:27 +01:00
|
|
|
$SKIP 2 test.in --line alpha >test.out
|
2023-03-23 16:05:37 +00:00
|
|
|
$DIFF test.expect test.out
|
|
|
|
rm test.in test.expect test.out
|
|
|
|
|
|
|
|
echo "> skip lines until 2 tokens seen"
|
2024-07-30 07:11:27 +01:00
|
|
|
cat <<EOF >test.in
|
2023-03-23 16:05:37 +00:00
|
|
|
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
|
2024-07-30 07:11:27 +01:00
|
|
|
cat <<EOF >test.expect
|
2023-03-23 16:05:37 +00:00
|
|
|
Ut enim ad minim veniam,
|
|
|
|
quis nostrud exercitation ullamco
|
|
|
|
laboris nisi ut aliquip ex ea
|
|
|
|
commodo consequat.
|
|
|
|
EOF
|
2024-07-30 07:11:27 +01:00
|
|
|
$SKIP 2 test.in --token dolor >test.out
|
2023-03-23 16:05:37 +00:00
|
|
|
$DIFF test.expect test.out
|
|
|
|
rm test.in test.expect test.out
|
|
|
|
|
|
|
|
echo "> handle unknown parameter with simple error message"
|
2024-07-30 07:11:27 +01:00
|
|
|
cat <<EOF >test.expect.err
|
2023-03-23 16:05:37 +00:00
|
|
|
error: unexpected argument '--foo' found
|
|
|
|
|
2024-01-23 19:17:11 +00:00
|
|
|
tip: to pass '--foo' as a value, use '-- --foo'
|
2023-03-23 16:05:37 +00:00
|
|
|
|
|
|
|
Usage: skip [OPTIONS] <LINES> [FILE]
|
|
|
|
|
|
|
|
For more information, try '--help'.
|
|
|
|
EOF
|
2024-07-30 07:11:27 +01:00
|
|
|
cat <<EOF >test.expect
|
2023-03-23 16:05:37 +00:00
|
|
|
EOF
|
|
|
|
touch test.out test.err
|
2024-07-30 07:11:27 +01:00
|
|
|
$SKIP --foo >test.out 2>test.err || true
|
2023-03-23 16:05:37 +00:00
|
|
|
$DIFF test.expect test.out
|
|
|
|
$DIFF test.expect.err test.err
|
|
|
|
rm test.expect test.out
|
|
|
|
rm test.expect.err test.err
|
|
|
|
|
|
|
|
echo "> handle ignore-extra when token is missing"
|
2024-07-30 07:11:27 +01:00
|
|
|
cat <<EOF >test.expect.err
|
2023-03-23 16:05:37 +00:00
|
|
|
error: the following required arguments were not provided:
|
|
|
|
--token <TOKEN>
|
|
|
|
<LINES>
|
|
|
|
|
|
|
|
Usage: skip --ignore-extras --token <TOKEN> <LINES> [FILE]
|
|
|
|
|
|
|
|
For more information, try '--help'.
|
|
|
|
EOF
|
2024-07-30 07:11:27 +01:00
|
|
|
cat <<EOF >test.expect
|
2023-03-23 16:05:37 +00:00
|
|
|
EOF
|
|
|
|
touch test.out test.err
|
2024-07-30 07:11:27 +01:00
|
|
|
$SKIP --ignore-extras >test.out 2>test.err || true
|
2023-03-23 16:05:37 +00:00
|
|
|
$DIFF test.expect test.out
|
|
|
|
$DIFF test.expect.err test.err
|
|
|
|
rm test.expect test.out
|
|
|
|
rm test.expect.err test.err
|
|
|
|
|
|
|
|
echo "> skip lines until 4 tokens seen - ignored extra tokens on same line"
|
2024-07-30 07:11:27 +01:00
|
|
|
cat <<EOF >test.in
|
2023-03-23 16:05:37 +00:00
|
|
|
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
|
2024-07-30 07:11:27 +01:00
|
|
|
cat <<EOF >test.expect
|
2023-03-23 16:05:37 +00:00
|
|
|
quis nostrud exercitation ullamco
|
|
|
|
laboris nisi ut aliquip ex ea
|
|
|
|
commodo consequat.
|
|
|
|
EOF
|
2024-07-30 07:11:27 +01:00
|
|
|
$SKIP 4 test.in --token m --ignore-extras >test.out
|
2023-03-23 16:05:37 +00:00
|
|
|
$DIFF test.expect test.out
|
|
|
|
rm test.in test.expect test.out
|
|
|
|
|
|
|
|
echo done
|