0.9.2.31:
[sbcl.git] / tests / run-tests.sh
1 #!/bin/sh
2
3 # Run the regression tests in this directory.
4
5 # This software is part of the SBCL system. See the README file for
6 # more information.
7 #
8 # While most of SBCL is derived from the CMU CL system, the test
9 # files (like this one) were written from scratch after the fork
10 # from CMU CL.
11
12 # This software is in the public domain and is provided with
13 # absolutely no warranty. See the COPYING and CREDITS files for
14 # more information.
15
16 # how we invoke SBCL in the tests
17 #
18 # Until sbcl-0.6.12.8, the shell variable SBCL was bound to a relative
19 # pathname, but now we take care to bind it to an absolute pathname (still
20 # generated relative to `pwd` in the tests/ directory) so that tests
21 # can chdir before invoking SBCL and still work.
22 sbclstem=`pwd`/../src/runtime/sbcl
23 SBCL="${1:-$sbclstem --core `pwd`/../output/sbcl.core --noinform --sysinit /dev/null --userinit /dev/null --noprint --disable-debugger}"
24 export SBCL
25 echo /running tests on SBCL=\'$SBCL\'
26 # more or less like SBCL, but without enough grot removed that appending
27 # a --core command line argument works
28 #
29 # (KLUDGE: and also without any magic to suppress --userinit and
30 # --sysinit, so if you use it in a test, you need to add those
31 # yourself if you want things to be clean. If many tests start using
32 # this, we can redo it as a shell function or something so that the
33 # magic can be done once and only once.)
34 SBCL_ALLOWING_CORE=${1:-$sbclstem}
35 export SBCL_ALLOWING_CORE
36 echo /with SBCL_ALLOWING_CORE=\'$SBCL_ALLOWING_CORE\'
37
38 LANG=C
39 LC_ALL=C
40 export LANG
41 export LC_ALL
42
43 # "Ten four" is the closest numerical slang I can find to "OK", so
44 # it's the Unix status value that we expect from a successful test.
45 # (Of course, zero is the usual success value, but we don't want to
46 # use that because SBCL returns that by default, so we might think
47 # we passed a test when in fact some error caused us to exit SBCL
48 # in a weird unexpected way. In contrast, 104 is unlikely to be
49 # returned unless we exit through the intended explicit "test
50 # successful" path.
51 tenfour () {
52     if [ $1 = 104 ]; then
53         echo ok
54     else
55         echo test $2 failed, expected 104 return code, got $1
56         exit 1
57     fi
58 }
59
60 # *.pure.lisp files are ordinary Lisp code with no side effects,
61 # and we can run them all in a single Lisp process.
62 echo //running '*.pure.lisp' tests
63 echo //i.e. *.pure.lisp
64 (
65 echo "(progn"
66 echo "  (progn (format t \"//loading assertoid.lisp~%\") (load \"assertoid.lisp\"))"
67 echo "  (use-package \"ASSERTOID\")"
68 for f in *.pure.lisp; do
69     if [ -f $f ]; then
70         echo "  (progn (format t \"//running $f test~%\") (load \"$f\"))"
71     fi
72 done
73 echo "  (sb-ext:quit :unix-status 104)) ; Return status=success."
74 ) | $SBCL ; tenfour $? "(pure.lisp files)"
75
76 # *.impure.lisp files are Lisp code with side effects (e.g. doing
77 # DEFSTRUCT or DEFTYPE or DEFVAR, or messing with the read table).
78 # Each one should be LOADed in a separate invocation of Lisp, so 
79 # that we don't need to worry about them interfering with each
80 # other.
81 echo //running '*.impure.lisp' tests
82 for f in *.impure.lisp; do
83     if [ -f $f ]; then
84         echo //running $f test
85         echo "(load \"$f\")" | $SBCL ; tenfour $? $f
86     fi
87 done
88
89 # *.test.sh files are scripts to test stuff, typically stuff which 
90 # can't so easily be tested within Lisp itself. A file foo.test.sh
91 # may be associated with other files foo*, e.g. foo.lisp, foo-1.lisp,
92 # or foo.pl.
93 echo //running '*.test.sh' tests
94 for f in *.test.sh; do
95     if [ -f $f ]; then
96         echo //running $f test
97         sh $f "$SBCL"; tenfour $? $f
98     fi
99 done
100
101 # *.assertoids files contain ASSERTOID statements to test things
102 # interpreted and at various compilation levels.
103 echo //running '*.assertoids' tests
104 for f in *.assertoids; do
105     if [ -f $f ]; then
106         echo //running $f test
107         echo "(load \"$f\")" | $SBCL --eval '(load "assertoid.lisp")' ; tenfour $? $f
108     fi
109 done
110
111 # *.pure-cload.lisp files want to be compiled, then loaded. They 
112 # can all be done in the same invocation of Lisp.
113 echo //running '*.pure-cload.lisp' tests
114 for f in *.pure-cload.lisp; do
115     # (Actually here we LOAD each one into a separate invocation
116     # of Lisp just because I haven't figured out a concise way
117     # to LOAD them all into the same Lisp.)
118     if [ -f $f ]; then
119         echo //running $f test
120         $SBCL <<EOF ; tenfour $? $f
121                 (compile-file "$f")
122                 (progn
123                   (unwind-protect
124                   (load *)
125                    (ignore-errors (delete-file (compile-file-pathname "$f"))))
126                   (sb-ext:quit :unix-status 104))
127 EOF
128     fi
129 done
130
131 # *.impure-cload.lisp files want to be compiled, then loaded. They
132 # can have side effects, so each one should be done in a separate
133 # invocation of Lisp so that they don't interfere.
134 echo //running '*.impure-cload.lisp' tests
135 for f in *.impure-cload.lisp; do
136     if [ -f $f ]; then
137         echo //running $f test
138         $SBCL <<EOF ; tenfour $? $f
139                 (compile-file "$f")
140                 (progn
141                   (unwind-protect
142                   (load *)
143                    (ignore-errors (delete-file (compile-file-pathname "$f"))))
144                   (sb-ext:quit :unix-status 104))
145 EOF
146     fi
147 done
148
149 # (*.before-xc.lisp and *.after-xc.lisp files aren't handled in this
150 # script at all. They're tests intended to run in the cross-compiler,
151 # so that some functionality can be tested even when cold init doesn't
152 # work.)
153
154 echo '//apparent success (reached end of run-tests.sh normally)'
155 date