summaryrefslogtreecommitdiffstats
path: root/triehash/tests/framework.sh
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-05 18:07:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-05 18:07:13 +0000
commit636c7dc17286d93d788c741d15fd756aeda066d5 (patch)
treee7ae158cc54f591041a061b9865bcae51854f15c /triehash/tests/framework.sh
parentInitial commit. (diff)
downloadapt-636c7dc17286d93d788c741d15fd756aeda066d5.tar.xz
apt-636c7dc17286d93d788c741d15fd756aeda066d5.zip
Adding upstream version 1.8.2.3.upstream/1.8.2.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'triehash/tests/framework.sh')
-rw-r--r--triehash/tests/framework.sh84
1 files changed, 84 insertions, 0 deletions
diff --git a/triehash/tests/framework.sh b/triehash/tests/framework.sh
new file mode 100644
index 0000000..51d4580
--- /dev/null
+++ b/triehash/tests/framework.sh
@@ -0,0 +1,84 @@
+#!/bin/sh
+# Simple integration test framework
+
+set -e
+
+
+cleanup() {
+ rm -f test.output test.c test.h test.tree
+}
+
+dumpone() {
+ if [ -e "$@" ]; then
+ echo "Content of $@:"
+ cat "$@" | sed "s#^#\t#g"
+ fi
+
+}
+
+dump() {
+ dumpone test.output
+ dumpone test.c
+ dumpone test.h
+ dumpone test.tree
+ return 1
+}
+
+testsuccess() {
+ [ "$INNER" ] || cleanup
+ [ "$INNER" ] || echo "Testing success of $@"
+ if ! "$@" > test.output 2>&1; then
+ echo "ERROR: Running $@ failed with error $?, messages were:" >&2
+ dump
+ return 1
+ fi
+}
+
+testfailure() {
+ [ "$INNER" ] || cleanup
+ [ "$INNER" ] || echo "Testing failure of $@"
+ if "$@" > test.output 2>&1; then
+ echo "ERROR: Running $@ unexpectedly succeeded, messages were:" >&2
+ dump
+ return 1
+ fi
+}
+
+testfileequal() {
+ [ "$INNER" ] || echo "Testing output of $2"
+ printf "%b\n" "$1" > expected
+ if ! diff -u "expected" "$2" > test.diff; then
+ echo "ERROR: Differences between expected output and and $2:" >&2
+ cat test.diff | sed "s#^#\t#g"
+ dump
+ return 1
+ fi
+}
+
+testgrep() {
+ [ "$INNER" ] || echo "Testing grep $@"
+ INNER=1 testsuccess grep "$@"
+ unset INNER
+}
+
+testsuccessequal() {
+ expect="$1"
+ shift
+ cleanup
+ echo "Testing success and output of $@"
+ INNER=1 testsuccess "$@"
+ INNER=1 testfileequal "$expect" test.output
+ unset INNER
+}
+
+
+WORDS="Word-_0
+Word = 42
+VeryLongWord
+Label ~ Word2
+= -9"
+
+triehash() {
+ printf "%b\n" "$WORDS" | perl -MDevel::Cover=-summary,0,-silent,1 $(dirname $(dirname $(readlink -f $0)))/triehash.pl "$@" || return $?
+ return $?
+}