skip/test.sh

132 lines
2.8 KiB
Bash
Raw Normal View History

2023-03-23 16:05:37 +00:00
#!/usr/bin/env bash
set -e
SKIP="./target/debug/skip"
DIFF="diff -u --color"
if test ! -x $SKIP ; then
2024-02-26 08:47:12 +00:00
echo "File missing: $SKIP - try 'cargo build'"
2023-03-23 16:05:37 +00:00
exit 1
fi
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
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
echo "> skip until 2 matching lines seen"
cat<<EOF > test.in
alpha
beta
alpha
alpha
gamma
alpha
EOF
cat<<EOF > test.expect
alpha
gamma
alpha
EOF
$SKIP 2 test.in --line alpha > test.out
$DIFF test.expect test.out
rm test.in test.expect test.out
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
$DIFF test.expect test.out
rm test.in test.expect test.out
echo "> handle unknown parameter with simple error message"
cat<<EOF > test.expect.err
error: unexpected argument '--foo' found
Update Rust crate clap to 4.4 (#5) This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [clap](https://github.com/clap-rs/clap) | dependencies | minor | `4.0` -> `4.4` | > :exclamation: **Important** > > Release Notes retrieval for this PR were skipped because no github.com credentials were available. > If you are self-hosted, please see [this instruction](https://github.com/renovatebot/renovate/blob/master/docs/usage/examples/self-hosting.md#githubcom-token-for-release-notes). --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4xNDYuMCIsInVwZGF0ZWRJblZlciI6IjM3LjE0Ni4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9--> Co-authored-by: Renovate Bot <renovate@kemitix.net> Co-authored-by: Paul Campbell <kemitix@noreply.kemitix.net> Reviewed-on: https://git.kemitix.net/kemitix/skip/pulls/5 Co-authored-by: renovate <renovate@noreply.kemitix.net> Co-committed-by: renovate <renovate@noreply.kemitix.net>
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
cat<<EOF > test.expect
EOF
touch test.out test.err
$SKIP --foo > test.out 2> test.err || true
$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"
cat<<EOF > test.expect.err
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
cat<<EOF > test.expect
EOF
touch test.out test.err
$SKIP --ignore-extras > test.out 2> test.err || true
$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"
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
echo done