-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrun_all_unit_tests.sh
More file actions
executable file
·219 lines (143 loc) · 4.19 KB
/
Copy pathrun_all_unit_tests.sh
File metadata and controls
executable file
·219 lines (143 loc) · 4.19 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#! /bin/bash
ScriptPath=$0
Dir=$(cd $(dirname "$ScriptPath"); pwd)
Basename=$(basename "$ScriptPath")
CMakeDir=${SIS_CMAKE_BUILD_DIR:-$Dir/_build}
[[ -n "$MSYSTEM" ]] && DefaultMakeCmd=mingw32-make.exe || DefaultMakeCmd=make
MakeCmd=${SIS_CMAKE_MAKE_COMMAND:-${SIS_CMAKE_COMMAND:-$DefaultMakeCmd}}
ProjectNameFile="$Dir/.sis/project_name.txt"
ProjectName=$(tr -d '[:space:]' < "$ProjectNameFile")
ListOnly=0
RunMake=1
UnitOnly=0
ComponentOnly=0
Verbosity=${XTESTS_VERBOSITY:-${TEST_VERBOSITY:-3}}
# ##########################################################
# colours
if command -v tput > /dev/null; then
RbEnvClr_Blue=${FG_BLUE:-$(tput setaf 4)}
RbEnvClr_Red=${FG_BLUE:-$(tput setaf 1)}
RbEnvClr_Bold=${FD_BOLD:-$(tput bold)}
RbEnvClr_None=${FD_NONE:-$(tput sgr0)}
else
RbEnvClr_Blue=
RbEnvClr_Red=
RbEnvClr_Bold=
RbEnvClr_None=
fi
# ##########################################################
# command-line handling
while [[ $# -gt 0 ]]; do
case $1 in
--list-only|-l)
ListOnly=1
;;
--no-make|-M)
RunMake=0
;;
--unit-only)
UnitOnly=1
;;
--component-only)
ComponentOnly=1
;;
--verbosity)
shift
Verbosity=$1
;;
--help)
[ -f "$Dir/.sis/script_info_lines.txt" ] && cat "$Dir/.sis/script_info_lines.txt"
cat << EOF
Runs all (matching) unit-test and/or component-test programs
$ScriptPath [ ... flags/options ... ]
Flags/options:
behaviour:
-l
--list-only
lists the target programs but does not execute them
-M
--no-make
does not execute CMake and make before running tests
--unit-only
runs only unit-test programs (test.unit.* / test_unit*)
--component-only
runs only component-test programs (test.component.* / test_component*)
--verbosity <verbosity>
specifies an explicit verbosity for the unit-test(s)
standard flags:
--help
displays this help and terminates
EOF
exit 0
;;
*)
>&2 echo "$ScriptPath: unrecognised argument '$1'; use --help for usage"
exit 1
;;
esac
shift
done
if [ $UnitOnly -ne 0 ] && [ $ComponentOnly -ne 0 ]; then
>&2 echo "$ScriptPath: --unit-only and --component-only are mutually exclusive"
exit 1
fi
# ##########################################################
# main()
status=0
if [ $UnitOnly -ne 0 ]; then
TestKindDescription='unit test'
elif [ $ComponentOnly -ne 0 ]; then
TestKindDescription='component test'
else
TestKindDescription='component and unit test'
fi
if [ $RunMake -ne 0 ]; then
if [ $ListOnly -eq 0 ]; then
echo "Executing build (via command \`$MakeCmd\`) and then running all ${ProjectName} ${TestKindDescription} programs"
mkdir -p $CMakeDir || exit 1
cd $CMakeDir
$MakeCmd
status=$?
cd ->/dev/null
fi
else
if [ ! -d "$CMakeDir" ] || [ ! -f "$CMakeDir/CMakeCache.txt" ] || [ ! -d "$CMakeDir/CMakeFiles" ]; then
>&2 echo "$ScriptPath: cannot run in '--no-make' mode without a previous successful build step"
exit 1
fi
fi
if [ $status -eq 0 ]; then
if [ $ListOnly -ne 0 ]; then
echo "Listing all ${ProjectName} ${TestKindDescription} programs"
else
echo "Running all ${ProjectName} ${TestKindDescription} programs"
fi
if [ $UnitOnly -ne 0 ]; then
find_name_expr=( \( -name 'test_unit*' -o -name 'test.unit.*' \) )
elif [ $ComponentOnly -ne 0 ]; then
find_name_expr=( \( -name 'test_component*' -o -name 'test.component.*' \) )
else
find_name_expr=( \( -name 'test_unit*' -o -name 'test.unit.*' -o -name 'test_component*' -o -name 'test.component.*' \) )
fi
for f in $(find "$CMakeDir" -type f "${find_name_expr[@]}" -exec test -x {} \; -print | sort)
do
if [ $ListOnly -ne 0 ]; then
echo "would execute $RbEnvClr_Blue$RbEnvClr_Bold$f$RbEnvClr_None:"
continue
fi
if [ $Verbosity -ge 3 ]; then
echo
fi
if [ $Verbosity -ge 2 ]; then
echo "executing $RbEnvClr_Blue$RbEnvClr_Bold$f$RbEnvClr_None:"
fi
if $f --verbosity=$Verbosity; then
:
else
status=$?
break 1
fi
done
fi
exit $status
# ############################## end of file ############################# #