forked from haskell/cabal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
validate.sh
executable file
·377 lines (281 loc) · 11.1 KB
/
validate.sh
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
#!/bin/sh
# shellcheck disable=SC2086
# default config
#######################################################################
HC=ghc-8.2.2
CABAL=cabal
CABALPLAN=cabal-plan
JOBS=4
CABALTESTS=true
CABALINSTALLTESTS=true
CABALSUITETESTS=true
CABALONLY=false
DEPSONLY=false
DOCTEST=false
BENCHMARKS=false
VERBOSE=false
# Help
#######################################################################
show_usage() {
cat <<EOF
./validate.sh - build & test
Usage: ./validate.sh [ -j JOBS | -l | -C | -c | -s | -w HC | -x CABAL | -y CABALPLAN | -d | -D | -b | -v ]
A script which runs all the tests.
Available options:
-j JOBS cabal v2-build -j argument (default: $JOBS)
-l Test Cabal-the-library only (default: $CABALONLY)
-C Don't run Cabal tests (default: $CABALTESTS)
-c Don't run cabal-install tests (default: $CABALINSTALLTESTS)
-s Don't run cabal-testsuite tests (default: $CABALSUITETESTS)
-w HC With compiler
-x CABAL With cabal-install
-y CABALPLAN With cabal-plan
-d Build dependencies only
-D Run doctest
-b Run benchmarks (quick run, verify they work)
-v Verbose
EOF
exit 0
}
# "library"
#######################################################################
OUTPUT=$(mktemp)
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
CYAN='\033[0;96m'
RESET='\033[0m' # No Color
JOB_START_TIME=$(date +%s)
timed() {
PRETTYCMD=$(echo "$@" | sed -E 's/\/home[^ ]*\/([^\/])/**\/\1/g')
echo "$BLUE>>> $PRETTYCMD $RESET"
start_time=$(date +%s)
if $VERBOSE; then
"$@" 2>&1
else
"$@" > "$OUTPUT" 2>&1
fi
# echo "MOCK" > "$OUTPUT"
RET=$?
end_time=$(date +%s)
duration=$((end_time - start_time))
tduration=$((end_time - JOB_START_TIME))
if [ $RET -eq 0 ]; then
if ! $VERBOSE; then
# if output is relatively short, show everything
if [ "$(wc -l < "$OUTPUT")" -le 50 ]; then
cat "$OUTPUT"
else
echo "..."
tail -n 20 "$OUTPUT"
fi
rm -f "$OUTPUT"
fi
echo "$GREEN<<< $PRETTYCMD $RESET ($duration/$tduration sec)"
# bottom-margin
echo ""
else
if ! $VERBOSE; then
cat "$OUTPUT"
fi
echo "$RED<<< $PRETTYCMD $RESET ($duration/$tduration sec, $RET)"
echo "$RED<<< $* $RESET ($duration/$tduration sec, $RET)"
rm -f "$OUTPUT"
exit 1
fi
}
footer() {
JOB_END_TIME=$(date +%s)
tduration=$((JOB_END_TIME - JOB_START_TIME))
echo "$CYAN=== END ============================================ $(date +%T) === $RESET"
echo "$CYAN!!! Validation took $tduration seconds. $RESET"
}
# getopt
#######################################################################
while getopts 'j:lCcsw:x:y:dDbv' flag; do
case $flag in
j) JOBS="$OPTARG"
;;
l) CABALONLY=true
;;
C) CABALTESTS=false
;;
c) CABALINSTALLTESTS=false
;;
s) CABALSUITETESTS=false
;;
w) HC="$OPTARG"
;;
x) CABAL="$OPTARG"
;;
y) CABALPLAN="$OPTARG"
;;
d) DEPSONLY=true
;;
D) DOCTEST=true
;;
b) BENCHMARKS=true
;;
v) VERBOSE=true
;;
?) show_usage
;;
esac
done
shift $((OPTIND - 1))
# header
#######################################################################
if [ "xhelp" = "x$1" ]; then
show_usage;
fi
TESTSUITEJOBS="-j$JOBS"
JOBS="-j$JOBS"
# assume compiler is GHC
RUNHASKELL=$(echo $HC | sed -E 's/ghc(-[0-9.]*)$/runghc\1/')
echo "$CYAN=== validate.sh ======================================== $(date +%T) === $RESET"
cat <<EOF
compiler: $HC
runhaskell $RUNHASKELL
cabal-install: $CABAL
cabal-plan: $CABALPLAN
jobs: $JOBS
Cabal tests: $CABALTESTS
cabal-install tests: $CABALINSTALLTESTS
cabal-testsuite: $CABALSUITETESTS
library only: $CABALONLY
dependencies only: $DEPSONLY
doctest: $DOCTEST
benchmarks: $BENCHMARKS
verbose: $VERBOSE
EOF
timed $HC --version
timed $CABAL --version
timed $CABALPLAN --version
# Basic setup
#######################################################################
if [ "$(uname)" = "Linux" ]; then
ARCH="x86_64-linux"
else
ARCH="x86_64-osx"
fi
if $CABALONLY; then
PROJECTFILE=cabal.project.validate.libonly
else
PROJECTFILE=cabal.project.validate
fi
BASEHC=ghc-$($HC --numeric-version)
BUILDDIR=dist-newstyle-validate-$BASEHC
CABAL_TESTSUITE_BDIR="$(pwd)/$BUILDDIR/build/$ARCH/$BASEHC/cabal-testsuite-3"
CABALNEWBUILD="${CABAL} v2-build $JOBS -w $HC --builddir=$BUILDDIR --project-file=$PROJECTFILE"
CABALPLANLISTBIN="${CABALPLAN} list-bin --builddir=$BUILDDIR"
# SCRIPT
#######################################################################
if ! $CABALONLY; then
echo "$CYAN=== make cabal-install-dev ============================= $(date +%T) === $RESET"
# make cabal-install-dev
timed ${RUNHASKELL} cabal-dev-scripts/src/Preprocessor.hs -o cabal-install/cabal-install.cabal -f CABAL_FLAG_LIB cabal-install/cabal-install.cabal.pp
fi # CABALONLY
# Dependencies
if $DEPSONLY; then
echo "$CYAN=== dependencies ====================================== $(date +%T) === $RESET"
timed $CABALNEWBUILD Cabal:lib:Cabal --enable-tests --disable-benchmarks --dep --dry-run || exit 1
timed $CABALNEWBUILD Cabal:lib:Cabal --enable-tests --disable-benchmarks --dep || exit 1
if $CABALTESTS; then
timed $CABALNEWBUILD Cabal --enable-tests --disable-benchmarks --dep --dry-run || exit 1
timed $CABALNEWBUILD Cabal --enable-tests --disable-benchmarks --dep || exit 1
fi
# Unfortunately we can not install cabal-install or cabal-testsuite dependencies:
# that would build Cabal-lib!
footer
exit
fi # DEPSONLY
# Cabal lib
#######################################################################
echo "$CYAN=== Cabal: build ======================================= $(date +%T) === $RESET"
timed $CABALNEWBUILD Cabal:lib:Cabal --enable-tests --disable-benchmarks --dry-run || exit 1
timed $CABALNEWBUILD Cabal:lib:Cabal --enable-tests --disable-benchmarks --dep || exit 1
timed $CABALNEWBUILD Cabal:lib:Cabal --enable-tests --disable-benchmarks || exit 1
if $DOCTEST; then
if command -v doctest >/dev/null; then
echo "$CYAN=== Cabal: doctest ===================================== $(date +%T) === $RESET"
timed $CABALNEWBUILD Cabal:lib:Cabal --enable-tests --disable-benchmarks --write-ghc-environment-files=always || exit 1
timed doctest --fast Cabal/Distribution Cabal/Language
timed rm -f .ghc.environment.*
else
echo "No doctest command found"
fi # command -v doctest
fi # DOCTEST
if $CABALTESTS; then
echo "$CYAN=== Cabal: test ======================================== $(date +%T) === $RESET"
timed $CABALNEWBUILD Cabal:tests --enable-tests --disable-benchmarks --dry-run || exit 1
timed $CABALNEWBUILD Cabal:tests --enable-tests --disable-benchmarks --dep || exit 1
timed $CABALNEWBUILD Cabal:tests --enable-tests --disable-benchmarks || exit 1
CMD="$($CABALPLANLISTBIN Cabal:test:unit-tests) $TESTSUITEJOBS --hide-successes --with-ghc=$HC"
(cd Cabal && timed $CMD) || exit 1
CMD="$($CABALPLANLISTBIN Cabal:test:check-tests) $TESTSUITEJOBS --hide-successes"
(cd Cabal && timed $CMD) || exit 1
CMD="$($CABALPLANLISTBIN Cabal:test:parser-tests) $TESTSUITEJOBS --hide-successes"
(cd Cabal && timed $CMD) || exit 1
CMD=$($CABALPLANLISTBIN Cabal:test:hackage-tests)
(cd Cabal && timed $CMD read-fields) || exit 1
(cd Cabal && timed $CMD parsec d) || exit 1
(cd Cabal && timed $CMD roundtrip k) || exit 1
fi # $CABALTESTS
if $CABALSUITETESTS; then
echo "$CYAN=== cabal-testsuite: build ============================= $(date +%T) === $RESET"
timed $CABALNEWBUILD cabal-testsuite --enable-tests --disable-benchmarks --dry-run || exit 1
timed $CABALNEWBUILD cabal-testsuite --enable-tests --disable-benchmarks --dep || exit 1
timed $CABALNEWBUILD cabal-testsuite --enable-tests --disable-benchmarks || exit 1
echo "$CYAN=== cabal-testsuite: Cabal test ======================== $(date +%T) === $RESET"
CMD="$($CABALPLANLISTBIN cabal-testsuite:exe:cabal-tests) --builddir=$CABAL_TESTSUITE_BDIR $TESTSUITEJOBS --with-ghc=$HC --hide-successes"
(cd cabal-testsuite && timed $CMD) || exit 1
fi # CABALSUITETESTS (Cabal)
# If testing only library, stop here
if $CABALONLY; then
footer
exit
fi
# cabal-install
#######################################################################
echo "$CYAN=== cabal-install: build =============================== $(date +%T) === $RESET"
timed $CABALNEWBUILD cabal-install --enable-tests --disable-benchmarks --dry-run || exit 1
# For some reason this sometimes fails. So we try twice.
CMD="$CABALNEWBUILD cabal-install --enable-tests --disable-benchmarks"
(timed $CMD) || (timed $CMD) || exit 1
if $CABALINSTALLTESTS; then
echo "$CYAN=== cabal-install: test ================================ $(date +%T) === $RESET"
# this are sorted in asc time used, quicker tests first.
CMD="$($CABALPLANLISTBIN cabal-install:test:solver-quickcheck) $TESTSUITEJOBS --hide-successes"
(cd cabal-install && timed $CMD) || exit 1
# This doesn't work in parallel either
CMD="$($CABALPLANLISTBIN cabal-install:test:unit-tests) -j1 --hide-successes"
(cd cabal-install && timed $CMD) || exit 1
# Only single job, otherwise we fail with "Heap exhausted"
CMD="$($CABALPLANLISTBIN cabal-install:test:memory-usage-tests) -j1 --hide-successes"
(cd cabal-install && timed $CMD) || exit 1
# This test-suite doesn't like concurrency
CMD="$($CABALPLANLISTBIN cabal-install:test:integration-tests2) -j1 --hide-successes --with-ghc=$HC"
(cd cabal-install && timed $CMD) || exit 1
fi # CABALINSTALLTESTS
if $CABALSUITETESTS; then
echo "$CYAN=== cabal-testsuite: cabal-install test ================ $(date +%T) === $RESET"
CMD="$($CABALPLANLISTBIN cabal-testsuite:exe:cabal-tests) --builddir=$CABAL_TESTSUITE_BDIR --with-cabal=$($CABALPLANLISTBIN cabal-install:exe:cabal) $TESTSUITEJOBS --hide-successes"
(cd cabal-testsuite && timed $CMD) || exit 1
fi # CABALSUITETESTS
# solver-benchmarks
#######################################################################
if $BENCHMARKS; then
echo "$CYAN=== solver-benchmarks: build =========================== $(date +%T) === $RESET"
timed $CABALNEWBUILD solver-benchmarks:hackage-benchmark solver-benchmarks:unit-tests --enable-tests
echo "$CYAN=== solver-benchmarks: test ============================ $(date +%T) === $RESET"
CMD="$($CABALPLANLISTBIN solver-benchmarks:test:unit-tests)"
(cd Cabal && timed $CMD) || exit 1
echo "$CYAN=== solver-benchmarks: run ============================= $(date +%T) === $RESET"
SOLVEPKG=Chart-diagrams
CMD="$($CABALPLANLISTBIN solver-benchmarks:exe:hackage-benchmark) --cabal1=$CABAL --cabal2=$($CABALPLANLISTBIN cabal-install:exe:cabal) --trials=5 --packages=$SOLVEPKG --print-trials"
(cd Cabal && timed $CMD) || exit 1
fi
# END
#######################################################################
footer
#######################################################################