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 mutliple 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 # hackage-tests is not buildable in windows so $CMD will be empty here
405 if [ "$OSTYPE" != "msys" ]; then
406 (cd Cabal-tests
&& timed
$CMD read-fields
) ||
exit 1
407 if $HACKAGETESTSALL; then
408 (cd Cabal-tests
&& timed
$CMD parsec
) ||
exit 1
409 (cd Cabal-tests
&& timed
$CMD roundtrip
) ||
exit 1
411 (cd Cabal-tests
&& timed
$CMD parsec d
) ||
exit 1
412 (cd Cabal-tests
&& timed
$CMD roundtrip k
) ||
exit 1
418 # Cabal cabal-testsuite
419 #######################################################################
422 print_header
"Cabal: cabal-testsuite"
424 CMD
="$($CABALPLANLISTBIN cabal-testsuite:exe:cabal-tests) --builddir=$CABAL_TESTSUITE_BDIR $TESTSUITEJOBS --with-ghc=$HC --hide-successes"
425 (cd cabal-testsuite
&& timed
$CMD) ||
exit 1
428 step_lib_suite_extras
() {
429 for EXTRAHC
in $EXTRAHCS; do
431 CMD
="$($CABALPLANLISTBIN cabal-testsuite:exe:cabal-tests) --builddir=$CABAL_TESTSUITE_BDIR $TESTSUITEJOBS --with-ghc=$EXTRAHC --hide-successes"
432 (cd cabal-testsuite
&& timed
$CMD) ||
exit 1
438 #######################################################################
441 print_header
"cabal-install: tests"
443 # this are sorted in asc time used, quicker tests first.
444 CMD
="$($CABALPLANLISTBIN cabal-install:test:long-tests) $TESTSUITEJOBS --hide-successes"
445 (cd cabal-install
&& timed
$CMD) ||
exit 1
447 # This doesn't work in parallel either
448 CMD
="$($CABALPLANLISTBIN cabal-install:test:unit-tests) -j1 --hide-successes"
449 (cd cabal-install
&& timed
$CMD) ||
exit 1
451 # Only single job, otherwise we fail with "Heap exhausted"
452 CMD
="$($CABALPLANLISTBIN cabal-install:test:mem-use-tests) -j1 --hide-successes"
453 (cd cabal-install
&& timed
$CMD) ||
exit 1
455 # This test-suite doesn't like concurrency
456 CMD
="$($CABALPLANLISTBIN cabal-install:test:integration-tests2) -j1 --hide-successes --with-ghc=$HC"
457 (cd cabal-install
&& timed
$CMD) ||
exit 1
460 # cabal-install cabal-testsuite
461 #######################################################################
464 print_header
"cabal-install: cabal-testsuite"
466 CMD
="$($CABALPLANLISTBIN cabal-testsuite:exe:cabal-tests) --builddir=$CABAL_TESTSUITE_BDIR --with-cabal=$($CABALPLANLISTBIN cabal-install:exe:cabal) $TESTSUITEJOBS --with-ghc=$HC --hide-successes"
467 (cd cabal-testsuite
&& timed
$CMD) ||
exit 1
471 #######################################################################
473 step_solver_benchmarks_tests
() {
474 print_header
"solver-benchmarks: test"
476 CMD
="$($CABALPLANLISTBIN solver-benchmarks:test:unit-tests)"
477 (cd Cabal
&& timed
$CMD) ||
exit 1
480 step_solver_benchmarks_run
() {
481 print_header
"solver-benchmarks: run"
483 SOLVEPKG
=Chart-diagrams
484 CMD
="$($CABALPLANLISTBIN solver-benchmarks:exe:hackage-benchmark) --cabal1=$CABAL --cabal2=$($CABALPLANLISTBIN cabal-install:exe:cabal) --trials=5 --packages=$SOLVEPKG --print-trials"
485 (cd Cabal
&& timed
$CMD) ||
exit 1
489 #######################################################################
491 for step
in $STEPS; do
493 print-config
) step_print_config
;;
494 print-tool-versions
) step_print_tool_versions
;;
496 doctest
) step_doctest
;;
497 lib-tests
) step_lib_tests
;;
498 cli-tests
) step_cli_tests
;;
499 lib-suite
) step_lib_suite
;;
500 lib-suite-extras
) step_lib_suite_extras
;;
501 cli-suite
) step_cli_suite
;;
502 solver-benchmarks-tests
) step_solver_benchmarks_tests
;;
503 solver-benchmarks-run
) step_solver_benchmarks_run
;;
504 time-summary
) step_time_summary
;;
506 echo "Invalid step $step"
512 #######################################################################