1.0.14.28: small FGEN improvements
[sbcl/jsnell.git] / tests / run-tests.lisp
blobbcd090db8a3d17dd649c3b48607ff8c8c5c7b5e4
1 #+#.(cl:if (cl:find-package "ASDF") '(or) '(and))
2 (load (merge-pathnames "../contrib/asdf/asdf.fasl"))
4 #+#.(cl:if (cl:find-package "SB-POSIX") '(or) '(and))
5 (let ((asdf:*central-registry*
6 (cons "../contrib/systems/" asdf:*central-registry*)))
7 (asdf:oos 'asdf:load-op 'sb-posix))
9 (load "test-util.lisp")
11 (defpackage :run-tests
12 (:use :cl :test-util :sb-ext))
14 (load "assertoid.lisp")
16 (in-package run-tests)
18 (defvar *all-failures* nil)
19 (defvar *break-on-error* nil)
20 (defvar *accept-files* nil)
22 (defun run-all ()
23 (dolist (arg (cdr *posix-argv*))
24 (cond ((string= arg "--break-on-failure")
25 (setf *break-on-error* t)
26 (setf test-util:*break-on-failure* t))
27 ((string= arg "--break-on-expected-failure")
28 (setf test-util:*break-on-expected-failure* t))
30 (push (truename (parse-namestring arg)) *accept-files*))))
31 (pure-runner (pure-load-files) #'load-test)
32 (pure-runner (pure-cload-files) #'cload-test)
33 (impure-runner (impure-load-files) #'load-test)
34 (impure-runner (impure-cload-files) #'cload-test)
35 #-win32 (impure-runner (sh-files) #'sh-test)
36 (report)
37 (sb-ext:quit :unix-status (if (unexpected-failures)
39 104)))
41 (defun report ()
42 (terpri)
43 (format t "Finished running tests.~%")
44 (cond (*all-failures*
45 (format t "Status:~%")
46 (dolist (fail (reverse *all-failures*))
47 (cond ((eq (car fail) :unhandled-error)
48 (format t " ~20a ~a~%"
49 "Unhandled error"
50 (enough-namestring (second fail))))
51 ((eq (car fail) :invalid-exit-status)
52 (format t " ~20a ~a~%"
53 "Invalid exit status:"
54 (enough-namestring (second fail))))
56 (format t " ~20a ~a / ~a~%"
57 (ecase (first fail)
58 (:expected-failure "Expected failure:")
59 (:unexpected-failure "Failure:")
60 (:unexpected-success "Unexpected success:"))
61 (enough-namestring (second fail))
62 (third fail))))))
64 (format t "All tests succeeded~%"))))
66 (defun pure-runner (files test-fun)
67 (format t "// Running pure tests (~a)~%" test-fun)
68 (let ((*package* (find-package :cl-user))
69 (*failures* nil))
70 (setup-cl-user)
71 (dolist (file files)
72 (when (accept-test-file file)
73 (format t "// Running ~a~%" file)
74 (restart-case
75 (handler-bind ((error (make-error-handler file)))
76 (eval (funcall test-fun file)))
77 (skip-file ()))))
78 (append-failures)))
80 (defun run-in-child-sbcl (load-forms forms)
81 (declare (ignorable load-forms))
82 #-win32
83 (let ((pid (sb-posix:fork)))
84 (cond ((= pid 0)
85 (dolist (form forms)
86 (eval form)))
88 (let ((status (make-array 1 :element-type '(signed-byte 32))))
89 (sb-posix:waitpid pid 0 status)
90 (if (sb-posix:wifexited (aref status 0))
91 (sb-posix:wexitstatus (aref status 0))
92 1)))))
93 #+win32
94 (process-exit-code
95 (sb-ext:run-program
96 (first *POSIX-ARGV*)
97 (append
98 (list "--core" SB-INT:*CORE-STRING*
99 "--noinform"
100 "--no-sysinit"
101 "--no-userinit")
102 (loop for form in (append load-forms forms)
103 collect "--eval"
104 collect (write-to-string form)))
105 :output sb-sys:*stdout*
106 :input sb-sys:*stdin*)))
108 (defun run-impure-in-child-sbcl (test-file test-code)
109 (run-in-child-sbcl
110 `((load "test-util")
111 (load "assertoid")
112 (defpackage :run-tests
113 (:use :cl :test-util :sb-ext)))
115 `((in-package :cl-user)
116 (use-package :test-util)
117 (use-package :assertoid)
118 (setf test-util:*break-on-failure* ,test-util:*break-on-failure*)
119 (setf test-util:*break-on-expected-failure*
120 ,test-util:*break-on-expected-failure*)
121 (let ((file ,test-file)
122 (*break-on-error* ,run-tests::*break-on-error*))
123 (format t "// Running ~a~%" file)
124 (restart-case
125 (handler-bind
126 ((error (lambda (condition)
127 (push (list :unhandled-error file)
128 test-util::*failures*)
129 (cond (*break-on-error*
130 (test-util:really-invoke-debugger condition))
132 (format *error-output* "~&Unhandled ~a: ~a~%"
133 (type-of condition) condition)
134 (sb-debug:backtrace)))
135 (invoke-restart 'skip-file))))
136 ,test-code)
137 (skip-file ()
138 (format t ">>>~a<<<~%" test-util::*failures*)))
139 (test-util:report-test-status)
140 (sb-ext:quit :unix-status 104)))))
142 (defun impure-runner (files test-fun)
143 (format t "// Running impure tests (~a)~%" test-fun)
144 (let ((*package* (find-package :cl-user)))
145 (setup-cl-user)
146 (dolist (file files)
147 (when (accept-test-file file)
148 (force-output)
149 (let ((exit-code (run-impure-in-child-sbcl file
150 (funcall test-fun file))))
151 (if (= exit-code 104)
152 (with-open-file (stream "test-status.lisp-expr"
153 :direction :input
154 :if-does-not-exist :error)
155 (append-failures (read stream)))
156 (push (list :invalid-exit-status file)
157 *all-failures*)))))))
159 (defun make-error-handler (file)
160 (lambda (condition)
161 (push (list :unhandled-error file) *failures*)
162 (cond (*break-on-error*
163 (test-util:really-invoke-debugger condition))
165 (format *error-output* "~&Unhandled ~a: ~a~%"
166 (type-of condition) condition)
167 (sb-debug:backtrace)))
168 (invoke-restart 'skip-file)))
170 (defun append-failures (&optional (failures *failures*))
171 (setf *all-failures* (append failures *all-failures*)))
173 (defun unexpected-failures ()
174 (remove-if (lambda (x)
175 (or (eq (car x) :expected-failure)
176 (eq (car x) :unexpected-success)))
177 *all-failures*))
179 (defun setup-cl-user ()
180 (use-package :test-util)
181 (use-package :assertoid))
183 (defun load-test (file)
184 `(load ,file))
186 (defun cload-test (file)
187 `(let ((compile-name (compile-file-pathname ,file)))
188 (unwind-protect
189 (progn
190 (compile-file ,file)
191 (load compile-name))
192 (ignore-errors
193 (delete-file compile-name)))))
195 (defun sh-test (file)
196 ;; What? No SB-POSIX:EXECV?
197 `(let ((process (sb-ext:run-program "/bin/sh"
198 (list (native-namestring ,file))
199 :output *error-output*)))
200 (sb-ext:quit :unix-status (process-exit-code process))))
202 (defun accept-test-file (file)
203 (if *accept-files*
204 (find (truename file) *accept-files* :test #'equalp)
207 (defun pure-load-files ()
208 (directory "*.pure.lisp"))
210 (defun pure-cload-files ()
211 (directory "*.pure-cload.lisp"))
213 (defun impure-load-files ()
214 (directory "*.impure.lisp"))
216 (defun impure-cload-files ()
217 (directory "*.impure-cload.lisp"))
219 (defun sh-files ()
220 (directory "*.test.sh"))