2 # shellcheck disable=SC2086
5 #######################################################################
7 # We use the default ghc in PATH as default
8 # Use the ghc-x.y.z trigger several errors in windows:
9 # * It triggers the max path length issue:
10 # See https://github.com/haskell/cabal/issues/6271#issuecomment-1065102255
11 # * It triggers a `createProcess: does not exist` error in units tests
12 # See https://github.com/haskell/cabal/issues/8049
33 #######################################################################
37 ./validate.sh - build & test
39 Usage: ./validate.sh [options]
40 A script which runs all the tests.
43 -j, --jobs JOBS cabal build -j argument (default: $JOBS)
44 --libonly Test only Cabal-the-library
45 --cli Test both Cabal-the-library and cabal-install
46 --(no-)run-lib-tests Run library tests
47 --(no-)run-cli-tests Run client tests
48 --(no-)run-lib-suite Run cabal-testsuite with library
49 --(no-)run-cli-suite Run cabal-testsuite with client
50 -w, --with-compiler HC With compiler
51 --with-cabal CABAL With cabal-install
52 --extra-hc HC Extra compiler to run test-suite with
53 --(no-)doctest Run doctest on library
54 --(no-)solver-benchmarks Build and trial run solver-benchmarks
55 --complete-hackage-tests Run hackage-tests on complete Hackage data
56 --partial-hackage-tests Run hackage-tests on parts of Hackage data
57 -v, --verbose Verbose output
58 -q, --quiet Less output
59 -s, --step STEP Run only specific step (can be specified multiple times)
60 --list-steps List steps and build-targets and exit
61 --help Print this message and exit
66 #######################################################################
70 # `red` and `green` are used to output also the spent time in white at the end.
71 # `blue` and `cyan` are used to print the spawned command, so they only have one
74 printf "\033[0;31m%s\033[0m %s \n" "$1" "$2"
77 printf "\033[0;32m%s\033[0m %s \n" "$1" "$2"
80 printf "\033[0;34m%s\033[0m\n" "$1"
83 printf "\033[0;96m%s\033[0m\n" "$1"
86 JOB_START_TIME
=$
(date +%s
)
89 PRETTYCMD
=$
(echo "$@" |
sed -E 's/\/home[^ ]*\/([^\/])/**\/\1/g')
91 start_time
=$
(date +%s
)
98 # echo "MOCK" > "$OUTPUT"
102 duration
=$
((end_time
- start_time
))
103 tduration
=$
((end_time
- JOB_START_TIME
))
105 if [ $RET -eq 0 ]; then
107 # if output is relatively short, show everything
108 if [ "$(wc -l < "$OUTPUT")" -le 50 ]; then
118 green
"<<< $PRETTYCMD" "($duration/$tduration sec)"
127 red
"<<< $PRETTYCMD" "($duration/$tduration sec, $RET)"
128 red
"<<< $*" "($duration/$tduration sec, $RET)"
136 TITLEPAT
="$(echo "$TITLE"|sed 's:.:=:g')"
137 cyan
"===X========================================================================== $(date +%T) ===" \
138 |
sed "s#X$TITLEPAT=# $TITLE #"
143 #######################################################################
145 while [ $# -gt 0 ]; do
208 EXTRAHCS
="$EXTRAHCS $2"
224 --no-solver-benchmarks)
228 --complete-hackage-tests)
232 --partial-hackage-tests)
233 HACKAGETESTSALL
=false
254 echo "Unknown option $arg"
259 # calculate steps and build targets
260 #######################################################################
262 # If there are no explicit steps given calculate them
269 if [ -z "$STEPS" ]; then
270 STEPS
="print-config print-tool-versions"
272 if $DOCTEST; then STEPS
="$STEPS doctest"; fi
273 if $LIBTESTS; then STEPS
="$STEPS lib-tests"; fi
274 if $LIBSUITE; then STEPS
="$STEPS lib-suite"; fi
275 if $LIBSUITE && [ -n "$EXTRAHCS" ];
276 then STEPS
="$STEPS lib-suite-extras"; fi
277 if $CLITESTS; then STEPS
="$STEPS cli-tests"; fi
278 if $CLISUITE; then STEPS
="$STEPS cli-suite"; fi
279 if $BENCHMARKS; then STEPS
="$STEPS solver-benchmarks-tests solver-benchmarks-run"; fi
280 STEPS
="$STEPS time-summary"
283 TARGETS
="Cabal Cabal-hooks cabal-testsuite Cabal-tests Cabal-QuickCheck Cabal-tree-diff Cabal-described"
284 if ! $LIBONLY; then TARGETS
="$TARGETS cabal-install cabal-install-solver cabal-benchmarks"; fi
285 if $BENCHMARKS; then TARGETS
="$TARGETS solver-benchmarks"; fi
288 echo "Targets: $TARGETS"
293 # Adjust runtime configuration
294 #######################################################################
296 TESTSUITEJOBS
="-j$JOBS"
299 # assume compiler is GHC
300 RUNHASKELL
=$
(echo "$HC" |
sed -E 's/ghc(-[0-9.]*)$/runghc\1/')
304 ARCH
="x86_64-windows"
315 PROJECTFILE
=cabal.validate-libonly.project
317 PROJECTFILE
=cabal.validate.project
320 BASEHC
=ghc-$
($HC --numeric-version)
321 BUILDDIR
=dist-newstyle-validate-
$BASEHC
322 CABAL_TESTSUITE_BDIR
="$(pwd)/$BUILDDIR/build/$ARCH/$BASEHC/cabal-testsuite-3"
324 CABALNEWBUILD
="${CABAL} build $JOBS -w $HC --builddir=$BUILDDIR --project-file=$PROJECTFILE"
325 CABALLISTBIN
="${CABAL} list-bin --builddir=$BUILDDIR --project-file=$PROJECTFILE"
327 # This was needed in some local Windows MSYS2 environments
328 # but breaks CI for Windows + GHC 9.0.2, thus it is set only on non-CI executions
330 # https://github.com/haskell/cabal/issues/9571
331 # https://github.com/haskell/cabal/pull/10114
332 RTSOPTS
="$([[ $ARCH = "x86_64-windows
" && -z "$CI" ]] && echo "+RTS
--io-manager=native
" || echo "")"
335 #######################################################################
337 step_print_config
() {
338 print_header print-config
342 runhaskell: $RUNHASKELL
343 cabal-install: $CABAL
345 Cabal tests: $LIBTESTS
346 cabal-install tests: $CLITESTS
347 cabal-testsuite: $CABALSUITETESTS
348 library only: $LIBONLY
349 dependencies only: $DEPSONLY
351 benchmarks: $BENCHMARKS
353 extra compilers: $EXTRAHCS
354 extra RTS options: $RTSOPTS
359 step_print_tool_versions
() {
360 print_header print-tool-versions
362 timed
"$HC" --version
363 timed
"$CABAL" --version
365 for EXTRAHC
in $EXTRAHCS; do
366 timed
"$EXTRAHC" --version
370 step_time_summary
() {
373 JOB_END_TIME
=$
(date +%s
)
374 tduration
=$
((JOB_END_TIME
- JOB_START_TIME
))
376 cyan
"!!! Validation took $tduration seconds."
380 #######################################################################
384 print_header
"Step Build: dry run"
385 timed
$CABALNEWBUILD $TARGETS --dry-run ||
exit 1
386 print_header
"Step Build: full build plan (cached and to-be-built dependencies):"
387 jq
-r '."install-plan" | map(."pkg-name" + "-" + ."pkg-version" + " " + ."component-name") | join("\n")' "$BUILDDIR/cache/plan.json"
388 print_header
"Step Build: actual build"
389 timed
$CABALNEWBUILD $TARGETS ||
exit 1
393 #######################################################################
396 print_header
"Cabal: doctest"
397 cabal-env
--name doctest-Cabal
--transitive QuickCheck
398 cabal-env
--name doctest-Cabal array bytestring containers deepseq directory filepath pretty process
time binary unix text parsec mtl
399 timed doctest
-package-env=doctest-Cabal
--fast Cabal
/Distribution Cabal
/Language
403 print_header
"Cabal: tests"
405 CMD
="$($CABALLISTBIN Cabal-tests:test:unit-tests) $TESTSUITEJOBS --hide-successes --with-ghc=$HC"
406 (cd Cabal-tests
&& timed
$CMD) ||
exit 1
408 CMD
="$($CABALLISTBIN Cabal-tests:test:check-tests) $TESTSUITEJOBS --hide-successes"
409 (cd Cabal-tests
&& timed
$CMD) ||
exit 1
411 CMD
="$($CABALLISTBIN Cabal-tests:test:parser-tests) $TESTSUITEJOBS --hide-successes"
412 (cd Cabal-tests
&& timed
$CMD) ||
exit 1
414 CMD
="$($CABALLISTBIN Cabal-tests:test:rpmvercmp) $TESTSUITEJOBS --hide-successes"
415 (cd Cabal-tests
&& timed
$CMD) ||
exit 1
417 CMD
="$($CABALLISTBIN Cabal-tests:test:no-thunks-test) $TESTSUITEJOBS --hide-successes"
418 (cd Cabal-tests
&& timed
$CMD) ||
exit 1
420 CMD
=$
($CABALLISTBIN Cabal-tests
:test:hackage-tests
)
421 (cd Cabal-tests
&& timed
$CMD read-fields
) ||
exit 1
422 if $HACKAGETESTSALL; then
423 (cd Cabal-tests
&& timed
$CMD parsec
) ||
exit 1
424 (cd Cabal-tests
&& timed
$CMD roundtrip
) ||
exit 1
426 (cd Cabal-tests
&& timed
$CMD parsec d
) ||
exit 1
427 (cd Cabal-tests
&& timed
$CMD roundtrip k
) ||
exit 1
431 # Cabal cabal-testsuite
432 #######################################################################
435 print_header
"Cabal: cabal-testsuite"
437 CMD
="$($CABALLISTBIN cabal-testsuite:exe:cabal-tests) --builddir=$CABAL_TESTSUITE_BDIR $TESTSUITEJOBS --with-ghc=$HC --hide-successes $RTSOPTS"
438 (cd cabal-testsuite
&& timed
$CMD) ||
exit 1
441 step_lib_suite_extras
() {
442 for EXTRAHC
in $EXTRAHCS; do
444 CMD
="$($CABALLISTBIN cabal-testsuite:exe:cabal-tests) --builddir=$CABAL_TESTSUITE_BDIR $TESTSUITEJOBS --with-ghc=$EXTRAHC --hide-successes"
445 (cd cabal-testsuite
&& timed
$CMD) ||
exit 1
451 #######################################################################
454 print_header
"cabal-install: tests"
456 # this are sorted in asc time used, quicker tests first.
457 CMD
="$($CABALLISTBIN cabal-install:test:long-tests) $TESTSUITEJOBS --hide-successes"
458 (cd cabal-install
&& timed
$CMD) ||
exit 1
460 # This doesn't work in parallel either
461 CMD
="$($CABALLISTBIN cabal-install:test:unit-tests) -j1 --hide-successes"
462 (cd cabal-install
&& timed
$CMD) ||
exit 1
464 # Only single job, otherwise we fail with "Heap exhausted"
465 CMD
="$($CABALLISTBIN cabal-install:test:mem-use-tests) -j1 --hide-successes"
466 (cd cabal-install
&& timed
$CMD) ||
exit 1
468 # This test-suite doesn't like concurrency
469 CMD
="$($CABALLISTBIN cabal-install:test:integration-tests2) -j1 --hide-successes --with-ghc=$HC"
470 (cd cabal-install
&& timed
$CMD) ||
exit 1
473 # cabal-install cabal-testsuite
474 #######################################################################
477 print_header
"cabal-install: cabal-testsuite"
479 CMD
="$($CABALLISTBIN cabal-testsuite:exe:cabal-tests) --builddir=$CABAL_TESTSUITE_BDIR --with-cabal=$($CABALLISTBIN cabal-install:exe:cabal) $TESTSUITEJOBS --with-ghc=$HC --hide-successes --intree-cabal-lib=$PWD --test-tmp=$PWD/testdb $RTSOPTS"
480 (cd cabal-testsuite
&& timed
$CMD) ||
exit 1
484 #######################################################################
486 step_solver_benchmarks_tests
() {
487 print_header
"solver-benchmarks: test"
489 CMD
="$($CABALLISTBIN solver-benchmarks:test:unit-tests)"
490 (cd Cabal
&& timed
$CMD) ||
exit 1
493 step_solver_benchmarks_run
() {
494 print_header
"solver-benchmarks: run"
496 SOLVEPKG
=Chart-diagrams
497 CMD
="$($CABALLISTBIN solver-benchmarks:exe:hackage-benchmark) --cabal1=$CABAL --cabal2=$($CABALLISTBIN cabal-install:exe:cabal) --trials=5 --packages=$SOLVEPKG --print-trials"
498 (cd Cabal
&& timed
$CMD) ||
exit 1
502 #######################################################################
504 for step
in $STEPS; do
506 print-config
) step_print_config
;;
507 print-tool-versions
) step_print_tool_versions
;;
509 doctest
) step_doctest
;;
510 lib-tests
) step_lib_tests
;;
511 cli-tests
) step_cli_tests
;;
512 lib-suite
) step_lib_suite
;;
513 lib-suite-extras
) step_lib_suite_extras
;;
514 cli-suite
) step_cli_suite
;;
515 solver-benchmarks-tests
) step_solver_benchmarks_tests
;;
516 solver-benchmarks-run
) step_solver_benchmarks_run
;;
517 time-summary
) step_time_summary
;;
519 echo "Invalid step $step"
525 #######################################################################