aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xaux/utils.sh9
-rwxr-xr-xtests/cli-opts.sh1
-rwxr-xr-xtests/lib.sh57
-rwxr-xr-xtests/ranking.sh3
4 files changed, 57 insertions, 13 deletions
diff --git a/aux/utils.sh b/aux/utils.sh
new file mode 100755
index 0000000..8d93fb5
--- /dev/null
+++ b/aux/utils.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+uuid() {
+ # Taken from:
+ # https://serverfault.com/a/799198
+ od -xN20 /dev/urandom | \
+ head -1 | \
+ awk '{OFS="-"; print $2$3,$4,$5,$6,$7$8$9}'
+}
diff --git a/tests/cli-opts.sh b/tests/cli-opts.sh
index 05a898e..d1fee95 100755
--- a/tests/cli-opts.sh
+++ b/tests/cli-opts.sh
@@ -1,6 +1,7 @@
#!/bin/sh
set -u
+. aux/utils.sh
. tests/lib.sh
assert_usage() {
diff --git a/tests/lib.sh b/tests/lib.sh
index 9f3c629..957566e 100755
--- a/tests/lib.sh
+++ b/tests/lib.sh
@@ -1,6 +1,5 @@
#!/bin/sh
-export XDG_DATA_HOME="$PWD/tests/test-profiles"
OUT=
ERR=
STATUS=
@@ -13,28 +12,60 @@ assert_status() {
fi
}
+assert_usage() {
+ if ! grep -Fq 'Usage' "$1"; then
+ echo 'Expected to find "Usage" text, it was missing:' >&2
+ cat "$1" >&2
+ exit 1
+ fi
+}
+
+assert_empty_stream() {
+ if [ -s "$2" ]; then
+ printf '\nERR: Expected %s (%s) to be empty, but has content:\n%s\n' \
+ "$1" "$2" "$(cat "$2")" >&2
+ exit 1
+ fi
+}
+
+assert_empty_stdout() {
+ assert_empty_stream STDOUT "$OUT"
+}
+
assert_empty_stderr() {
- if [ "$(cat "$ERR")" != '' ]; then
- printf '\nERR: Expected STDERR (%s) to be empty, but has content:\n%s\n' \
- "$ERR" "$(cat "$ERR")" >&2
+ assert_empty_stream STDERR "$ERR"
+}
+
+assert_stream() {
+ if [ "$(cat "$2")" != "$3" ]; then
+ printf '\nERR: Bad %s (%s)\n\nexpected: %s\ngot: %s\n' \
+ "$1" "$2" "$3" "$(cat "$2")" >&2
exit 1
fi
}
assert_stdout() {
- if [ "$(cat "$OUT")" != "$1" ]; then
- printf '\nERR: Bad STDOUT (%s)\n\nexpected: %s\ngot: %s\n' \
- "$OUT" "$1" "$(cat "$OUT")" >&2
+ assert_stream STDOUT "$OUT" "$1"
+}
+
+assert_stderr() {
+ assert_stream STDERR "$ERR" "$1"
+}
+
+assert_grep_stream() {
+ if ! grep -qE "$3" "$2"; then
+ printf '\nERR: Bad %s (%s)\n\ngrepping: %s\nin:\n%s\n' \
+ "$1" "$2" "$3" "$(cat "$2")" >&2
exit 1
fi
}
-uuid() {
- # Taken from:
- # https://serverfault.com/a/799198
- od -xN20 /dev/urandom | \
- head -1 | \
- awk '{OFS="-"; print $2$3,$4,$5,$6,$7$8$9}'
+assert_grep_stdout() {
+ assert_grep_stream STDOUT "$OUT" "$1"
+}
+
+assert_grep_stderr() {
+ assert_grep_stream STDERR "$ERR" "$1"
}
testing() {
diff --git a/tests/ranking.sh b/tests/ranking.sh
index c3bee84..3b9ac6e 100755
--- a/tests/ranking.sh
+++ b/tests/ranking.sh
@@ -1,8 +1,11 @@
#!/bin/sh
set -eu
+. aux/utils.sh
. tests/lib.sh
+export XDG_DATA_HOME="$PWD/tests/test-profiles"
+
test_picking_first_makes_it_be_always_first() {
testing 'picking first makes it be always first'
OUT="$(mktemp)"