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

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