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
34 #######################################################################
38 ./validate.sh - build & test
40 Usage: ./validate.sh [options]
41 A script which runs all the tests.
44 -j, --jobs JOBS cabal v2-build -j argument (default: $JOBS)
45 --libonly Test only Cabal-the-library
46 --cli Test both Cabal-the-library and cabal-install
47 --(no-)run-lib-tests Run library tests
48 --(no-)run-cli-tests Run client tests
49 --(no-)run-lib-suite Run cabal-testsuite with library
50 --(no-)run-cli-suite Run cabal-testsuite with client
51 -w, --with-compiler HC With compiler
52 --with-cabal CABAL With cabal-install
53 --with-cabal-plan CABALPLAN With cabal-plan
54 --extra-hc HC Extra compiler to run test-suite with
55 --(no-)doctest Run doctest on library
56 --(no-)solver-benchmarks Build and trial run solver-benchmarks
57 --complete-hackage-tests Run hackage-tests on complete Hackage data
58 --partial-hackage-tests Run hackage-tests on parts of Hackage data
59 -v, --verbose Verbose output
60 -q, --quiet Less output
61 -s, --step STEP Run only specific step (can be specified multiple times)
62 --list-steps List steps and build-targets and exit
63 --help Print this message and exit
68 #######################################################################
76 RESET
='\033[0m' # No Color
78 JOB_START_TIME
=$
(date +%s
)
81 PRETTYCMD
=$
(echo "$@" |
sed -E 's/\/home[^ ]*\/([^\/])/**\/\1/g')
82 echo "$BLUE>>> $PRETTYCMD $RESET"
83 start_time
=$
(date +%s
)
90 # echo "MOCK" > "$OUTPUT"
94 duration
=$
((end_time
- start_time
))
95 tduration
=$
((end_time
- JOB_START_TIME
))
97 if [ $RET -eq 0 ]; then
99 # if output is relatively short, show everything
100 if [ "$(wc -l < "$OUTPUT")" -le 50 ]; then
110 echo "$GREEN<<< $PRETTYCMD $RESET ($duration/$tduration sec)"
119 echo "$RED<<< $PRETTYCMD $RESET ($duration/$tduration sec, $RET)"
120 echo "$RED<<< $* $RESET ($duration/$tduration sec, $RET)"
128 TITLEPAT
="$(echo "$TITLE"|sed 's:.:=:g')"
129 echo "$CYAN===X============================================================ $(date +%T) ===$RESET" \
130 |
sed "s#X$TITLEPAT=# $TITLE #"
135 #######################################################################
137 while [ $# -gt 0 ]; do
205 EXTRAHCS
="$EXTRAHCS $2"
221 --no-solver-benchmarks)
225 --complete-hackage-tests)
229 --partial-hackage-tests)
230 HACKAGETESTSALL
=false
251 echo "Unknown option $arg"
256 # calculate steps and build targets
257 #######################################################################
259 # If there are no explicit steps given calculate them
266 if [ -z "$STEPS" ]; then
267 STEPS
="print-config print-tool-versions"
269 if $DOCTEST; then STEPS
="$STEPS doctest"; fi
270 if $LIBTESTS; then STEPS
="$STEPS lib-tests"; fi
271 if $LIBSUITE; then STEPS
="$STEPS lib-suite"; fi
272 if $LIBSUITE && [ -n "$EXTRAHCS" ];
273 then STEPS
="$STEPS lib-suite-extras"; fi
274 if $CLITESTS; then STEPS
="$STEPS cli-tests"; fi
275 if $CLISUITE; then STEPS
="$STEPS cli-suite"; fi
276 if $BENCHMARKS; then STEPS
="$STEPS solver-benchmarks-tests solver-benchmarks-run"; fi
277 STEPS
="$STEPS time-summary"
280 TARGETS
="Cabal cabal-testsuite Cabal-tests Cabal-QuickCheck Cabal-tree-diff Cabal-described"
281 if ! $LIBONLY; then TARGETS
="$TARGETS cabal-install cabal-install-solver cabal-benchmarks"; fi
282 if $BENCHMARKS; then TARGETS
="$TARGETS solver-benchmarks"; fi
285 echo "Targets: $TARGETS"
290 # Adjust runtime configuration
291 #######################################################################
293 TESTSUITEJOBS
="-j$JOBS"
296 # assume compiler is GHC
297 RUNHASKELL
=$
(echo $HC |
sed -E 's/ghc(-[0-9.]*)$/runghc\1/')
299 if [ "$OSTYPE" = "msys" ]; then
300 ARCH
="x86_64-windows"
301 elif [ "$(uname)" = "Linux" ]; then
308 PROJECTFILE
=cabal.project.validate.libonly
310 PROJECTFILE
=cabal.project.validate
313 BASEHC
=ghc-$
($HC --numeric-version)
314 BUILDDIR
=dist-newstyle-validate-
$BASEHC
315 CABAL_TESTSUITE_BDIR
="$(pwd)/$BUILDDIR/build/$ARCH/$BASEHC/cabal-testsuite-3"
317 CABALNEWBUILD
="${CABAL} v2-build $JOBS -w $HC --builddir=$BUILDDIR --project-file=$PROJECTFILE"
318 CABALPLANLISTBIN
="${CABALPLAN} list-bin --builddir=$BUILDDIR"
321 #######################################################################
323 step_print_config
() {
324 print_header print-config
328 runhaskell: $RUNHASKELL
329 cabal-install: $CABAL
330 cabal-plan: $CABALPLAN
332 Cabal tests: $LIBTESTS
333 cabal-install tests: $CLITESTS
334 cabal-testsuite: $CABALSUITETESTS
335 library only: $LIBONLY
336 dependencies only: $DEPSONLY
338 benchmarks: $BENCHMARKS
340 extra compilers: $EXTRAHCS
345 step_print_tool_versions
() {
346 print_header print-tool-versions
349 timed
$CABAL --version
350 timed
$CABALPLAN --version
352 for EXTRAHC
in $EXTRAHCS; do
353 timed
$EXTRAHC --version
357 step_time_summary
() {
360 JOB_END_TIME
=$
(date +%s
)
361 tduration
=$
((JOB_END_TIME
- JOB_START_TIME
))
363 echo "$CYAN!!! Validation took $tduration seconds. $RESET"
367 #######################################################################
371 timed
$CABALNEWBUILD $TARGETS --dry-run ||
exit 1
372 timed
$CABALNEWBUILD $TARGETS ||
exit 1
376 #######################################################################
379 print_header
"Cabal: doctest"
380 cabal-env
--name doctest-Cabal
--transitive QuickCheck
381 cabal-env
--name doctest-Cabal array bytestring containers deepseq directory filepath pretty process
time binary unix text parsec mtl
382 timed doctest
-package-env=doctest-Cabal
--fast Cabal
/Distribution Cabal
/Language
386 print_header
"Cabal: tests"
388 CMD
="$($CABALPLANLISTBIN Cabal-tests:test:unit-tests) $TESTSUITEJOBS --hide-successes --with-ghc=$HC"
389 (cd Cabal-tests
&& timed
$CMD) ||
exit 1
391 CMD
="$($CABALPLANLISTBIN Cabal-tests:test:check-tests) $TESTSUITEJOBS --hide-successes"
392 (cd Cabal-tests
&& timed
$CMD) ||
exit 1
394 CMD
="$($CABALPLANLISTBIN Cabal-tests:test:parser-tests) $TESTSUITEJOBS --hide-successes"
395 (cd Cabal-tests
&& timed
$CMD) ||
exit 1
397 CMD
="$($CABALPLANLISTBIN Cabal-tests:test:rpmvercmp) $TESTSUITEJOBS --hide-successes"
398 (cd Cabal-tests
&& timed
$CMD) ||
exit 1
400 CMD
="$($CABALPLANLISTBIN Cabal-tests:test:no-thunks-test) $TESTSUITEJOBS --hide-successes"
401 (cd Cabal-tests
&& timed
$CMD) ||
exit 1
403 CMD
=$
($CABALPLANLISTBIN Cabal-tests
:test:hackage-tests
)
404 (cd Cabal-tests
&& timed
$CMD read-fields
) ||
exit 1
405 if $HACKAGETESTSALL; then
406 (cd Cabal-tests
&& timed
$CMD parsec
) ||
exit 1
407 (cd Cabal-tests
&& timed
$CMD roundtrip
) ||
exit 1
409 (cd Cabal-tests
&& timed
$CMD parsec d
) ||
exit 1
410 (cd Cabal-tests
&& timed
$CMD roundtrip k
) ||
exit 1
414 # Cabal cabal-testsuite
415 #######################################################################
418 print_header
"Cabal: cabal-testsuite"
420 CMD
="$($CABALPLANLISTBIN cabal-testsuite:exe:cabal-tests) --builddir=$CABAL_TESTSUITE_BDIR $TESTSUITEJOBS --with-ghc=$HC --hide-successes"
421 (cd cabal-testsuite
&& timed
$CMD) ||
exit 1
424 step_lib_suite_extras
() {
425 for EXTRAHC
in $EXTRAHCS; do
427 CMD
="$($CABALPLANLISTBIN cabal-testsuite:exe:cabal-tests) --builddir=$CABAL_TESTSUITE_BDIR $TESTSUITEJOBS --with-ghc=$EXTRAHC --hide-successes"
428 (cd cabal-testsuite
&& timed
$CMD) ||
exit 1
434 #######################################################################
437 print_header
"cabal-install: tests"
439 # this are sorted in asc time used, quicker tests first.
440 CMD
="$($CABALPLANLISTBIN cabal-install:test:long-tests) $TESTSUITEJOBS --hide-successes"
441 (cd cabal-install
&& timed
$CMD) ||
exit 1
443 # This doesn't work in parallel either
444 CMD
="$($CABALPLANLISTBIN cabal-install:test:unit-tests) -j1 --hide-successes"
445 (cd cabal-install
&& timed
$CMD) ||
exit 1
447 # Only single job, otherwise we fail with "Heap exhausted"
448 CMD
="$($CABALPLANLISTBIN cabal-install:test:mem-use-tests) -j1 --hide-successes"
449 (cd cabal-install
&& timed
$CMD) ||
exit 1
451 # This test-suite doesn't like concurrency
452 CMD
="$($CABALPLANLISTBIN cabal-install:test:integration-tests2) -j1 --hide-successes --with-ghc=$HC"
453 (cd cabal-install
&& timed
$CMD) ||
exit 1
456 # cabal-install cabal-testsuite
457 #######################################################################
460 print_header
"cabal-install: cabal-testsuite"
462 CMD
="$($CABALPLANLISTBIN cabal-testsuite:exe:cabal-tests) --builddir=$CABAL_TESTSUITE_BDIR --with-cabal=$($CABALPLANLISTBIN cabal-install:exe:cabal) $TESTSUITEJOBS --with-ghc=$HC --hide-successes"
463 (cd cabal-testsuite
&& timed
$CMD) ||
exit 1
467 #######################################################################
469 step_solver_benchmarks_tests
() {
470 print_header
"solver-benchmarks: test"
472 CMD
="$($CABALPLANLISTBIN solver-benchmarks:test:unit-tests)"
473 (cd Cabal
&& timed
$CMD) ||
exit 1
476 step_solver_benchmarks_run
() {
477 print_header
"solver-benchmarks: run"
479 SOLVEPKG
=Chart-diagrams
480 CMD
="$($CABALPLANLISTBIN solver-benchmarks:exe:hackage-benchmark) --cabal1=$CABAL --cabal2=$($CABALPLANLISTBIN cabal-install:exe:cabal) --trials=5 --packages=$SOLVEPKG --print-trials"
481 (cd Cabal
&& timed
$CMD) ||
exit 1
485 #######################################################################
487 for step
in $STEPS; do
489 print-config
) step_print_config
;;
490 print-tool-versions
) step_print_tool_versions
;;
492 doctest
) step_doctest
;;
493 lib-tests
) step_lib_tests
;;
494 cli-tests
) step_cli_tests
;;
495 lib-suite
) step_lib_suite
;;
496 lib-suite-extras
) step_lib_suite_extras
;;
497 cli-suite
) step_cli_suite
;;
498 solver-benchmarks-tests
) step_solver_benchmarks_tests
;;
499 solver-benchmarks-run
) step_solver_benchmarks_run
;;
500 time-summary
) step_time_summary
;;
502 echo "Invalid step $step"
508 #######################################################################