aboutsummaryrefslogtreecommitdiff
path: root/paludis/repositories/gentoo/ebuild/utils/run_test.bash
blob: 1f9db4e3836c36a785359ca48f3d36cc2e77c7e9 (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
#!/bin/bash
# vim: set sw=4 sts=4 et :

shopt -s expand_aliases
shopt -s extglob
set +o posix

export TEST_STATUS=
export PALUDIS_IN_TEST_FRAMEWORK="yes"

test_return_code()
{
    local r="$?"
    if [[ "0" == "${r}" ]] ; then
        echo -n "."
    else
        echo -n "!{retcode: ${r}}"
        export local_test_status="fail"
        export TEST_STATUS="fail"
    fi
}

test_equality()
{
    if [[ "${1}" == "${2}" ]] ; then
        echo -n "."
    else
        echo -n "!{'${1}' not equal to '${2}'}"
        export local_test_status="fail"
        export TEST_STATUS="fail"
    fi
}

if test -f "$TEST_SCRIPT_DIR""${1%.bash}"_"setup.sh" ; then
    echo ">>> setup for test ${1%.bash}"
    if ! "$TEST_SCRIPT_DIR""${1%.bash}"_"setup.sh" ; then
        echo ">>> exiting with error for test ${1%.bash}"
        exit 255
    fi
fi

echo "Test program ${1%.bash}:"
source "${1}" || exit 200

for testname in $(set | grep '_TEST *() *$' ) ; do
    [[ ${testname/()} != ${testname} ]] && continue
    echo -n "* ${testname%_TEST}: "
    export local_test_status=""
    ${testname}
    [[ -z "$local_test_status" ]] && echo " OK" || echo " FAIL"
done

if test -f "$TEST_SCRIPT_DIR""${1%.bash}"_"cleanup.sh" ; then
    echo ">>> cleanup for test ${1%.bash}"
    if ! "$TEST_SCRIPT_DIR""${1%.bash}"_"cleanup.sh" ; then
        echo ">>> exiting with error for test ${1%.bash}"
        exit 255
    fi
fi

[[ -z "$TEST_STATUS" ]]