]> git.saurik.com Git - apt.git/blob - triehash/tests/framework.sh
don't perform implicit crossgrades involving M-A:same
[apt.git] / triehash / tests / framework.sh
1 #!/bin/sh
2 # Simple integration test framework
3
4 set -e
5
6
7 cleanup() {
8 rm -f test.output test.c test.h test.tree
9 }
10
11 dumpone() {
12 if [ -e "$@" ]; then
13 echo "Content of $@:"
14 cat "$@" | sed "s#^#\t#g"
15 fi
16
17 }
18
19 dump() {
20 dumpone test.output
21 dumpone test.c
22 dumpone test.h
23 dumpone test.tree
24 return 1
25 }
26
27 testsuccess() {
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
37 testfailure() {
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
47 testfileequal() {
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
58 testgrep() {
59 [ "$INNER" ] || echo "Testing grep $@"
60 INNER=1 testsuccess grep "$@"
61 unset INNER
62 }
63
64 testsuccessequal() {
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
75 WORDS="Word-_0
76 Word = 42
77 VeryLongWord
78 Label ~ Word2
79 = -9"
80
81 triehash() {
82 printf "%b\n" "$WORDS" | perl -MDevel::Cover=-summary,0,-silent,1 $(dirname $(dirname $(readlink -f $0)))/triehash.pl "$@" || return $?
83 return $?
84 }