diff options
Diffstat (limited to 'tests/ranking.sh')
-rwxr-xr-x | tests/ranking.sh | 81 |
1 files changed, 41 insertions, 40 deletions
diff --git a/tests/ranking.sh b/tests/ranking.sh index 45629d8..807f17b 100755 --- a/tests/ranking.sh +++ b/tests/ranking.sh @@ -6,25 +6,6 @@ set -eu export XDG_DATA_HOME="$PWD/tests/test-profiles" export LANG=C.UTF-8 -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)" - for _ in $(seq 10); do - printf 'always-picked\nnever-picked\n' | \ - ./src/remembering \ - -p "$PROFILE" \ - -c 'head -n1' \ - 1>"$OUT" 2>"$ERR" - STATUS=$? - assert_status 0 - assert_empty_stderr - assert_stdout 'always-picked' - done - test_ok -} - INPUT='a b c @@ -69,12 +50,49 @@ pick_x() { assert_first() { FIRST="$(head -n1 "$ERR")" if [ "$FIRST" != "$1" ]; then - printf '\nERR: Previous choice did not appear at the beginning of the list:\n\nexpected: %s\ngot: %s\n' \ - "$1" "$FIRST" >&2 + printf '\n%s: Previous choice did not appear at the beginning of the list:\n\nexpected: %s\ngot: %s\n' \ + "$(ERROR)" "$1" "$FIRST" >&2 + exit 1 + fi +} + +BASE_PROFILE='0:a +0:b +0:c +0:d +0:e' +BASE_PROFILE_A_PICKED='1:a +0:b +0:c +0:d +0:e' +assert_profile() { + if [ "$(cat "$XDG_DATA_HOME/$1")" != "$2" ]; then + printf '\n%s: Bad profile merge (%s).\n\nExpected:\n%s\nGot\n%s\n' \ + "$(ERROR)" "$PROFILE" "$2" "$(cat "$XDG_DATA_HOME/$1")" >&2 exit 1 fi } +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)" + for _ in $(seq 10); do + printf 'always-picked\nnever-picked\n' | \ + ./src/remembering \ + -p "$PROFILE" \ + -c 'head -n1' \ + 1>"$OUT" 2>"$ERR" + STATUS=$? + assert_status 0 + assert_empty_stderr + assert_stdout 'always-picked' + done + test_ok +} + test_promoting_values() { testing 'promoting values' PROFILE="promoting-$(uuid)" @@ -151,7 +169,8 @@ m s' ACTUAL="$(head -n9 "$ERR")" if [ "$ACTUAL" != "$EXPECTED" ]; then - printf '\nERR: Bad order!\n\nexpected: %s\ngot: %s\n' \ + printf '\n%s: Bad order!\n\nexpected: %s\ngot: %s\n' \ + "$(ERROR)" \ "$(echo "$EXPECTED" | tr '\n' ' ')" \ "$(echo "$ACTUAL" | tr '\n' ' ')" \ >&2 @@ -181,24 +200,6 @@ e' test_ok } -BASE_PROFILE='0:a -0:b -0:c -0:d -0:e' -BASE_PROFILE_A_PICKED='1:a -0:b -0:c -0:d -0:e' -assert_profile() { - if [ "$(cat "$XDG_DATA_HOME/$1")" != "$2" ]; then - printf '\nERR: Bad profile merge (%s).\n\nExpected:\n%s\nGot\n%s\n' \ - "$PROFILE" "$2" "$(cat "$XDG_DATA_HOME/$1")" >&2 - exit 1 - fi -} - test_stdin_is_larger_than_profile() { testing 'STDIN is larger than profile' PROFILE="stdin-is-larger-than-profile-$(uuid)" |