run-tests.sh 14 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
    echo " lisps include abcl, allegro, allegromodern, ccl (clozure),"
15
    echo "  clisp, cmucl, ecl, gcl, gclcvs, sbcl, scl and xcl."
16 17
    echo "OPTIONS:"
    echo "    -d -- debug mode"
18 19
    echo "    -h -- show this message."
    echo "    -u -- upgrade tests."
20 21
    echo "    -c -- clean load test"
    echo "    -l -- load systems tests"
22
    echo "    -t -- test interactively"
23
    echo "    -H -- extract all asdf versions to upgrade from"
24 25
}

26
unset DEBUG_ASDF_TEST upgrade clean_load load_systems test_interactively extract_all
27
SHELL=/bin/sh
28
export SHELL DEBUG_ASDF_TEST GCL_ANSI ASDF_OUTPUT_TRANSLATIONS
Robert P. Goldman's avatar
 
Robert P. Goldman committed
29

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

59
if [ x"$1" = "xhelp" ]; then
Robert P. Goldman's avatar
 
Robert P. Goldman committed
60 61
    usage
    exit 1
62
fi
63
lisp=${1:-sbcl} ; shift
64

65

66 67 68 69 70 71 72 73 74 75 76 77 78
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
79

80
do_tests () {
81 82 83 84 85
  if [ -z "$*" ]; then
       scripts="*.script"
  else
       scripts="$*"
  fi
86
  env | grep -i asdf
87
  rm -f ~/.cache/common-lisp/"`pwd`"/* || true
88
  ( cd .. && DO $cmd $debugp $eval '(or #.(load "test/script-support.lisp") #.(asdf-test::compile-asdf-script))' )
89 90
  if [ $? -ne 0 ] ; then
    echo "Compilation FAILED" >&2
91 92 93 94 95 96
    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
    echo "$cmd" >&2
    echo "then copy/paste:" >&2
    echo '(load "test/script-support.lisp") (asdf-test::compile-asdf-script)' >&2
97 98
  else
    echo "Compiled OK" >&2
99 100 101 102
    test_count=0
    test_pass=0
    test_fail=0
    failed_list=""
103 104
    for i in $scripts ;
    do
105 106
      echo "Testing: $i" >&2
      test_count=`expr "$test_count" + 1`
107
      rm -f ~/.cache/common-lisp/"`pwd`"/* || true
108
      if DO $cmd $debugp $eval "(load \"script-support.lisp\")" $eval "(progn (asdf-test::load-asdf) (asdf-test::frob-packages) (asdf-test::with-test () (load \"$i\")))" ; then
109
        echo "Using $command, $i passed" >&2
110 111
	test_pass=`expr "$test_pass" + 1`
      else
112
        echo "Using $command, $i failed" >&2
113 114
	test_fail=`expr "$test_fail" + 1`
	failed_list="$failed_list $i"
115 116 117 118 119
        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
        echo "(cd test ; $cmd )" >&2
        echo "then copy/paste:" >&2
120
        echo "'(#.(load \"script-support.lisp\") #.(asdf-test::da) #.(load-asdf) #.(load \"$i\"))" >&2
121
      fi
122 123
      echo >&2
      echo >&2
124 125
    done
    echo >&2
Gary King's avatar
Gary King committed
126
    echo "-#---------------------------------------" >&2
127
    echo "Using $command" >&2
128 129 130 131
    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
132
        echo success > ../build/results/status
133 134 135
    else
	echo "failing test(s): $failed_list" >&2
    fi
Gary King's avatar
Gary King committed
136
    echo "-#---------------------------------------" >&2
137
    echo >&2
138
  fi
139 140
}

141
# terminate on error
142 143
set -e

144
command= flags= nodebug= eval=
145
case "$lisp" in
146 147
  abcl)
    command="${ABCL:-abcl}"
148
    flags="--noinit --nosystem --noinform"
149
    eval="--eval" ;;
150
  allegro)
Francois-Rene Rideau's avatar
1.647:  
Francois-Rene Rideau committed
151
    command="${ALLEGRO:-alisp}"
152
    #flags="-q"
153 154
    nodebug="-batch"
    eval="-e" ;;
155
  allegromodern)
Francois-Rene Rideau's avatar
1.647:  
Francois-Rene Rideau committed
156
    command="${ALLEGROMODERN:-mlisp}"
157 158 159
    flags="-q"
    nodebug="-batch"
    eval="-e" ;;
160
  ccl)
Francois-Rene Rideau's avatar
1.647:  
Francois-Rene Rideau committed
161
    command="${CCL:-ccl}"
162 163 164
    flags="--no-init --quiet"
    nodebug="--batch"
    eval="--eval" ;;
165 166
  clisp)
    command="${CLISP:-clisp}"
167
    flags="-norc --silent -ansi -I "
168 169
    nodebug="-on-error exit"
    eval="-x" ;;
170
  cmucl)
171 172 173
    # cmucl likes to have its executable called lisp, but so does scl
    # Please use a symlink or an exec ... "$@" trampoline script.
    command="${CMUCL:-cmucl}"
174 175 176
    flags="-noinit"
    nodebug="-batch"
    eval="-eval" ;;
177
  ecl)
Francois-Rene Rideau's avatar
1.647:  
Francois-Rene Rideau committed
178
    command="${ECL:-ecl}"
179 180
    flags="-norc -load sys:cmp"
    eval="-eval" ;;
181
  ecl_bytecodes)
182 183
    command="${ECL:-ecl}"
    flags="-norc -eval (ext::install-bytecodes-compiler)"
184
    eval="-eval" ;;
185
  gcl)
186
    GCL_ANSI=t
187 188 189
    command="${GCL:-gcl}"
    flags="-batch"
    eval="-eval" ;;
190
  gclcvs)
191
    GCL_ANSI=t
192
    command="${GCLCVS:-gclcvs}"
193 194
    flags="-batch"
    eval="-eval" ;;
195
  lispworks)
Francois-Rene Rideau's avatar
1.647:  
Francois-Rene Rideau committed
196
    command="${LISPWORKS:-lispworks}"
197 198 199 200
    # 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
201 202
    flags="-siteinit - -init -"
    eval="-eval" ;;
203 204 205 206
  mkcl)
    command="${MKCL:-mkcl}"
    flags="-norc"
    eval="-eval" ;;
207 208
  sbcl)
    command="${SBCL:-sbcl}"
209
    flags="--noinform --userinit /dev/null --sysinit /dev/null" # --eval (require'asdf)
210
    nodebug="--disable-debugger"
211
    eval="--eval" ;;
212 213 214 215 216
  scl)
    command="${SCL:-scl}"
    flags="-noinit"
    nodebug="-batch"
    eval="-eval" ;;
217 218 219 220
  xcl)
    command="${XCL:-xcl}"
    flags="--no-userinit --no-siteinit"
    eval="--eval" ;;
221 222 223 224
  *)
    echo "Unsupported lisp: $1" >&2
    echo "Please add support to run-tests.sh" >&2
    exit 42 ;;
225
esac
226

227
if ! type "$command" > /dev/null ; then
228
    echo "lisp implementation not found: $command" >&2
229 230 231
    exit 43
fi

232
ASDFDIR="$(cd $(dirname $0)/.. ; /bin/pwd)"
233

234
cmd="$command $flags"
235
debugp=
236
if [ -z "${DEBUG_ASDF_TEST}" ] ; then
237
  debugp="$nodebug"
238 239
fi

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

241
create_config () {
242 243
    cd ${ASDFDIR}
    mkdir -p build/results/ build/test-source-registry-conf.d build/test-asdf-output-translations-conf.d
244
}
245
upgrade_tags () {
246 247
    if [ -n "$ASDF_UPGRADE_TEST_TAGS" ] ; then
        echo $ASDF_UPGRADE_TEST_TAGS ; return
248
    fi
249
    # REQUIRE is a magic tag meaning whatever your implementation provides
250
    # 1.85 is the last release by Daniel Barlow (not 1.37, which is the README revision!)
251 252 253
    # 1.97 is the last release before Gary King takes over
    # 1.369 is the last release by Gary King
    # 2.000 to 2.019 and 2.20 to 2.27 and beyond are Faré's "stable" releases
254
    # 2.26.61 is the last single-file, single-package ASDF.
255
    echo REQUIRE 1.85 1.97 1.369
256 257 258
    git tag -l '2.0??'
    git tag -l '2.??'
}
259
upgrade_methods () {
260 261
    if [ -n "$ASDF_UPGRADE_TEST_METHODS" ] ; then
        echo $ASDF_UPGRADE_TEST_METHODS ; return
262 263
    fi
    cat <<EOF
264
'load-asdf-lisp'load-asdf-lisp-clean
265 266 267 268
'load-asdf-lisp'load-asdf-system
'load-asdf-lisp'compile-load-asdf
'load-asdf-lisp'load-asdf-fasl
()'load-asdf-fasl
269
'load-asdf-lisp-and-test-uiop'load-asdf-fasl
270 271
EOF
}
272
extract_tagged_asdf () {
273 274
    cd ${ASDFDIR}
    mkdir -p build/
275 276
    tag=$1
    if [ REQUIRE = "$tag" ] ; then return 0 ; fi
277 278
    file=build/asdf-${tag}.lisp ;
    if [ ! -f $file ] ; then
279
        case $tag in
280
            1.*|2.0*|2.2[0-6]|2.26.61)
281
                git show ${tag}:asdf.lisp > $file ;;
282
            2.2[7-9]*|2.[3-9]*|3.*)
283
                mkdir -p build/old/build
284
                git archive ${tag} | (cd build/old/ ; tar xf -)
285
                make -C build/old
286
                mv build/old/build/asdf.lisp build/asdf-${tag}.lisp
287 288
                rm -rf build/old ;;
             *)
289 290 291 292 293 294
                echo "Don't know how to extract asdf.lisp for version $tag"
                exit 55
                ;;
        esac
    fi
}
295 296 297 298 299
extract_all_tagged_asdf () {
    for i in `upgrade_tags` ; do
      extract_tagged_asdf $i
    done
}
300 301
valid_upgrade_test_p () {
    case "${1}:${2}:${3}" in
302 303 304
        # 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]:*) : ;;
305 306
        # Skip allegro modern on 1.x -- fails for rpgoldman on his mac (!)
        allegromodern:1.*) : ;;
307 308
        # ccl fasl numbering broke loading of old asdf 2.0
        ccl:2.0[01]*) : ;;
309 310
        # my old ubuntu clisp 2.44.1 is wired in
        # with an antique ASDF 1.374 from CLC that can't be downgraded.
311 312
        # 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.
313 314
        # 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]:*) : ;;
315
        # Skip, CMUCL has problems before 2.014.7 due to source-registry upgrade.
316 317 318 319 320 321 322 323 324
        # 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:*) : ;;
        # GCL 2.6 is only supported with ASDF 2.27, so skip earlier versions
        gcl:1.*|gcl:2.0*|gcl:2.2[0-6]*) : ;;
        # MKCL is only supported starting with 2.24, so skip earlier versions
        mkcl:1.*|mkcl:2.0[01]*|mkcl:2.2[0-3]:*) : ;;
325 326
        # XCL support starts with ASDF 2.014.2
        # — It also dies during upgrade trying to show the backtrace.
327
        xcl:1.*|xcl:2.00*|xcl:2.01[0-4]:*|xcl:*) : ;;
328 329 330
        *) return 0 ;;
   esac
   return 1
331
}
332
run_upgrade_tests () {
333
    cd ${ASDFDIR}
334
    mkdir -p build/results/
335
    rm -f build/*.*f* uiop/*.*f* test/*.*f* ## Remove stale FASLs from ASDF 1.x, especially when different implementations have same name
336
    ASDF_OUTPUT_TRANSLATIONS="(:output-translations (\"${ASDFDIR}\" (\"${ASDFDIR}/build/fasls/\" :implementation \"asdf/\")) (t (\"${ASDFDIR}/build/fasls/\" :implementation \"root/\")) :ignore-inherited-configuration)"
337 338
    su=test/script-support.lisp
    for tag in `upgrade_tags` ; do
339 340 341 342
        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
343
                $cmd $debugp $eval \
344
                "'(#.(load\"$su\")#.(in-package :asdf-test)#.(test-upgrade $method \"$tag\"))" ||
345 346
                { echo "upgrade FAILED for $lisp from $tag using method $method" ;
                  echo "you can retry just that test with:" ;
347
                  echo ASDF_UPGRADE_TEST_TAGS=\"$tag\" ASDF_UPGRADE_TEST_METHODS=\"$method\" ./test/run-tests.sh -u $lisp ;
348
                  echo "or more interactively (and maybe with rlwrap or in emacs), start with:"
349
                  echo "$cmd"
350
                  echo "then copy/paste:"
351
                  echo "(load\"$su\") (asdf-test::da) (test-upgrade $method \"$tag\")"
352
                  exit 1 ;}
353
    fi ; done ; done 2>&1 | tee build/results/${lisp}-upgrade.text
354 355 356
}
run_tests () {
  create_config
357
  cd ./test/
358 359
  echo failure > ../build/results/status
    thedate=`date "+%Y-%m-%d"`
360
    do_tests "$@" 2>&1 | \
361 362 363
	tee "../build/results/${lisp}.text" "../build/results/${lisp}-${thedate}.save"
    read a < ../build/results/status
  clean_up
364 365 366 367 368 369 370
  if [ success = "$a" ] ; then ## exit code
      return 0
  else
     echo "To view full results and failures, try the following command:" >&2
     echo "     less -p ABORTED build/results/${lisp}.text" >&2
     return 1
  fi
371
}
372
clean_up () {
373
    rm -rf ../build/test-source-registry-conf.d ../build/test-asdf-output-translations-conf.d
374
}
375
test_clean_load () {
376
    case $lisp in
377
        gcl|cmucl) return 0 ;; # These are hopeless
378
    esac
379 380
    cd ${ASDFDIR}
    mkdir -p build/results/
381 382
    nop=build/results/${lisp}-nop.text
    load=build/results/${lisp}-load.text
383
    ${cmd} ${eval} \
384
      '(or #.(load "test/script-support.lisp" :verbose nil :print nil) #.(asdf-test::exit-lisp 0))' \
385
        > $nop 2>&1
386
    ${cmd} ${eval} \
387
      '(or #.(load "test/script-support.lisp" :verbose nil :print nil) #.(asdf-test::verbose nil) #.(load "build/asdf.lisp" :verbose nil) #.(asdf/image:quit 0))' \
388 389 390 391 392 393 394
        > $load 2>&1
    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
}
395 396 397 398
test_load_systems () {
    case $lisp in
        gcl) return 0 ;; # This one is hopeless
    esac
399 400
    cd ${ASDFDIR}
    mkdir -p build/results/
401
    echo "Loading all these systems: $*"
402
    ${cmd} ${eval} \
403
      "(or #.(load \"test/script-support.lisp\") #.(asdf-test::with-test () (asdf-test::test-load-systems $*)))" \
404 405
        2>&1 | tee build/results/${lisp}-systems.text
}
406
test_interactively () {
407 408
    cd ${ASDFDIR}
    mkdir -p build/results/
409 410
    rlwrap $cmd $eval "(or #.(load \"test/script-support.lisp\") #.(asdf-test::interactive-test '($*)))"
}
411

412
if [ -z "$cmd" ] ; then
Gary King's avatar
Gary King committed
413
    echo "Error: cannot find or do not know how to run Lisp named $lisp"
414 415
elif [ -n "$test_interactively" ] ; then
    test_interactively "$@"
416 417
elif [ -n "$clean_load" ] ; then
    test_clean_load
418
elif [ -n "$load_systems" ] ; then
419
    test_load_systems "$@"
420 421
elif [ -n "$upgrade" ] ; then
    run_upgrade_tests
422 423
elif [ -n "$extract_all" ] ; then
    extract_all_tagged_asdf
424
else
425
    run_tests "$@"
426
fi ; exit # NB: "; exit" makes it robust wrt the script being modified while running.