summaryrefslogtreecommitdiff
path: root/triehash/tests/framework.sh
blob: 51d4580a6ba4e4ac548db539362503d28374af7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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 $?
}