13220: Test framework refactor WIP
[arvados.git] / build / new-run-tests.sh
1 #!/bin/bash
2 # Copyright (C) The Arvados Authors. All rights reserved.
3 #
4 # SPDX-License-Identifier: AGPL-3.0
5
6 set -e
7
8 # First make sure to remove any ARVADOS_ variables from the calling
9 # environment that could interfere with the tests.
10 unset $(env | cut -d= -f1 | grep \^ARVADOS_)
11
12 # Reset other variables that could affect our [tests'] behavior by
13 # accident.
14 GITDIR=
15 GOPATH=
16 VENVDIR=
17 VENV3DIR=
18 PYTHONPATH=
19 GEMHOME=
20 PERLINSTALLBASE=
21 R_LIBS=
22
23 short=
24 temp=
25 temp_preserve=
26
27 if [[ -z "$WORKSPACE" ]] ; then
28     WORKSPACE=$(readlink -f $(dirname $0)/..)
29 fi
30
31 declare -a include_tests
32 declare -A exclude_tests
33
34 declare -A include_install
35 declare -A exclude_install
36
37 . test-library.sh
38
39 if [[ $(whoami) = 'arvbox' && -f /usr/local/lib/arvbox/common.sh ]] ; then
40     . /usr/local/lib/arvbox/common.sh
41 fi
42
43 interrupt() {
44     failures+=("($(basename $0) interrupted)")
45     exit_cleanly
46 }
47 trap interrupt INT
48
49 echo "WORKSPACE is $WORKSPACE"
50
51 while [[ -n "$1" ]]
52 do
53     arg="$1"; shift
54     case "$arg" in
55         --help)
56             echo >&2 "$helpmessage"
57             echo >&2
58             exit 1
59             ;;
60         --temp)
61             temp="$1"; shift
62             temp_preserve=1
63             ;;
64         --leave-temp)
65             temp_preserve=1
66             ;;
67         --repeat)
68             repeat=$((${1}+0)); shift
69             ;;
70         --retry)
71             retry=1
72             ;;
73         -i)
74             include_tests+="$1"; shift
75             ;;
76         -x)
77             exclude_tests[$1]=1; shift
78             ;;
79         --only-install)
80             include_install[$1]=1; shift
81             ;;
82         --skip-install)
83             if [[ $1 = all ]] ; then
84                 include_install["none"]=1
85             else
86                 exclude_install[$1]=1
87             fi
88             shift
89             ;;
90         --debug)
91             set -x
92             ;;
93         *)
94             echo >&2 "$0: Unrecognized option: '$arg'. Try: $0 --help"
95             exit 1
96             ;;
97     esac
98 done
99
100 echo "temp is $temp"
101
102 cd $WORKSPACE
103 find . -name '*.pyc' -delete
104
105 if [[ -z "${include_tests[@]}" ]] ; then
106     find_run_tests=$(find . -name .run-tests)
107
108     for t in $find_run_tests ; do
109         [[ $t =~ ./(.*)/.run-tests ]]
110         include_tests+=(${BASH_REMATCH[1]})
111     done
112 fi
113
114 for t in "${include_tests[@]}" ; do
115     if [[ -n "${exclude_tests[$t]}" ]] ; then
116         continue
117     fi
118
119     TESTDEPS=()
120     TESTS=()
121     . $WORKSPACE/$t/.run-tests
122
123     if [[ -n "${TESTDEPS}" ]] ; then
124         title "Begin $t"
125     fi
126     installfail=""
127     for TESTDEP in ${TESTDEPS} ; do
128         $TESTDEP
129         if [[ $? != 0 ]] ; then
130             installfail=1
131             break
132         fi
133     done
134     if [[ -n "$installfail" ]] ; then
135         continue
136     fi
137     for TESTFN in ${TESTS} ; do
138         do_test $t $TESTFN
139     done
140 done
141
142 exit_cleanly