aboutsummaryrefslogtreecommitdiff
path: root/aux/tests-lib.sh
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2021-06-27 16:39:44 -0300
committerEuAndreh <eu@euandre.org>2021-06-27 16:41:24 -0300
commit1533a1dbb2b16dbd12db4a4fffdad09de6057614 (patch)
tree45096e78f91ae1c08ee171e5cda5457316162172 /aux/tests-lib.sh
parentsrc/unit-test.h: Make its output equal to aux/tests-lib.sh (diff)
downloadremembering-1533a1dbb2b16dbd12db4a4fffdad09de6057614.tar.gz
remembering-1533a1dbb2b16dbd12db4a4fffdad09de6057614.tar.xz
mv {aux => tests}/tests-lib.sh
Diffstat (limited to 'aux/tests-lib.sh')
-rwxr-xr-xaux/tests-lib.sh123
1 files changed, 0 insertions, 123 deletions
diff --git a/aux/tests-lib.sh b/aux/tests-lib.sh
deleted file mode 100755
index a3ce7dc..0000000
--- a/aux/tests-lib.sh
+++ /dev/null
@@ -1,123 +0,0 @@
-#!/bin/sh
-
-end="\033[0m"
-red="\033[0;31m"
-green="\033[0;32m"
-yellow="\033[0;33m"
-
-N=
-OUT=
-ERR=
-STATUS=
-
-ERROR() {
- # shellcheck disable=2059
- printf "${red}ERROR${end}"
-}
-
-print_debug_info() {
- printf 'LINENO: %s\nOUT: %s\nERR: %s\n' "$N" "$OUT" "$ERR" >&2
-}
-
-assert_status() {
- if [ "$STATUS" != "$1" ]; then
- printf '\n%s: Bad status.\n\nexpected: %s\ngot: %s\n' \
- "$(ERROR)" "$1" "$STATUS" >&2
- print_debug_info
- exit 1
- fi
-}
-
-assert_usage() {
- if ! grep -Fq 'Usage' "$1"; then
- echo 'Expected to find "Usage" text, it was missing:' >&2
- cat "$1" >&2
- print_debug_info
- exit 1
- fi
-}
-
-assert_empty_stream() {
- if [ -s "$2" ]; then
- printf '\n%s: Expected %s (%s) to be empty, but has content:\n%s\n' \
- "$(ERROR)" "$1" "$2" "$(cat "$2")" >&2
- print_debug_info
- exit 1
- fi
-}
-
-assert_empty_stdout() {
- assert_empty_stream STDOUT "$OUT"
-}
-
-assert_empty_stderr() {
- 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
- print_debug_info
- exit 1
- fi
-}
-
-assert_stdout() {
- 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
- print_debug_info
- exit 1
- fi
-}
-
-assert_grep_stdout() {
- assert_grep_stream STDOUT "$OUT" "$1"
-}
-
-assert_grep_stderr() {
- assert_grep_stream STDERR "$ERR" "$1"
-}
-
-assert_fgrep_stream() {
- if ! grep -Fq -- "$3" "$2"; then
- printf '\nERR: Bad %s (%s)\n\ngrepping: %s\nin:\n%s\n' \
- "$1" "$2" "$3" "$(cat "$2")" >&2
- print_debug_info
- exit 1
- fi
-}
-
-assert_fgrep_stdout() {
- assert_fgrep_stream STDOUT "$OUT" "$1"
-}
-
-assert_fgrep_stderr() {
- assert_fgrep_stream STDERR "$ERR" "$1"
-}
-
-testing() {
- printf "${yellow}testing${end}: %s..." "$1" >&2
-}
-
-test_ok() {
- # shellcheck disable=2059
- printf " ${green}OK${end}.\n" >&2
-}
-
-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}'
-}