]> git.saurik.com Git - apt.git/blame - triehash/tests/framework.sh
Release 1.4~beta1
[apt.git] / triehash / tests / framework.sh
CommitLineData
e2073b02
JAK
1#!/bin/sh
2# Simple integration test framework
3
4set -e
5
6
7cleanup() {
8 rm -f test.output test.c test.h test.tree
9}
10
11dumpone() {
12 if [ -e "$@" ]; then
13 echo "Content of $@:"
14 cat "$@" | sed "s#^#\t#g"
15 fi
16
17}
18
19dump() {
20 dumpone test.output
21 dumpone test.c
22 dumpone test.h
23 dumpone test.tree
24 return 1
25}
26
27testsuccess() {
28 [ "$INNER" ] || cleanup
29 [ "$INNER" ] || echo "Testing success of $@"
30 if ! "$@" > test.output 2>&1; then
31 echo "ERROR: Running $@ failed with error $?, messages were:" >&2
32 dump
33 return 1
34 fi
35}
36
37testfailure() {
38 [ "$INNER" ] || cleanup
39 [ "$INNER" ] || echo "Testing failure of $@"
40 if "$@" > test.output 2>&1; then
41 echo "ERROR: Running $@ unexpectedly succeeded, messages were:" >&2
42 dump
43 return 1
44 fi
45}
46
47testfileequal() {
48 [ "$INNER" ] || echo "Testing output of $2"
49 printf "%b\n" "$1" > expected
50 if ! diff -u "expected" "$2" > test.diff; then
51 echo "ERROR: Differences between expected output and and $2:" >&2
52 cat test.diff | sed "s#^#\t#g"
53 dump
54 return 1
55 fi
56}
57
58testgrep() {
59 [ "$INNER" ] || echo "Testing grep $@"
60 INNER=1 testsuccess grep "$@"
61 unset INNER
62}
63
64testsuccessequal() {
65 expect="$1"
66 shift
67 cleanup
68 echo "Testing success and output of $@"
69 INNER=1 testsuccess "$@"
70 INNER=1 testfileequal "$expect" test.output
71 unset INNER
72}
73
74
75WORDS="Word-_0
76Word = 42
77VeryLongWord
78Label ~ Word2
79= -9"
80
81triehash() {
82 printf "%b\n" "$WORDS" | perl -MDevel::Cover=-summary,0,-silent,1 $(dirname $(dirname $(readlink -f $0)))/triehash.pl "$@" || return $?
83 return $?
84}