aboutsummaryrefslogtreecommitdiff
path: root/test/run_test.sh
blob: 63b3ebc1dac510cf85adfe705da703f11b33d12d (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
63
64
65
66
67
#!/usr/bin/env bash
# vim: set ft=sh sw=4 sts=4 et :

testname=${2:-${1}}
interp=
[[ ${testname%.py} != ${testname} ]] && interp="${PYTHON}"
[[ ${testname%.rb} != ${testname} ]] && interp="${RUBY} -I ./.libs/"

testname=${testname%.rb}
testname=${testname%.py}
testname=${testname%.bash}

[[ -z "PALUDIS_TESTS_REAL_STDOUT_FD" ]] && export PALUDIS_TESTS_REAL_STDOUT_FD=1

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

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

now=$(date +'%s' )
echo ">>> test ${testname}" 1>&$PALUDIS_TESTS_REAL_STDOUT_FD 1>&$PALUDIS_TESTS_REAL_STDOUT_FD
$interp ${@}
code=$?
duration=$(( $(date +'%s' ) - ${now} ))

if [[ 0 != ${code} ]] ; then
    echo ">>> test ${testname} returned ${code} [${duration}s]" 1>&$PALUDIS_TESTS_REAL_STDOUT_FD
    if [[ -z "${PALUDIS_TESTS_RERUN_VERBOSELY}" ]] && [[ "${testname#./}" != "test_fail_TEST" ]] ; then
        out=`pwd`/${testname#./}.epicfail
        echo ">>> rerunning test ${testname} verbosely redirected to ${out}" 1>&$PALUDIS_TESTS_REAL_STDOUT_FD
        env PALUDIS_TESTS_RERUN_VERBOSELY=no PALUDIS_TESTS_KEEP_STDERR=yes \
            PALUDIS_TESTS_KEEP_LOG=yes TEST_OUTPUT_WRAPPER= $0 $@ > $out 2>&1
        echo ">>> saved output of verbose ${testname} rerun to ${out}" 1>&$PALUDIS_TESTS_REAL_STDOUT_FD
    fi
    echo ">>> exiting with error for test ${testname}" 1>&$PALUDIS_TESTS_REAL_STDOUT_FD
    exit 255
fi

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

echo ">>> exiting with success for test ${testname} [${duration}s]" 1>&$PALUDIS_TESTS_REAL_STDOUT_FD
exit 0