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 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517
|
#!/bin/sh
# shellcheck disable=SC2086
# default config
#######################################################################
# We use the default ghc in PATH as default
# Use the ghc-x.y.z trigger several errors in windows:
# * It triggers the max path length issue:
# See https://github.com/haskell/cabal/issues/6271#issuecomment-1065102255
# * It triggers a `createProcess: does not exist` error in units tests
# See https://github.com/haskell/cabal/issues/8049
HC=ghc
CABAL=cabal
JOBS=4
LIBTESTS=true
CLITESTS=true
CABALSUITETESTS=true
LIBONLY=false
DEPSONLY=false
DOCTEST=false
BENCHMARKS=false
VERBOSE=false
HACKAGETESTSALL=false
TARGETS=""
STEPS=""
EXTRAHCS=""
LISTSTEPS=false
# Help
#######################################################################
show_usage() {
cat <<EOF
./validate.sh - build & test
Usage: ./validate.sh [options]
A script which runs all the tests.
Available options:
-j, --jobs JOBS cabal build -j argument (default: $JOBS)
--libonly Test only Cabal-the-library
--cli Test both Cabal-the-library and cabal-install
--(no-)run-lib-tests Run library tests
--(no-)run-cli-tests Run client tests
--(no-)run-lib-suite Run cabal-testsuite with library
--(no-)run-cli-suite Run cabal-testsuite with client
-w, --with-compiler HC With compiler
--with-cabal CABAL With cabal-install
--extra-hc HC Extra compiler to run test-suite with
--(no-)doctest Run doctest on library
--(no-)solver-benchmarks Build and trial run solver-benchmarks
--complete-hackage-tests Run hackage-tests on complete Hackage data
--partial-hackage-tests Run hackage-tests on parts of Hackage data
-v, --verbose Verbose output
-q, --quiet Less output
-s, --step STEP Run only specific step (can be specified multiple times)
--list-steps List steps and build-targets and exit
--help Print this message and exit
EOF
}
# "library"
#######################################################################
OUTPUT=$(mktemp)
# `red` and `green` are used to output also the spent time in white at the end.
# `blue` and `cyan` are used to print the spawned command, so they only have one
# argument.
red () {
printf "\033[0;31m%s\033[0m %s \n" "$1" "$2"
}
green () {
printf "\033[0;32m%s\033[0m %s \n" "$1" "$2"
}
blue () {
printf "\033[0;34m%s\033[0m\n" "$1"
}
cyan () {
printf "\033[0;96m%s\033[0m\n" "$1"
}
JOB_START_TIME=$(date +%s)
timed() {
PRETTYCMD=$(echo "$@" | sed -E 's/\/home[^ ]*\/([^\/])/**\/\1/g')
blue "$PRETTYCMD"
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
green "<<< $PRETTYCMD" "($duration/$tduration sec)"
# bottom-margin
echo ""
else
if ! $VERBOSE; then
cat "$OUTPUT"
fi
red "<<< $PRETTYCMD" "($duration/$tduration sec, $RET)"
red "<<< $*" "($duration/$tduration sec, $RET)"
rm -f "$OUTPUT"
exit 1
fi
}
print_header() {
TITLE=$1
TITLEPAT="$(echo "$TITLE"|sed 's:.:=:g')"
cyan "===X========================================================================== $(date +%T) ===" \
| sed "s#X$TITLEPAT=# $TITLE #"
}
# getopt
#######################################################################
while [ $# -gt 0 ]; do
arg=$1
case $arg in
--help)
show_usage
exit
;;
-j|--jobs)
JOBS="$2"
shift
shift
;;
--lib-only)
LIBONLY=true
shift
;;
--cli)
LIBONLY=false
shift
;;
--run-lib-tests)
LIBTESTS=true
shift
;;
--no-run-lib-tests)
LIBTESTS=false
shift
;;
--run-cli-tests)
CLITESTS=true
shift
;;
--no-run-cli-tests)
CLITESTS=false
shift
;;
--run-lib-suite)
LIBSUITE=true
shift
;;
--no-run-lib-suite)
LIBSUITE=false
shift
;;
--run-cli-suite)
CLISUITE=true
shift
;;
--no-run-cli-suite)
CLISUITE=false
shift
;;
-w|--with-compiler)
HC=$2
shift
shift
;;
--with-cabal)
CABAL=$2
shift
shift
;;
--extra-hc)
EXTRAHCS="$EXTRAHCS $2"
shift
shift
;;
--doctest)
DOCTEST=true
shift
;;
--no-doctest)
DOCTEST=false
shift
;;
--solver-benchmarks)
BENCHMARKS=true
shift
;;
--no-solver-benchmarks)
BENCHMARKS=false
shift
;;
--complete-hackage-tests)
HACKAGETESTSALL=true
shift
;;
--partial-hackage-tests)
HACKAGETESTSALL=false
shift
;;
-v|--verbose)
VERBOSE=true
shift
;;
-q|--quiet)
VERBOSE=false
shift
;;
-s|--step)
STEPS="$STEPS $2"
shift
shift
;;
--list-steps)
LISTSTEPS=true
shift
;;
*)
echo "Unknown option $arg"
exit 1
esac
done
# calculate steps and build targets
#######################################################################
# If there are no explicit steps given calculate them
if $LIBONLY; then
CLITESTS=false
CLISUITE=false
BENCHMARKS=false
fi
if [ -z "$STEPS" ]; then
STEPS="print-config print-tool-versions"
STEPS="$STEPS build"
if $DOCTEST; then STEPS="$STEPS doctest"; fi
if $LIBTESTS; then STEPS="$STEPS lib-tests"; fi
if $LIBSUITE; then STEPS="$STEPS lib-suite"; fi
if $LIBSUITE && [ -n "$EXTRAHCS" ];
then STEPS="$STEPS lib-suite-extras"; fi
if $CLITESTS; then STEPS="$STEPS cli-tests"; fi
if $CLISUITE; then STEPS="$STEPS cli-suite"; fi
if $BENCHMARKS; then STEPS="$STEPS solver-benchmarks-tests solver-benchmarks-run"; fi
STEPS="$STEPS time-summary"
fi
TARGETS="Cabal cabal-testsuite Cabal-tests Cabal-QuickCheck Cabal-tree-diff Cabal-described"
if ! $LIBONLY; then TARGETS="$TARGETS cabal-install cabal-install-solver cabal-benchmarks"; fi
if $BENCHMARKS; then TARGETS="$TARGETS solver-benchmarks"; fi
if $LISTSTEPS; then
echo "Targets: $TARGETS"
echo "Steps: $STEPS"
exit
fi
# Adjust runtime configuration
#######################################################################
TESTSUITEJOBS="-j$JOBS"
JOBS="-j$JOBS"
# assume compiler is GHC
RUNHASKELL=$(echo "$HC" | sed -E 's/ghc(-[0-9.]*)$/runghc\1/')
case "$(uname)" in
MINGW64*)
ARCH="x86_64-windows"
;;
Linux )
ARCH="x86_64-linux"
;;
*)
ARCH="x86_64-osx"
;;
esac
if $LIBONLY; then
PROJECTFILE=cabal.validate-libonly.project
else
PROJECTFILE=cabal.validate.project
fi
BASEHC=ghc-$($HC --numeric-version)
BUILDDIR=dist-newstyle-validate-$BASEHC
CABAL_TESTSUITE_BDIR="$(pwd)/$BUILDDIR/build/$ARCH/$BASEHC/cabal-testsuite-3"
CABALNEWBUILD="${CABAL} build $JOBS -w $HC --builddir=$BUILDDIR --project-file=$PROJECTFILE"
CABALLISTBIN="${CABAL} list-bin --builddir=$BUILDDIR --project-file=$PROJECTFILE"
# header
#######################################################################
step_print_config() {
print_header print-config
cat <<EOF
compiler: $HC
runhaskell: $RUNHASKELL
cabal-install: $CABAL
jobs: $JOBS
Cabal tests: $LIBTESTS
cabal-install tests: $CLITESTS
cabal-testsuite: $CABALSUITETESTS
library only: $LIBONLY
dependencies only: $DEPSONLY
doctest: $DOCTEST
benchmarks: $BENCHMARKS
verbose: $VERBOSE
extra compilers: $EXTRAHCS
EOF
}
step_print_tool_versions() {
print_header print-tool-versions
timed "$HC" --version
timed "$CABAL" --version
for EXTRAHC in $EXTRAHCS; do
timed "$EXTRAHC" --version
done
}
step_time_summary() {
print_header END
JOB_END_TIME=$(date +%s)
tduration=$((JOB_END_TIME - JOB_START_TIME))
cyan "!!! Validation took $tduration seconds."
}
# build
#######################################################################
step_build() {
print_header "build"
print_header "Step Build: dry run"
timed $CABALNEWBUILD $TARGETS --dry-run || exit 1
print_header "Step Build: full build plan (cached and to-be-built dependencies):"
jq -r '."install-plan" | map(."pkg-name" + "-" + ."pkg-version" + " " + ."component-name") | join("\n")' "$BUILDDIR/cache/plan.json"
print_header "Step Build: actual build"
timed $CABALNEWBUILD $TARGETS || exit 1
}
# Cabal lib
#######################################################################
step_doctest() {
print_header "Cabal: doctest"
cabal-env --name doctest-Cabal --transitive QuickCheck
cabal-env --name doctest-Cabal array bytestring containers deepseq directory filepath pretty process time binary unix text parsec mtl
timed doctest -package-env=doctest-Cabal --fast Cabal/Distribution Cabal/Language
}
step_lib_tests() {
print_header "Cabal: tests"
CMD="$($CABALLISTBIN Cabal-tests:test:unit-tests) $TESTSUITEJOBS --hide-successes --with-ghc=$HC"
(cd Cabal-tests && timed $CMD) || exit 1
CMD="$($CABALLISTBIN Cabal-tests:test:check-tests) $TESTSUITEJOBS --hide-successes"
(cd Cabal-tests && timed $CMD) || exit 1
CMD="$($CABALLISTBIN Cabal-tests:test:parser-tests) $TESTSUITEJOBS --hide-successes"
(cd Cabal-tests && timed $CMD) || exit 1
CMD="$($CABALLISTBIN Cabal-tests:test:rpmvercmp) $TESTSUITEJOBS --hide-successes"
(cd Cabal-tests && timed $CMD) || exit 1
CMD="$($CABALLISTBIN Cabal-tests:test:no-thunks-test) $TESTSUITEJOBS --hide-successes"
(cd Cabal-tests && timed $CMD) || exit 1
CMD=$($CABALLISTBIN Cabal-tests:test:hackage-tests)
(cd Cabal-tests && timed $CMD read-fields) || exit 1
if $HACKAGETESTSALL; then
(cd Cabal-tests && timed $CMD parsec) || exit 1
(cd Cabal-tests && timed $CMD roundtrip) || exit 1
else
(cd Cabal-tests && timed $CMD parsec d) || exit 1
(cd Cabal-tests && timed $CMD roundtrip k) || exit 1
fi
}
# Cabal cabal-testsuite
#######################################################################
step_lib_suite() {
print_header "Cabal: cabal-testsuite"
CMD="$($CABALLISTBIN cabal-testsuite:exe:cabal-tests) --builddir=$CABAL_TESTSUITE_BDIR $TESTSUITEJOBS --with-ghc=$HC --hide-successes"
(cd cabal-testsuite && timed $CMD) || exit 1
}
step_lib_suite_extras() {
for EXTRAHC in $EXTRAHCS; do
CMD="$($CABALLISTBIN cabal-testsuite:exe:cabal-tests) --builddir=$CABAL_TESTSUITE_BDIR $TESTSUITEJOBS --with-ghc=$EXTRAHC --hide-successes"
(cd cabal-testsuite && timed $CMD) || exit 1
done
}
# cabal-install
#######################################################################
step_cli_tests() {
print_header "cabal-install: tests"
# this are sorted in asc time used, quicker tests first.
CMD="$($CABALLISTBIN cabal-install:test:long-tests) $TESTSUITEJOBS --hide-successes"
(cd cabal-install && timed $CMD) || exit 1
# This doesn't work in parallel either
CMD="$($CABALLISTBIN 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="$($CABALLISTBIN cabal-install:test:mem-use-tests) -j1 --hide-successes"
(cd cabal-install && timed $CMD) || exit 1
# This test-suite doesn't like concurrency
CMD="$($CABALLISTBIN cabal-install:test:integration-tests2) -j1 --hide-successes --with-ghc=$HC"
(cd cabal-install && timed $CMD) || exit 1
}
# cabal-install cabal-testsuite
#######################################################################
step_cli_suite() {
print_header "cabal-install: cabal-testsuite"
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"
(cd cabal-testsuite && timed $CMD) || exit 1
}
# solver-benchmarks
#######################################################################
step_solver_benchmarks_tests() {
print_header "solver-benchmarks: test"
CMD="$($CABALLISTBIN solver-benchmarks:test:unit-tests)"
(cd Cabal && timed $CMD) || exit 1
}
step_solver_benchmarks_run() {
print_header "solver-benchmarks: run"
SOLVEPKG=Chart-diagrams
CMD="$($CABALLISTBIN solver-benchmarks:exe:hackage-benchmark) --cabal1=$CABAL --cabal2=$($CABALLISTBIN cabal-install:exe:cabal) --trials=5 --packages=$SOLVEPKG --print-trials"
(cd Cabal && timed $CMD) || exit 1
}
# Steps dispatcher
#######################################################################
for step in $STEPS; do
case $step in
print-config) step_print_config ;;
print-tool-versions) step_print_tool_versions ;;
build) step_build ;;
doctest) step_doctest ;;
lib-tests) step_lib_tests ;;
cli-tests) step_cli_tests ;;
lib-suite) step_lib_suite ;;
lib-suite-extras) step_lib_suite_extras ;;
cli-suite) step_cli_suite ;;
solver-benchmarks-tests) step_solver_benchmarks_tests ;;
solver-benchmarks-run) step_solver_benchmarks_run ;;
time-summary) step_time_summary ;;
*)
echo "Invalid step $step"
exit 1
;;
esac
done
#######################################################################
|