run-tests.sh 16.4 KB
Newer Older
Daniel Barlow's avatar
Daniel Barlow committed
1 2
#!/bin/sh

3
# run-tests {lisp invocation} {scripts-regex}
4 5 6 7
# - read lisp forms one at a time from standard input
# - quit with exit status 0 on getting eof
# - quit with exit status >0 if an unhandled error occurs

8 9 10 11 12 13
usage () {
    echo "$0 [lisp invocation] [scripts-regex]"
    echo " - read lisp forms one at a time from matching scripts"
    echo " - quit with exit status 0 on getting eof"
    echo " - quit with exit status >0 if an unhandled error occurs"
    echo " you need to supply the .script in the second argument"
14 15 16 17 18 19
    echo " lisps include abcl, ccl (clozure),"
    echo " allegro, allegro8, allegromodern, allegromodern8,"
    echo " allegro_s, allegro8_s, allegromodern_s, allegromodern8_s (SMP variants)"
    echo " allegro_64, allegro8_64, allegromodern_64, allegromodern8_64 (64-bit variants),"
    echo " allegro_64_S, allegro8_64_S, allegromodern_64_S, allegromodern8_64_S, (SMP, 64-bit variants)"
    echo " clisp, cmucl, ecl, gcl, sbcl, scl and xcl."
20 21
    echo "OPTIONS:"
    echo "    -d -- debug mode"
22 23
    echo "    -h -- show this message."
    echo "    -u -- upgrade tests."
24 25
    echo "    -c -- clean load test"
    echo "    -l -- load systems tests"
26
    echo "    -t -- test interactively"
27
    echo "    -H -- extract all asdf versions to upgrade from"
28 29
}

30
unset DEBUG_ASDF_TEST upgrade clean_load load_systems test_interactively extract_all
31
SHELL=/bin/sh
32
export SHELL DEBUG_ASDF_TEST GCL_ANSI ASDF_OUTPUT_TRANSLATIONS
Robert P. Goldman's avatar
 
Robert P. Goldman committed
33

34
while getopts "cdtHulhu" OPTION
Robert P. Goldman's avatar
 
Robert P. Goldman committed
35
do
36
    case $OPTION in
Robert P. Goldman's avatar
 
Robert P. Goldman committed
37
        d)
38
            DEBUG_ASDF_TEST=t
Robert P. Goldman's avatar
 
Robert P. Goldman committed
39 40
            ;;
        u)
41
            upgrade=t
Robert P. Goldman's avatar
 
Robert P. Goldman committed
42
            ;;
43 44 45
        c)
            clean_load=t
            ;;
46 47 48
        l)
            load_systems=t
            ;;
49 50 51
        t)
            test_interactively=t
            ;;
52 53 54
        H)
            extract_all=t
            ;;
Robert P. Goldman's avatar
 
Robert P. Goldman committed
55 56 57 58 59 60 61
        h)
            usage
            exit 1
            ;;
    esac
done
shift $(($OPTIND - 1))
62

63
if [ x"$1" = "xhelp" ]; then
Robert P. Goldman's avatar
 
Robert P. Goldman committed
64 65
    usage
    exit 1
66
fi
67
lisp=${1:-sbcl} ; shift
68

69

70 71 72 73 74 75 76 77 78 79 80 81 82
ECHO () { printf '%s\n' "$*" ;}
ECHOn () { printf '%s' "$*" ;}
DBG () { ECHO "$*" >& 2 ;}
simple_term_p () {
  case "$1" in *[!a-zA-Z0-9-+_,.:=%/]*) return 1 ;; *) return 0 ;; esac
}
kwote0 () { ECHOn "$1" | sed -e "s/\([\\\\\"\$\`]\)/\\\\\\1/g" ;}
kwote1 () { if simple_term_p "$1" ; then ECHOn "$1"
  else ECHOn "\"$(kwote0 "$1")\"" ; fi ;}
kwote () { ( set +x
  k="" ; for i ; do ECHOn "$k" ; kwote1 "$i" ; k=" " ; done ; echo
) }
DO () { kwote "$@" ; "$@" ; }
Francois-Rene Rideau's avatar
1.647:  
Francois-Rene Rideau committed
83

84
do_tests () {
85 86 87 88 89
  if [ -z "$*" ]; then
       scripts="*.script"
  else
       scripts="$*"
  fi
90
  env | grep -i asdf
91
  ## We go through great lengths to avoid " in the command line,
92
  ## the quoting of which many Windows implementations get wrong.
93
  ## While we're at it, we also avoid spaces and backslashes.
94
  ( DO $bcmd $eval '(or`,#.(load(string`|script-support.lisp|))#.(asdf-test::compile-asdf-script))' )
95 96
  if [ $? -ne 0 ] ; then
    echo "Compilation FAILED" >&2
97 98 99
    echo "you can retry compilation with:" >&2
    echo ./test/run-tests.sh $lisp >&2
    echo "or more interactively (and maybe with rlwrap or in emacs), start with:" >&2
100
    echo "$icmd" >&2
101 102
    echo "then copy/paste:" >&2
    echo '(load "test/script-support.lisp") (asdf-test::compile-asdf-script)' >&2
103 104
  else
    echo "Compiled OK" >&2
105 106 107 108
    test_count=0
    test_pass=0
    test_fail=0
    failed_list=""
109 110
    for i in $scripts ;
    do
111 112
      echo "Testing: $i" >&2
      test_count=`expr "$test_count" + 1`
113
      rm -f ~/.cache/common-lisp/"`pwd`"/* || true
114
      if DO $bcmd $eval "'(#.(load(string'|script-support.lisp|))#.(asdf-test::load-asdf)#.(asdf-test::frob-packages)#.(asdf-test::with-test()(load(string'|$i|))))" ; then
115
        echo "Using $command, $i passed" >&2
116 117
	test_pass=`expr "$test_pass" + 1`
      else
118
        echo "Using $command, $i failed" >&2
119 120
	test_fail=`expr "$test_fail" + 1`
	failed_list="$failed_list $i"
121 122 123
        echo "you can retry compilation with:" >&2
        echo ./test/run-tests.sh $lisp $i >&2
        echo "or more interactively (and maybe with rlwrap or in emacs), start with:" >&2
124
        echo "(cd test ; $icmd )" >&2
125
        echo "then copy/paste:" >&2
Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
126
        echo "'(#.(load \"script-support.lisp\") #.(asdf-test::da) #.(load-asdf) #.(frob-packages) #.(asdf::with-asdf-cache () (load \"$i\")))" >&2
127
      fi
128 129
      echo >&2
      echo >&2
130 131
    done
    echo >&2
Gary King's avatar
Gary King committed
132
    echo "-#---------------------------------------" >&2
133
    echo "Using $command" >&2
134 135 136 137
    echo "Ran $test_count tests: " >&2
    echo "  $test_pass passing and $test_fail failing" >&2
    if [ $test_fail -eq 0 ] ; then
	echo "all tests apparently successful" >&2
138
        echo success > ../build/results/status
139 140 141
    else
	echo "failing test(s): $failed_list" >&2
    fi
Gary King's avatar
Gary King committed
142
    echo "-#---------------------------------------" >&2
143
    echo >&2
144
  fi
145 146
}

147 148 149
#
# not used currently but leave here for future reference.
#
150 151
case $(uname) in
    CYGWIN*) os=windows ;;
152 153 154
    Darwin) os=macos ;;
    Linux) os=linux ;;
    *) os=unknown ;;
155 156
esac

157 158


159
# terminate on error
160 161
set -e

162
command= flags= nodebug= eval= bcmd= icmd=
163
case "$lisp" in
164 165
  abcl)
    command="${ABCL:-abcl}"
166
    flags="--noinit --nosystem --noinform"
167 168
    eval="--eval"
    ;;
169 170 171 172 173 174
  allegro|allegro8|allegromodern|allegromodern8)
    case "$lisp" in
      allegro) command="${ALLEGRO:-alisp}" ;;
      allegro8) command="${ALLEGRO8:-alisp8}" ;;
      allegromodern) command="${ALLEGROMODERN:-mlisp}" ;;
      allegromodern8) command="${ALLEGROMODERN8:-mlisp8}" ;;
175 176 177 178 179 180 181 182 183 184 185 186 187
      allegro_s) command="${ALLEGRO_S:-alisp_s}" ;;
      allegro8_s) command="${ALLEGRO8_S:-alisp8_s}" ;;
      allegromodern_s) command="${ALLEGROMODERN_S:-mlisp_s}" ;;
      allegromodern8_s) command="${ALLEGROMODERN8_S:-mlisp8_s}" ;;
      allegro_64) command="${ALLEGRO_64:-alisp_64}" ;;
      allegro8_64) command="${ALLEGRO8_64:-alisp8_64}" ;;
      allegromodern_64) command="${ALLEGROMODERN_64:-mlisp_64}" ;;
      allegromodern8_64) command="${ALLEGROMODERN8_64:-mlisp8_64}" ;;
      allegro_64_s) command="${ALLEGRO_64_S:-alisp_64_s}" ;;
      allegro8_64_s) command="${ALLEGRO8_64_S:-alisp8_64_s}" ;;
      allegromodern_64_s) command="${ALLEGROMODERN_64_S:-mlisp_64_s}" ;;
      allegromodern8_64_s) command="${ALLEGROMODERN8_64_S:-mlisp8_64_s}" ;;

188
    esac
189 190
    flags="-q"
    nodebug="-batch"
191
    if [ "$os" = windows ] && [ -z "$ALLEGRO_NOISY" ] ; then bcmd="$command +c $flags" ; fi
192
    eval="-e" ;;
193
  ccl)
Francois-Rene Rideau's avatar
1.647:  
Francois-Rene Rideau committed
194
    command="${CCL:-ccl}"
195 196 197
    flags="--no-init --quiet"
    nodebug="--batch"
    eval="--eval" ;;
198 199
  clisp)
    command="${CLISP:-clisp}"
200
    flags="-norc --silent -ansi -I "
201 202
    nodebug="-on-error exit"
    eval="-x" ;;
203
  cmucl)
204 205 206
    # cmucl likes to have its executable called lisp, but so does scl
    # Please use a symlink or an exec ... "$@" trampoline script.
    command="${CMUCL:-cmucl}"
207 208 209
    flags="-noinit"
    nodebug="-batch"
    eval="-eval" ;;
210
  ecl)
Francois-Rene Rideau's avatar
1.647:  
Francois-Rene Rideau committed
211
    command="${ECL:-ecl}"
212 213
    flags="-norc -load sys:cmp"
    eval="-eval" ;;
214
  ecl_bytecodes)
215 216
    command="${ECL:-ecl}"
    flags="-norc -eval (ext::install-bytecodes-compiler)"
217
    eval="-eval" ;;
218
  gcl)
219
    GCL_ANSI=t
220
    command="${GCL:-gcl}"
221 222
    flags=""
    nodebug="-batch"
223
    eval="-eval" ;;
224
  lispworks)
Francois-Rene Rideau's avatar
1.647:  
Francois-Rene Rideau committed
225
    command="${LISPWORKS:-lispworks}"
226 227 228 229
    # If you have a licensed copy of lispworks,
    # you can obtain the "lispworks" binary with, e.g.
    # echo '(hcl:save-image "/lispworks" :environment nil)' > /tmp/build.lisp ;
    # ./lispworks-6-0-0-x86-linux -siteinit - -init - -build /tmp/build.lisp
230 231
    flags="-siteinit - -init -"
    eval="-eval" ;;
232 233 234 235
  mkcl)
    command="${MKCL:-mkcl}"
    flags="-norc"
    eval="-eval" ;;
236 237
  sbcl)
    command="${SBCL:-sbcl}"
238
    flags="--noinform --no-userinit --no-sysinit"
239
    nodebug="--disable-debugger"
240
    eval="--eval" ;;
241 242 243 244 245
  scl)
    command="${SCL:-scl}"
    flags="-noinit"
    nodebug="-batch"
    eval="-eval" ;;
246 247
  xcl)
    command="${XCL:-xcl}"
248
    flags="--no-userinit --no-siteinit --noinform"
249
    eval="--eval" ;;
250 251 252 253
  *)
    echo "Unsupported lisp: $1" >&2
    echo "Please add support to run-tests.sh" >&2
    exit 42 ;;
254
esac
255

256
if ! type "$command" > /dev/null ; then
257
    echo "lisp implementation not found: $command" >&2
258 259 260
    exit 43
fi

261
ASDFDIR="$(cd $(dirname $0)/.. ; /bin/pwd)"
262
: ${bcmd:=$command $flags} ${icmd:=$command $flags} # batch and interactive
263
if [ -z "${DEBUG_ASDF_TEST}" ] ; then
264
  bcmd="$bcmd $nodebug"
265 266
fi

Francois-Rene Rideau's avatar
1.647:  
Francois-Rene Rideau committed
267

268
create_config () {
269 270
    cd ${ASDFDIR}
    mkdir -p build/results/ build/test-source-registry-conf.d build/test-asdf-output-translations-conf.d
271
}
272
upgrade_tags () {
273 274
    if [ -n "$ASDF_UPGRADE_TEST_TAGS" ] ; then
        echo $ASDF_UPGRADE_TEST_TAGS ; return
275
    fi
276 277 278 279 280 281 282
    # REQUIRE is a magic tag meaning whatever your implementation provides, if anything
    #
    # 1.85 (2004-05-16) is the last release by Daniel Barlow (not 1.37, which is the README revision!)
    # 1.97 (2006-05-14) is the last release before Gary King takes over
    # 1.369 (2009-10-27) is the last release by Gary King
    #
    # 2.000 to 2.019 and 2.20 to 2.26 and beyond are Faré's "stable" ASDF 2 releases
283
    # 2.26.61 is the last single-file, single-package ASDF.
284 285 286 287 288 289 290 291 292 293 294 295
    # 2.27 and beyond are Faré's "stable" ASDF 3 pre-releases
    #
    # 2.000 (2010-05-31) was the first ASDF 2 release
    # 2.008 (2010-09-10) was a somewhat stable ASDF 2 release
    # 2.011 (2010-11-28) was used by CLISP 2.49, Debian squeeze, Ubuntu 10.04 LTS
    # 2.014.6 (2011-04-06) was used by Quicklisp in 2011
    # 2.019 (2011-11-27) was stable
    # 2.20 (2012-01-18) was in CCL 1.8, Ubuntu 12.04 LTS
    # 2.22 (2012-06-12) was used by debian wheezy
    # 2.26 (2012-10-30) was used by Quicklisp
    # 2.27 (2013-02-01) is the first ASDF 3 pre-release
    # 2.32 (2013-03-05) is the first really stable ASDF 3 pre-release
296
    # 3.0.1 (2013-05-16) is the first stable ASDF 3 release
297
    echo REQUIRE 1.85 1.97 1.369
298 299 300
    # git tag -l '2.0??'
    # git tag -l '2.??'
    echo 2.000 2.008 2.011 2.014.6 2.019 2.20 2.22 2.26
301 302
    echo 2.27 2.32
    git tag -l '3.0.[1-9]'
303
}
304
upgrade_methods () {
305 306
    if [ -n "$ASDF_UPGRADE_TEST_METHODS" ] ; then
        echo $ASDF_UPGRADE_TEST_METHODS ; return
307 308
    fi
    cat <<EOF
309
'load-asdf-lisp'load-asdf-lisp-clean
310
'load-asdf-lisp'load-asdf-system
311
'load-asdf-lisp'compile-load-asdf-upgrade
312 313
'load-asdf-lisp'load-asdf-fasl
()'load-asdf-fasl
314
'load-asdf-lisp-and-test-uiop'load-asdf-fasl
315 316
EOF
}
317
extract_tagged_asdf () {
318 319
    cd ${ASDFDIR}
    mkdir -p build/
320 321
    tag=$1
    if [ REQUIRE = "$tag" ] ; then return 0 ; fi
322 323
    file=build/asdf-${tag}.lisp ;
    if [ ! -f $file ] ; then
324
        case $tag in
325
            1.*|2.0*|2.2[0-6]|2.26.61)
326
                git show ${tag}:asdf.lisp > $file ;;
327
            2.2[7-9]*|2.[3-9]*|3.*)
328
                mkdir -p build/old/build
329
                git archive ${tag} | (cd build/old/ ; tar xf -)
330
                make -C build/old
331
                mv build/old/build/asdf.lisp build/asdf-${tag}.lisp
332 333
                rm -rf build/old ;;
             *)
334 335 336 337 338 339
                echo "Don't know how to extract asdf.lisp for version $tag"
                exit 55
                ;;
        esac
    fi
}
340 341 342 343 344
extract_all_tagged_asdf () {
    for i in `upgrade_tags` ; do
      extract_tagged_asdf $i
    done
}
345 346
valid_upgrade_test_p () {
    case "${1}:${2}:${3}" in
347 348 349
        # It's damn slow. Also, for some reason, we punt on anything earlier than 2.25,
        # and only need to test it once, below for 2.24.
        abcl:1.*|abcl:2.00[0-9]:*|abcl:201[0-9]:*|abcl:2.2[0-3]:*) : ;;
350 351
        # Skip allegro modern on 1.x -- fails for rpgoldman on his mac (!)
        allegromodern:1.*) : ;;
352 353
        # ccl fasl numbering broke loading of old asdf 2.0
        ccl:2.0[01]*) : ;;
354 355
        # my old ubuntu clisp 2.44.1 is wired in
        # with an antique ASDF 1.374 from CLC that can't be downgraded.
356 357
        # 2.00[0-7] use UID, which fails on that CLISP and was removed afterwards.
        # Note that for the longest time, CLISP has included 2.011 in its distribution.
358 359
        # Since we punt on the upgrade, let's only do the test once, for 2.26.
        clisp:2.00[0-7]:*|clisp:1.*|clisp:2.0[01]*|clisp:2.2[0-5]:*) : ;;
360
        # Skip, CMUCL has problems before 2.014.7 due to source-registry upgrade.
361 362 363 364 365
        # Weird unidentified problems before 2.018, so we punt equally for everything before,
        # and only need to test it once: above, for 2.017.
        cmucl:1.*|cmucl:2.00*|cmucl:2.01[0-6]:*) : ;;
        # Skip many ECL tests, for various ASDF issues
        ecl*:1.*|ecl*:2.0[01]*|ecl*:2.20:*) : ;;
366 367
        # GCL 2.7.0 from late November 2013 is required, with ASDF 3.1.1
        gcl:1.*|gcl:2.*|gcl:3.0*) : ;;
368 369
        # MKCL is only supported starting with 2.24, so skip earlier versions
        mkcl:1.*|mkcl:2.0[01]*|mkcl:2.2[0-3]:*) : ;;
370 371
        # XCL support starts with ASDF 2.014.2
        # — It also dies during upgrade trying to show the backtrace.
372
        xcl:1.*|xcl:2.00*|xcl:2.01[0-4]:*|xcl:*) : ;;
373 374 375
        *) return 0 ;;
   esac
   return 1
376
}
377
run_upgrade_tests () {
378
    cd ${ASDFDIR}
379
    mkdir -p build/results/
380
    rm -f build/*.*f* uiop/*.*f* test/*.*f* ## Remove stale FASLs from ASDF 1.x, especially when different implementations have same name
381
    ASDF_OUTPUT_TRANSLATIONS="(:output-translations (\"${ASDFDIR}\" (\"${ASDFDIR}/build/fasls/\" :implementation \"asdf/\")) (t (\"${ASDFDIR}/build/fasls/\" :implementation \"root/\")) :ignore-inherited-configuration)"
382 383
    su=test/script-support.lisp
    for tag in `upgrade_tags` ; do
384 385 386 387
        for method in `upgrade_methods` ; do
            if valid_upgrade_test_p $lisp $tag $method ; then
                echo "Testing ASDF upgrade from ${tag} using method $method"
                extract_tagged_asdf $tag
388
                $bcmd $eval \
389
                "'(#.(load(string'|$su|))#.#.\`(in-package,:asdf-test)#.(test-upgrade$method\`|$tag|))" ||
390 391
                { echo "upgrade FAILED for $lisp from $tag using method $method" ;
                  echo "you can retry just that test with:" ;
392
                  echo ASDF_UPGRADE_TEST_TAGS=\"$tag\" ASDF_UPGRADE_TEST_METHODS=\"$method\" ./test/run-tests.sh -u $lisp ;
393
                  echo "or more interactively (and maybe with rlwrap or in emacs), start with:"
394
                  echo "$icmd"
395
                  echo "then copy/paste:"
396
                  echo "(load \"$su\") (asdf-test::da) (test-upgrade $method \"$tag\")"
397
                  exit 1 ;}
398
    fi ; done ; done 2>&1 | tee build/results/${lisp}-upgrade.text
399 400 401
}
run_tests () {
  create_config
402
  cd ./test/
403 404
  echo failure > ../build/results/status
    thedate=`date "+%Y-%m-%d"`
405
    rm -f "../build/results/${lisp}-test.text" || :
406
    do_tests "$@" 2>&1 | \
407
	tee "../build/results/${lisp}-test.text" "../build/results/${lisp}-test-${thedate}.save"
408 409
    read a < ../build/results/status
  clean_up
410 411 412 413
  if [ success = "$a" ] ; then ## exit code
      return 0
  else
     echo "To view full results and failures, try the following command:" >&2
414
     echo "     less -p ABORTED build/results/${lisp}-test.text" >&2
415 416
     return 1
  fi
417
}
418
clean_up () {
419
    rm -rf ../build/test-source-registry-conf.d ../build/test-asdf-output-translations-conf.d
420
}
421
test_clean_load () {
422
    case $lisp in
423
        gcl|cmucl) return 0 ;; # These are hopeless
424
    esac
425 426
    cd ${ASDFDIR}
    mkdir -p build/results/
427 428
    nop=build/results/${lisp}-nop.text
    load=build/results/${lisp}-load.text
429
    $bcmd $eval \
430 431
      "(or'#.(load(string'|test/script-support.lisp|):verbose():print())#.(asdf-test::exit-lisp'0))" \
      > $nop 2>&1
432
    $bcmd $eval \
433 434
      "(or'#.(load(string'|test/script-support.lisp|):verbose():print())#.(asdf-test::verbose())#.(load(string'|build/asdf.lisp|):verbose())#.(asdf/image:quit'0))" \
      > $load 2>&1
435 436 437 438 439 440
    if diff $nop $load ; then
      echo "GOOD: Loading ASDF on $lisp produces no message" >&2 ; return 0
    else
      echo "BAD: Loading ASDF on $lisp produces messages" >&2 ; return 1
    fi
}
441
test_load_systems () {
442 443
    cd ${ASDFDIR}
    mkdir -p build/results/
444
    echo "Loading all these systems: $*"
445
    $bcmd $eval \
446
      "(or #.(load(string'|test/script-support.lisp|))#.(asdf-test::with-test()(asdf-test::test-load-systems $*)))" \
447 448
        2>&1 | tee build/results/${lisp}-systems.text
}
449
test_interactively () {
450 451
    cd ${ASDFDIR}
    mkdir -p build/results/
452
    rlwrap $icmd $eval "(or'#.(load(string'|test/script-support.lisp|))#.(asdf-test::interactive-test'($*)))"
453
}
454

455
if [ -z "$command" ] ; then
Gary King's avatar
Gary King committed
456
    echo "Error: cannot find or do not know how to run Lisp named $lisp"
457 458
elif [ -n "$test_interactively" ] ; then
    test_interactively "$@"
459 460
elif [ -n "$clean_load" ] ; then
    test_clean_load
461
elif [ -n "$load_systems" ] ; then
462
    test_load_systems "$@"
463 464
elif [ -n "$upgrade" ] ; then
    run_upgrade_tests
465 466
elif [ -n "$extract_all" ] ; then
    extract_all_tagged_asdf
467
else
468
    run_tests "$@"
469
fi ; exit # NB: "; exit" makes it robust wrt the script being modified while running.