run-tests.sh 12.9 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
Robert P. Goldman's avatar
 
Robert P. Goldman committed
26

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

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

59

60 61 62 63 64 65 66 67 68 69 70 71 72
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
73

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

135
# terminate on error
136 137
set -e

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

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

226
ASDFDIR="$(cd $(dirname $0)/.. ; /bin/pwd)"
227

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

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

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

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