Avoid forward references to PARSE-mumble-TYPE condition classes.
[sbcl.git] / tests / subr.sh
blob8d1d1be46bff7a8ba41bba01f21f33504207bc19
1 # To be sourced by shell scripts in the test suite.
3 # This software is part of the SBCL system. See the README file for
4 # more information.
6 # While most of SBCL is derived from the CMU CL system, the test
7 # files (like this one) were written from scratch after the fork
8 # from CMU CL.
10 # This software is in the public domain and is provided with
11 # absolutely no warranty. See the COPYING and CREDITS files for
12 # more information.
14 # Before sbcl-1.0.13 or so, we set up some environment variables to
15 # the absolute (POSIX) pathname naming the SBCL runtime, core, and
16 # home; but this runs afoul of the Bourne shell's repeated
17 # tokenization of its inputs, so now we use some shell functions.
18 . ../sbcl-pwd.sh
19 sbcl_pwd
21 # Make the shell bomb out whenever an unset shell variable is used.
22 # Note that scripts may toggle this if necessary.
23 set -u
25 # Initialize variables.
26 set -a # export all variables at assignment-time.
27 # Note: any script that uses the variables that name files should
28 # quote them (with double quotes), to contend with whitespace.
29 SBCL_HOME="${TEST_SBCL_HOME:-$SBCL_PWD/../obj/sbcl-home}"
30 SBCL_CORE="${TEST_SBCL_CORE:-$SBCL_PWD/../output/sbcl.core}"
31 SBCL_RUNTIME="${TEST_SBCL_RUNTIME:-$SBCL_PWD/../src/runtime/sbcl}"
32 SBCL_ARGS="${TEST_SBCL_ARGS:---noinform --no-sysinit --no-userinit --noprint --disable-debugger}"
34 # Scripts that use these variables should quote them.
35 TEST_BASENAME=`basename $0`
36 TEST_FILESTEM=`basename "${TEST_BASENAME}" | sed -e 's/\.sh$//' -e 's/\./-/g'`
37 : ${TEST_BASEDIR:="$SBCL_PWD"}
38 TEST_DIRECTORY="${TEST_BASEDIR}/${TEST_FILESTEM}-$$"
39 export TEST_DIRECTORY
41 # "Ten four" is the closest numerical slang I can find to "OK", so
42 # it's the Unix status value that we expect from a successful test.
43 # (Of course, zero is the usual success value, but we don't want to
44 # use that because SBCL returns that by default, so we might think
45 # we passed a test when in fact some error caused us to exit SBCL
46 # in a weird unexpected way. In contrast, 104 is unlikely to be
47 # returned unless we exit through the intended explicit "test
48 # successful" path.
49 EXIT_TEST_WIN=104
50 # Shell scripts in this test suite also return 104, so we need a
51 # convention for distinguishing successful execution of SBCL in one of
52 # our scripts.
53 EXIT_LISP_WIN=52
54 # Any test that exits with status 1 is an explicit failure.
55 EXIT_LOSE=1
57 LANG=C
58 LC_ALL=C
59 set +a
61 run_sbcl () (
62 set -u
63 if [ $# -gt 0 ]; then
64 "$SBCL_RUNTIME" --core "$SBCL_CORE" $SBCL_ARGS "$@"
65 else
66 "$SBCL_RUNTIME" --core "$SBCL_CORE" $SBCL_ARGS
70 run_sbcl_with_args () (
71 set -u
72 "$SBCL_RUNTIME" --core "$SBCL_CORE" "$@"
75 run_sbcl_with_core () (
76 set -u
77 core="$1"
78 shift
79 if [ $# -gt 0 ]; then
80 "$SBCL_RUNTIME" --core "$core" "$@"
81 else
82 "$SBCL_RUNTIME" --core "$core" $SBCL_ARGS
86 # Most tests that run an SBCL have to check whether the child's exit
87 # status. Our convention is that SBCL exits with status
88 # $EXIT_LISP_WIN to indicate a successful run; but some tests can't do
89 # this (e.g., ones that end in S-L-A-D), or need to indicate some
90 # other ways of succeeding. So this routine takes a test name, the
91 # exit status of the child, and then an arbitrary number extra
92 # arguments that will be treated as status-code/message pairs for
93 # unusual successful ways for the inferior SBCL to exit. If the exit
94 # code of the SBCL isn't found in the status-codes, the calling script
95 # will exit with a failure code.
96 check_status_maybe_lose () {
97 testname=$1
98 status=$2
99 lose=1
100 if [ $status = $EXIT_LISP_WIN ]; then
101 echo "test $testname ok"
102 lose=0
103 else
104 shift; shift;
105 while [ $# -gt 0 ]; do
106 if [ $status = $1 ]; then
107 shift;
108 echo "test $testname ok $1"
109 lose=0
110 break
112 shift; shift
113 done
115 if [ $lose = 1 ]; then
116 echo "test $testname failed: $status"
117 exit $EXIT_LOSE
119 unset lose
120 unset status
121 unset testname
124 # Not every test needs to touch the file system, but enough do to have
125 # them consistently do so in subdirectories. Note that such tests
126 # should not change their exit action, or do so only very carefully.
127 use_test_subdirectory () {
128 if test -d "$TEST_DIRECTORY"
129 then
130 cleanup_test_subdirectory
132 mkdir "$TEST_DIRECTORY"
133 cd "$TEST_DIRECTORY"
134 trap "cleanup_test_subdirectory" EXIT
137 cleanup_test_subdirectory () {
138 cd "$SBCL_PWD"
139 ( set -f; rm -r "$TEST_DIRECTORY" )