code/irrat: Disable all floating FFI on ARM.
[sbcl/nyef.git] / tests / run-tests.lisp
blobff0ae260c594f65dc6c27aaa52862b2bd6f6f454
1 (handler-bind (#+win32 (warning #'muffle-warning))
2 (require :sb-posix))
4 (load "test-util.lisp")
6 (defpackage :run-tests
7 (:use :cl :test-util :sb-ext))
9 (load "assertoid.lisp")
11 (in-package run-tests)
13 (load "colorize.lisp")
15 (defvar *all-failures* nil)
16 (defvar *break-on-error* nil)
17 (defvar *report-skipped-tests* nil)
18 (defvar *explicit-test-files* nil)
20 (defun run-all ()
21 (dolist (arg (cdr *posix-argv*))
22 (cond ((string= arg "--break-on-failure")
23 (setf *break-on-error* t)
24 (setf test-util:*break-on-failure* t))
25 ((string= arg "--break-on-expected-failure")
26 (setf test-util:*break-on-expected-failure* t))
27 ((string= arg "--report-skipped-tests")
28 (setf *report-skipped-tests* t))
29 ((string= arg "--no-color"))
31 (push (truename (parse-namestring arg)) *explicit-test-files*))))
32 (setf *explicit-test-files* (nreverse *explicit-test-files*))
33 (pure-runner (pure-load-files) #'load-test)
34 (pure-runner (pure-cload-files) #'cload-test)
35 (impure-runner (impure-load-files) #'load-test)
36 (impure-runner (impure-cload-files) #'cload-test)
37 #-win32 (impure-runner (sh-files) #'sh-test)
38 (report)
39 (sb-ext:exit :code (if (unexpected-failures)
41 104)))
43 (defun report ()
44 (terpri)
45 (format t "Finished running tests.~%")
46 (let ((skipcount 0)
47 (*print-pretty* nil))
48 (cond (*all-failures*
49 (format t "Status:~%")
50 (dolist (fail (reverse *all-failures*))
51 (cond ((eq (car fail) :unhandled-error)
52 (output-colored-text (car fail)
53 " Unhandled Error")
54 (format t " ~a~%"
55 (enough-namestring (second fail))))
56 ((eq (car fail) :invalid-exit-status)
57 (output-colored-text (car fail)
58 " Invalid exit status:")
59 (format t " ~a~%"
60 (enough-namestring (second fail))))
61 ((eq (car fail) :skipped-disabled)
62 (when *report-skipped-tests*
63 (format t " ~20a ~a / ~a~%"
64 "Skipped (irrelevant):"
65 (enough-namestring (second fail))
66 (third fail)))
67 (incf skipcount))
69 (output-colored-text
70 (first fail)
71 (ecase (first fail)
72 (:expected-failure " Expected failure:")
73 (:unexpected-failure " Failure:")
74 (:leftover-thread " Leftover thread (broken):")
75 (:unexpected-success " Unexpected success:")
76 (:skipped-broken " Skipped (broken):")
77 (:skipped-disabled " Skipped (irrelevant):")))
78 (format t " ~a / ~a~%"
79 (enough-namestring (second fail))
80 (third fail)))))
81 (when (> skipcount 0)
82 (format t " (~a tests skipped for this combination of platform and features)~%"
83 skipcount)))
85 (format t "All tests succeeded~%")))))
87 (defun pure-runner (files test-fun)
88 (when files
89 (format t "// Running pure tests (~a)~%" test-fun)
90 (let ((*package* (find-package :cl-user))
91 (*failures* nil))
92 (setup-cl-user)
93 (dolist (file files)
94 (format t "// Running ~a~%" file)
95 (restart-case
96 (handler-bind ((error (make-error-handler file)))
97 (eval (funcall test-fun file)))
98 (skip-file ())))
99 (append-failures))))
101 (defun run-in-child-sbcl (load-forms forms)
102 ;; We used to fork() for POSIX platforms, and use this for Windows.
103 ;; However, it seems better to use the same solution everywhere.
104 (process-exit-code
105 (#-win32 with-open-file #-win32 (devnull "/dev/null") #+win32 progn
106 (sb-ext:run-program
107 (first *POSIX-ARGV*)
108 (append
109 (list "--core" SB-INT:*CORE-STRING*
110 "--noinform"
111 "--no-sysinit"
112 "--no-userinit"
113 "--noprint"
114 "--disable-debugger")
115 (loop for form in (append load-forms forms)
116 collect "--eval"
117 collect (write-to-string form)))
118 :output sb-sys:*stdout*
119 :input #-win32 devnull #+win32 sb-sys:*stdin*))))
121 (defun run-impure-in-child-sbcl (test-file test-code)
122 (run-in-child-sbcl
123 `((load "test-util")
124 (load "assertoid")
125 (defpackage :run-tests
126 (:use :cl :test-util :sb-ext)))
128 `((in-package :cl-user)
129 (use-package :test-util)
130 (use-package :assertoid)
131 (setf test-util:*break-on-failure* ,test-util:*break-on-failure*)
132 (setf test-util:*break-on-expected-failure*
133 ,test-util:*break-on-expected-failure*)
134 (let ((file ,test-file)
135 (*break-on-error* ,run-tests::*break-on-error*))
136 (declare (special *break-on-error*))
137 (format t "// Running ~a~%" file)
138 (restart-case
139 (handler-bind
140 ((error (lambda (condition)
141 (push (list :unhandled-error file)
142 test-util::*failures*)
143 (cond (*break-on-error*
144 (test-util:really-invoke-debugger condition))
146 (format *error-output* "~&Unhandled ~a: ~a~%"
147 (type-of condition) condition)
148 (sb-debug:print-backtrace)))
149 (invoke-restart 'skip-file))))
150 ,test-code)
151 (skip-file ()
152 (format t ">>>~a<<<~%" test-util::*failures*)))
153 (test-util:report-test-status)
154 (sb-ext:exit :code 104)))))
156 (defun impure-runner (files test-fun)
157 (when files
158 (format t "// Running impure tests (~a)~%" test-fun)
159 (let ((*package* (find-package :cl-user)))
160 (setup-cl-user)
161 (dolist (file files)
162 (force-output)
163 (let ((exit-code (run-impure-in-child-sbcl file
164 (funcall test-fun file))))
165 (if (= exit-code 104)
166 (with-open-file (stream "test-status.lisp-expr"
167 :direction :input
168 :if-does-not-exist :error)
169 (append-failures (read stream)))
170 (push (list :invalid-exit-status file)
171 *all-failures*)))))))
173 (defun make-error-handler (file)
174 (lambda (condition)
175 (push (list :unhandled-error file) *failures*)
176 (cond (*break-on-error*
177 (test-util:really-invoke-debugger condition))
179 (format *error-output* "~&Unhandled ~a: ~a~%"
180 (type-of condition) condition)
181 (sb-debug:print-backtrace)))
182 (invoke-restart 'skip-file)))
184 (defun append-failures (&optional (failures *failures*))
185 (setf *all-failures* (append failures *all-failures*)))
187 (defun unexpected-failures ()
188 (remove-if (lambda (x)
189 (or (eq (car x) :expected-failure)
190 (eq (car x) :unexpected-success)
191 (eq (car x) :skipped-broken)
192 (eq (car x) :skipped-disabled)))
193 *all-failures*))
195 (defun setup-cl-user ()
196 (use-package :test-util)
197 (use-package :assertoid))
199 (defun load-test (file)
200 `(load ,file))
202 (defun cload-test (file)
203 `(let ((compile-name (compile-file-pathname ,file)))
204 (unwind-protect
205 (progn
206 (compile-file ,file)
207 (load compile-name))
208 (ignore-errors
209 (delete-file compile-name)))))
211 (defun sh-test (file)
212 ;; What? No SB-POSIX:EXECV?
213 `(let ((process (sb-ext:run-program "/bin/sh"
214 (list (native-namestring ,file))
215 :output *error-output*)))
216 (let ((*failures* nil))
217 (test-util:report-test-status))
218 (sb-ext:exit :code (process-exit-code process))))
220 (defun filter-test-files (wild-mask)
221 (if *explicit-test-files*
222 (loop for file in *explicit-test-files*
223 when (pathname-match-p file wild-mask)
224 collect file)
225 (directory wild-mask)))
227 (defun pure-load-files ()
228 (filter-test-files "*.pure.lisp"))
230 (defun pure-cload-files ()
231 (filter-test-files "*.pure-cload.lisp"))
233 (defun impure-load-files ()
234 (filter-test-files "*.impure.lisp"))
236 (defun impure-cload-files ()
237 (filter-test-files "*.impure-cload.lisp"))
239 (defun sh-files ()
240 (filter-test-files "*.test.sh"))