-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest
executable file
·259 lines (199 loc) · 4.23 KB
/
test
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#!/bin/sh
set -e -u
buildProductsDir=$( pwd )
projectDir=$( dirname "$0" )
# Make projectDir absolute
case $projectDir in
/*) ;;
*) projectDir="$buildProductsDir/$projectDir"
esac
. "$projectDir/shared.inc"
printHelp()
{
help='
SYNTAX
------
./test [options] ... [test] ...
OPTIONS
-------
-help Show this help screen.
-list List available test and exit.
-clean Make a clean build.
-norun Build but do not run tests.
-debug Build the tests with debug configuration.
'
printf '%s\n' "$help"
exit "$1"
}
list=
clean=
debug=
norun=
while [ $# -gt 0 ]
do
case $1 in
-help) printHelp 0 ;;
-list) list=true ;;
-clean) clean=true ;;
-norun) norun=true ;;
-debug) debug=true ;;
-*) syntaxError "Unkown option \"$1\"" ;;
*) break
esac
shift
done
testList=
while [ $# -gt 0 ]
do
case $1 in
*) testList="$testList $1"
esac
shift
done
srcDir="$projectDir/tests/code"
if [ -n "$list" ]
then
cd "$srcDir"
find . -type d -depth 1 | sed 's#^./##'
exit 0
fi
srcDirList=
if [ -n "$testList" ]
then
for test in $testList
do
if [ ! -d "$srcDir/$test" ]
then
error "Test \"$test\" not found!"
fi
srcDirList="$srcDirList \"$srcDir/$test\""
done
else
srcDirList="\"$srcDir\""
fi
buildStyle='test'
cfgFile="$projectDir/cfg/test.cfg"
if [ -n "$debug" ]
then
buildStyle='debugtest'
cfgFile="$projectDir/cfg/debugtest.cfg"
fi
buildDir="$buildProductsDir/tests"
binDir="$buildDir/bin"
objDir="$buildDir/objects"
lastBuildCfg="$buildDir/last.cfg"
if [ -n "$clean" ] \
|| ( [ -f "$lastBuildCfg" ] && ! cmp -s "$lastBuildCfg" "$cfgFile" )
then
rm -r "$buildDir"
"$projectDir/build" "$buildStyle" -clean
else
"$projectDir/build" "$buildStyle"
fi
[ -d "$buildDir" ] || mkdir -p "$buildDir"
[ -f "$lastBuildCfg" ] || cp "$cfgFile" "$lastBuildCfg"
buildArgs=
parseCfgFile buildArgs "$cfgFile"
srcFileList="$buildDir/sources.txt"
eval "find $srcDirList -name \"*.c\" >\"$srcFileList\""
echo
echo '=== Building Tests ==='
[ -z "$clean" ] || echo "(clean build)"
echo
while IFS='' read -r srcFile
do
echo "Next: ${srcFile#"$projectDir/"}"
objFile="$objDir/${srcFile#"$srcDir/"}.o"
flagsFile=$( findCompileFlags "$srcFile" "$projectDir" )
flagsFileDir=
flagsFileContent=
if [ -n "$flagsFile" ]
then
parseCfgFile flagsFileContent "$flagsFile"
flagsFileDir=$( dirname "$flagsFile" )
fi
if ! objectFileIsOutdated \
"$objFile" "$srcFile" \
"$flagsFileContent" "$flagsFileDir"
then
echo 'Nothing to do.'
echo
continue
fi
objFileDir=$( dirname "$objFile" )
[ -d "$objFileDir" ] || mkdir -p "$objFileDir"
buildCmd="clang -c -o $( quote "$objFile" )"
buildCmd="$buildCmd $flagsFileContent $buildArgs"
buildCmd="$buildCmd $(quote "$srcFile" )"
if [ -n "$flagsFileDir" ]
then
buildCmd="( cd $( quote "$flagsFileDir" ) && $buildCmd )"
fi
if ! eval "$buildCmd"
then
echo "Error: Building failed!" >&2
echo "Build command was: $buildCmd" >&2
exit 1
fi
echo "Created ${objFile#"$buildProductsDir/"}"
echo
done <"$srcFileList"
echo
echo '=== Linking Tests ==='
echo
libFile="$buildProductsDir/$LIBNAME"
[ -d "$binDir" ] || mkdir -p "$binDir"
for testDir in "$objDir"/*
do
binName=$( basename "$testDir" )
binFile="$binDir/$binName"
if [ -n "$testList" ]
then
case $testList in
"$binName "*|*" $binName "*|*" $binName") ;;
*) continue
esac
fi
echo "Next: $binName"
if [ -f "$binFile" ] \
&& ! anyFileIsNewerThan "$binFile" "$libFile" "$testDir"
then
echo 'Nothing to do.'
echo
continue
fi
objFileList="$buildDir/objects.txt"
find "$testDir" -name "*.o" >"$objFileList"
linkCmd="clang -o $( quote "$binFile" )"
if shouldLinkAddressSanitizer "$buildArgs"
then
linkCmd="$linkCmd -fsanitize=address"
fi
linkCmd="$linkCmd $( quote "$libFile" )"
while IFS='' read -r objFile
do
linkCmd="$linkCmd $( quote "$objFile" )"
done <"$objFileList"
eval "$linkCmd"
echo "Created ${binFile#"$buildProductsDir/"}"
echo
done
[ -n "$norun" ] && exit 0
echo
echo '=== Running Tests ==='
echo
for test in "$binDir"/*
do
testName="$( basename "$test" )"
if [ -n "$testList" ]
then
case $testList in
"$testName "*|*" $testName "*|*" $testName") ;;
*) continue
esac
fi
[ -x "$test" ] || continue
echo "Next: $testName"
"$test" && echo "Test succeeded."
echo
done