aboutsummaryrefslogtreecommitdiff
path: root/test/run_test.sh
blob: 52e1761e849da89a1fde344aa03a3c04d8f63356 (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
#!/bin/bash
# vim: set ft=sh sw=4 sts=4 et :

testname=${2:-${1}}
testname=${testname%.rb}
testname=${testname%.py}
testname=${testname%.bash}

if test -f "$TEST_SCRIPT_DIR""${testname}"_"cleanup.sh" ; then
    echo ">>> cleanup for test ${testname}"
    if ! "$TEST_SCRIPT_DIR""${testname}"_"cleanup.sh" ; then
        echo ">>> exiting with error for test ${testname}"
        exit 255
    fi
else
    echo ">>> No $TEST_SCRIPT_DIR${testname}_cleanup.sh to run"
fi

if test -f "$TEST_SCRIPT_DIR""${testname}"_"setup.sh" ; then
    echo ">>> setup for test ${testname}"
    if ! "$TEST_SCRIPT_DIR""${testname}"_"setup.sh" ; then
        echo ">>> exiting with error for test ${testname}"
        exit 255
    fi
else
    echo ">>> No $TEST_SCRIPT_DIR${testname}_setup.sh to run"
fi

echo ">>> test ${testname}"
if [[ -n "${TEST_OUTPUT_WRAPPER}" ]] ; then
    $TEST_OUTPUT_WRAPPER --stdout-prefix "${testname#./}> " --stderr-prefix "${testname#./}> " -- ${@}
    code=$?
else
    ${@}
    code=$?
fi

if [[ 0 != ${code} ]] ; then
    echo ">>> test ${testname} returned ${code}"
    if test -f "$TEST_SCRIPT_DIR""${testname}"_"cleanup.sh" ; then
        echo ">>> cleanup for test ${testname}"
        "$TEST_SCRIPT_DIR""${testname}"_"cleanup.sh"
    fi
    echo ">>> exiting with error for test ${testname}"
    exit 255
fi

if test -f "$TEST_SCRIPT_DIR""${testname}"_"cleanup.sh" ; then
    echo ">>> cleanup for test ${testname}"
    if ! "$TEST_SCRIPT_DIR""${testname}"_"cleanup.sh" ; then
        echo ">>> exiting with error for test ${testname}"
        exit 255
    fi
else
    echo ">>> No $TEST_SCRIPT_DIR${testname}_cleanup.sh to run"
fi

echo ">>> exiting with success for test ${testname}"
exit 0