aboutsummaryrefslogtreecommitdiff
path: root/src/libs/testing-library
blob: a1cf3c1a0c82544147e2bf8a8543094f0427d594 (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
#!/bin/sh

function description {
    echo "# DESCRIPTION: $1"
}

# $1 is the number of total tests
function plan {
    TESTS=$1; FAILED=0; CUR_TEST=0
    echo "1..$TESTS"
}

function conclude {
    PERC=$(echo "scale=2;100 * $FAILED / $TESTS" | bc)
    echo "# CONCLUSION: ($PERC%) $FAILED out of $TESTS tests failed"

    if [ $TESTS -ne $CUR_TEST ]; then
        echo -e "#     expected $TESTS, but got $CUR_TEST tests"
    fi

    if [ $FAILED -ne 0 ]; then
        exit 1
    fi
}

# $1 is the value to be tested
# $2 description
function ok {
    CUR_TEST=$((CUR_TEST + 1))

    if [ $1 -eq 0 ]; then
        echo "ok $CUR_TEST - $2"
    else
        echo "not ok $CUR_TEST - $2"
        echo -e "    returned '$1'"
        FAILED=$((FAILED + 1))
    fi
}

# $1 is the expected value
# $2 is the actual value
# $3 description
function is {
    CUR_TEST=$((CUR_TEST + 1))

    if [ "$1" = "$2" ]; then
        echo "ok $CUR_TEST - $3"
    else
        echo "not ok $CUR_TEST - $3"
        echo -e "    exptected '$2', but got '$1'"
        FAILED=$((FAILED + 1))
    fi
}