summaryrefslogtreecommitdiffstats
path: root/debian/tests/assert.sh
blob: 1d47bf48731a5de12a46cea11d1638685233dc4c (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
# utility functions for shell tests

assert_true() {
    if ! $1; then
        echo "FAIL: command '$1' failed with exit code $?" >&2
        exit 1
    fi
}


assert_eq() {
    if [ "$1" != "$2" ]; then
        echo "FAIL: expected: '$2' actual: '$1'" >&2
        exit 1
    fi
}

assert_in() {
    if ! echo "$2" | grep -q "$1"; then
        echo "FAIL: '$1' not found in:" >&2
        echo "$2" >&2
        exit 1
    fi
}

assert_rc() {
    local exp=$1
    shift
    set +e
    $@
    RC=$?
    set -e
    assert_eq $RC $exp
}