9976e298ed150f089db995b1adf9e7ed70e509a7
[sbcl.git] / tests / expect.sh
1 # file to be sourced by scripts wanting to test the compiler
2
3 # Check that compiling and loading the file $1 generates an error
4 # at load time; also that just loading it directly (into the
5 # interpreter) generates an error.
6 expect_load_error ()
7 {
8     # Test compiling and loading.
9     $SBCL <<EOF
10         (compile-file "$1")
11         ;;; But loading the file should fail.
12         (multiple-value-bind (value0 value1) (ignore-errors (load *))
13             (assert (null value0))
14             (format t "VALUE1=~S (~A)~%" value1 value1)
15             (assert (typep value1 'error)))
16         (sb-ext:quit :unix-status 52)
17 EOF
18     if [ $? != 52 ]; then
19         echo compile-and-load $1 test failed: $?
20         exit 1
21     fi
22
23     # Test loading into the interpreter.
24     $SBCL <<EOF
25         (multiple-value-bind (value0 value1) (ignore-errors (load "$1"))
26             (assert (null value0))
27             (format t "VALUE1=~S (~A)~%" value1 value1)
28             (assert (typep value1 'error)))
29         (sb-ext:quit :unix-status 52)
30 EOF
31     if [ $? != 52 ]; then
32         echo load-into-interpreter $1 test failed: $?
33         exit 1
34     fi
35 }
36
37 # Test that a file compiles cleanly, with no ERRORs, WARNINGs or
38 # STYLE-WARNINGs.
39 expect_clean_compile ()
40 {
41     $SBCL <<EOF
42         (multiple-value-bind (pathname warnings-p failure-p)
43             (compile-file "$1")
44           (declare (ignore pathname))
45           (assert (not warnings-p))
46           (assert (not failure-p))
47           (sb-ext:quit :unix-status 52))
48 EOF
49     if [ $? != 52 ]; then
50         echo clean-compile $1 test failed: $?
51         exit 1
52     fi
53 }
54
55 expect_warned_compile ()
56 {
57     $SBCL <<EOF
58         (multiple-value-bind (pathname warnings-p failure-p)
59             (compile-file "$1")
60           (declare (ignore pathname))
61           (assert warnings-p)
62           (assert (not failure-p))
63           (sb-ext:quit :unix-status 52))
64 EOF
65     if [ $? != 52 ]; then
66         echo warn-compile $1 test failed: $?
67         exit 1
68     fi
69 }
70
71 expect_failed_compile ()
72 {
73     $SBCL <<EOF
74         (multiple-value-bind (pathname warnings-p failure-p)
75             (compile-file "$1")
76           (declare (ignore pathname warnings-p))
77           (assert failure-p)
78           (sb-ext:quit :unix-status 52))
79 EOF
80     if [ $? != 52 ]; then
81         echo fail-compile $1 test failed: $?
82         exit 1
83     fi
84 }
85
86 expect_aborted_compile ()
87 {
88     $SBCL <<EOF
89         (let* ((lisp "$1")
90                (fasl (compile-file-pathname lisp)))
91           (multiple-value-bind (pathname warnings-p failure-p)
92               (compile-file "$1" :print t)
93             (assert (not pathname))
94             (assert failure-p)
95             (assert warnings-p)
96             (assert (not (probe-file fasl))))
97           (sb-ext:quit :unix-status 52))
98 EOF
99     if [ $? != 52 ]; then
100         echo abort-compile $1 test failed: $?
101         exit 1
102     fi
103 }
104
105 fail_on_compiler_note ()
106 {
107     $SBCL <<EOF
108         (handler-bind ((sb-ext:compiler-note #'error))
109           (compile-file "$1")
110           (sb-ext:quit :unix-status 52))
111 EOF
112     if [ $? != 52 ]; then
113         echo fail-on-compiler-note $1 test failed: $?
114         exit 1
115     fi
116 }
117
118 expect_compiler_note ()
119 {
120     $SBCL <<EOF
121         (handler-bind ((sb-ext:compiler-note (lambda (c)
122                                                (declare (ignore c))
123                                                (sb-ext:quit :unix-status 52))))
124           (compile-file "$1"))
125 EOF
126     if [ $? != 52 ]; then
127         echo expect-compiler-note $1 test failed: $?
128         exit 1
129     fi
130 }