summaryrefslogtreecommitdiff
path: root/minitap.sh
blob: d5bb4f86396fc4b1d9c44557eb91bfd42198c668 (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
minitap_started=0
minitap_counter=0
 
function ok() {
    minitap/maybe-start
    (( ++minitap_counter ))
    echo "ok ${minitap_counter} - $*"
}
 
function nok() {
    minitap/maybe-start
    (( ++minitap_counter ))
    echo "not ok ${minitap_counter} - $*"
}
 
function diag() {
    echo "$*"
}
 
function is() {
    local got="$1";shift
    local expect="$1";shift
 
    if [[ "$got" == $expect ]]; then
        ok "$@"
    else
        diag "got <$got>, expected <$expect>";
        nok "$@"
    fi
}
 
function should-succeed() {
    local last_status="$?"
    if [[ "$last_status" -eq 0 ]]; then
        ok "$@"
    else
        nok "$@"
    fi
}
 
function should-fail() {
    local last_status="$?"
    if [[ "$last_status" -eq 0 ]]; then
        nok "$@"
    else
        ok "$@"
    fi
}
 
function done-testing() {
    echo "1..${minitap_counter}"
}
 
function minitap/maybe-start() {
    if [[ "$minitap_started" == 0 ]]; then
        echo "TAP version 13"
        minitap_started=1
    fi
}