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

3
# do_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 24
}

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

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

55
if [ x"$1" = "xhelp" ]; then
Robert P. Goldman's avatar
 
Robert P. Goldman committed
56 57
    usage
    exit 1
58
fi
59
lisp=${1:-sbcl} ; shift
60

61

62 63 64 65 66 67 68 69 70 71 72 73 74
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
Francois-Rene Rideau committed
75

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

137
# terminate on error
138 139
set -e

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

223
if ! type "$command" > /dev/null ; then
224
    echo "lisp implementation not found: $command" >&2
225 226 227
    exit 43
fi

228
ASDFDIR="$(cd $(dirname $0)/.. ; /bin/pwd)"
229

230
cmd="$command $flags"
231
debugp=
232
if [ -z "${DEBUG_ASDF_TEST}" ] ; then
233
  debugp="$nodebug"
234 235
fi

Francois-Rene Rideau's avatar
Francois-Rene Rideau committed
236

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

391
if [ -z "$cmd" ] ; then
Gary King's avatar
Gary King committed
392
    echo "Error: cannot find or do not know how to run Lisp named $lisp"
393 394
elif [ -n "$test_interactively" ] ; then
    test_interactively "$@"
395 396
elif [ -n "$clean_load" ] ; then
    test_clean_load
397
elif [ -n "$load_systems" ] ; then
398
    test_load_systems "$@"
399 400
elif [ -n "$upgrade" ] ; then
    run_upgrade_tests
401
else
402
    run_tests "$@"
403
fi ; exit # NB: "; exit" makes it robust wrt the script being modified while running.