run-tests.sh 12.2 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

## Make sure testing remains within the confines of this filesystem tree
229
export CL_SOURCE_REGISTRY="${ASDFDIR}"
230
export ASDF_OUTPUT_TRANSLATIONS="(:output-translations (\"${ASDFDIR}\" (\"${ASDFDIR}/build/fasls\" :implementation)) :ignore-inherited-configuration)"
Francois-Rene Rideau's avatar
1.647:  
Francois-Rene Rideau committed
231

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

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

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

378
if [ -z "$cmd" ] ; then
Gary King's avatar
Gary King committed
379
    echo "Error: cannot find or do not know how to run Lisp named $lisp"
380 381
elif [ -n "$test_interactively" ] ; then
    test_interactively "$@"
382 383
elif [ -n "$clean_load" ] ; then
    test_clean_load
384 385
elif [ -n "$load_systems" ] ; then
    test_load_systems
386 387
elif [ -n "$upgrade" ] ; then
    run_upgrade_tests
388
else
389
    run_tests "$@"
390
fi