diff options
author | EuAndreh <eu@euandre.org> | 2021-01-24 14:56:02 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2021-01-24 14:56:02 -0300 |
commit | b9061b44194c6564364ee41dfda17df171547cf4 (patch) | |
tree | 7f1c15858005b4f827f879e52b3d3ad5f9cc7fa6 | |
parent | remembering: Append to in-memory string instead of intermediate file (diff) | |
download | remembering-b9061b44194c6564364ee41dfda17df171547cf4.tar.gz remembering-b9061b44194c6564364ee41dfda17df171547cf4.tar.xz |
tests: Add logs of which test is running
-rwxr-xr-x | tests/cli-opts.sh | 12 | ||||
-rwxr-xr-x | tests/lib.sh | 19 | ||||
-rwxr-xr-x | tests/ranking.sh | 15 | ||||
-rwxr-xr-x | tests/signals.sh | 5 |
4 files changed, 44 insertions, 7 deletions
diff --git a/tests/cli-opts.sh b/tests/cli-opts.sh index efc100b..0562517 100755 --- a/tests/cli-opts.sh +++ b/tests/cli-opts.sh @@ -12,24 +12,29 @@ assert_usage() { } test_unsupported_long_flags() { + testing 'unsupported long flags' OUT="$(mktemp)" ERR="$(mktemp)" sh remembering --unknown-long-flag 1>"$OUT" 2>"$ERR" STATUS=$? assert_status 2 assert_usage "$ERR" + test_ok } test_missing_required_flags() { + testing 'missing required flags' OUT="$(mktemp)" ERR="$(mktemp)" sh remembering -a something -b else 1>"$OUT" 2>"$ERR" STATUS=$? assert_status 2 assert_usage "$ERR" + test_ok } test_single_required_flag() { + testing 'single required flag' OUT="$(mktemp)" ERR="$(mktemp)" sh remembering -p valid-test-profile 1>"$OUT" 2>"$ERR" @@ -43,9 +48,11 @@ test_single_required_flag() { STATUS=$? assert_status 2 assert_usage "$ERR" + test_ok } test_flags_without_required_argument() { + testing 'flags without required argument' OUT="$(mktemp)" ERR="$(mktemp)" sh remembering -pc 1>"$OUT" 2>"$ERR" @@ -66,9 +73,11 @@ test_flags_without_required_argument() { STATUS=$? assert_status 2 assert_usage "$ERR" + test_ok } test_valid_options() { + testing 'valid options' OUT="$(mktemp)" ERR="$(mktemp)" printf 'a\nb\nc\n' | \ @@ -80,9 +89,11 @@ test_valid_options() { assert_status 0 assert_empty_stderr assert_stdout 'a' + test_ok } test_help_flags() { + testing 'help flags' OUT="$(mktemp)" ERR="$(mktemp)" sh remembering -h 1>"$OUT" 2>"$ERR" @@ -98,6 +109,7 @@ test_help_flags() { assert_status 0 assert_empty_stderr assert_usage "$OUT" + test_ok } test_unsupported_long_flags diff --git a/tests/lib.sh b/tests/lib.sh index f7f4415..8d77068 100755 --- a/tests/lib.sh +++ b/tests/lib.sh @@ -7,23 +7,24 @@ STATUS= assert_status() { if [ "$STATUS" != "$1" ]; then - printf 'Bad status.\n\nexpected: %s\ngot: %s\n' "$1" "$STATUS" >&2 + printf '\nERR: Bad status.\n\nexpected: %s\ngot: %s\n' \ + "$1" "$STATUS" >&2 exit 1 fi } assert_empty_stderr() { if [ "$(cat "$ERR")" != '' ]; then - echo "Expected STDERR ($ERR) to be empty, but has content:" >&2 - cat "$ERR" >&2 + printf '\nERR: Expected STDERR (%s) to be empty, but has content:\n%s\n' \ + "$ERR" "$(cat "$ERR")" >&2 exit 1 fi } assert_stdout() { if [ "$(cat "$OUT")" != "$1" ]; then - echo "Bad STDOUT ($OUT), expected '$1', got:" >&2 - cat "$OUT" >&2 + printf '\nERR: Bad STDOUT (%s)\nexpected: %s\ngot: %s\n' \ + "$OUT" "$1" "$(cat "$OUT")" >&2 exit 1 fi } @@ -35,3 +36,11 @@ uuid() { head -1 | \ awk '{OFS="-"; print $2$3,$4,$5,$6,$7$8$9}' } + +testing() { + printf 'testing: %s...' "$1" >&2 +} + +test_ok() { + printf ' OK.\n' >&2 +} diff --git a/tests/ranking.sh b/tests/ranking.sh index 5dec051..e01692e 100755 --- a/tests/ranking.sh +++ b/tests/ranking.sh @@ -4,6 +4,7 @@ set -eu . tests/lib.sh test_picking_first_makes_it_be_always_first() { + testing 'picking first makes it be always first' OUT="$(mktemp)" ERR="$(mktemp)" PROFILE="always-picks-first-$(uuid)" @@ -18,6 +19,7 @@ test_picking_first_makes_it_be_always_first() { assert_empty_stderr assert_stdout 'always-picked' done + test_ok } INPUT='a @@ -71,6 +73,7 @@ assert_first() { } test_promoting_values() { + testing 'promoting values' PROFILE="promoting-$(uuid)" pick_x h @@ -80,9 +83,11 @@ test_promoting_values() { pick_x h pick_x z assert_first h + test_ok } test_higher_values_loose_tie() { + testing 'higher values loose tie' PROFILE="higher-loose-tie-$(uuid)" pick_x f @@ -91,9 +96,11 @@ test_higher_values_loose_tie() { pick_x g pick_x z assert_first f + test_ok } test_smaller_values_win_tie() { + testing 'smaller values win tie' PROFILE="smaller-win-tie-$(uuid)" pick_x d @@ -102,9 +109,11 @@ test_smaller_values_win_tie() { pick_x c pick_x z assert_first c + test_ok } test_many_sequential_picks() { + testing 'many sequential pick' PROFILE="many-sequential-picks-$(uuid)" pick_x b @@ -139,11 +148,13 @@ m s' ACTUAL="$(head -n9 "$ERR")" if [ "$ACTUAL" != "$EXPECTED" ]; then - printf 'Bad order!\n\nexpected: %s\ngot: %s\n' \ + printf '\nERR: Bad order!\n\nexpected: %s\ngot: %s\n' \ "$(echo "$EXPECTED" | tr '\n' ' ')" \ - "$(echo "$ACTUAL" | tr '\n' ' ')" + "$(echo "$ACTUAL" | tr '\n' ' ')" \ + >&2 exit 1 fi + test_ok } test_picking_first_makes_it_be_always_first diff --git a/tests/signals.sh b/tests/signals.sh index ad7ed2d..124434c 100755 --- a/tests/signals.sh +++ b/tests/signals.sh @@ -4,6 +4,7 @@ set -u . tests/lib.sh test_status_is_zero_when_command_is_successful() { + testing 'status is 0 when command is successful' printf 'a\n' | sh remembering -pp1 -c 'head -n1' 1>/dev/null 2>/dev/null STATUS=$? assert_status 0 @@ -15,14 +16,18 @@ test_status_is_zero_when_command_is_successful() { seq 9 | sh remembering -pp3 -c 'grep 7' 1>/dev/null 2>/dev/null STATUS=$? assert_status 0 + + test_ok } test_status_is_forwarded_from_command() { + testing 'status is forwarded from command' for status in $(seq 1 125); do printf '' | sh remembering -pp4 -c "exit $status" 1>/dev/null 2>/dev/null STATUS=$? assert_status "$status" done + test_ok } test_status_is_zero_when_command_is_successful |