1 (load "test-util.lisp")
4 (:use
:cl
:test-util
:sb-ext
))
6 (load "assertoid.lisp")
10 (load "colorize.lisp")
12 (defvar *test-evaluator-mode
* :compile
)
13 (defvar *all-failures
* nil
)
14 (defvar *break-on-error
* nil
)
15 (defvar *report-skipped-tests
* nil
)
16 (defvar *explicit-test-files
* nil
)
19 (loop :with remainder
= (rest *posix-argv
*)
21 :for arg
= (pop remainder
)
23 ((string= arg
"--evaluator-mode")
24 (let ((mode (pop remainder
)))
26 ((string= mode
"interpret")
27 (setf *test-evaluator-mode
* :interpret
))
28 ((string= mode
"compile")
29 (setf *test-evaluator-mode
* :compile
))
31 (error "~@<Invalid evaluator mode: ~A. Must be one ~
32 of interpret, compile.~@:>"
34 ((string= arg
"--break-on-failure")
35 (setf *break-on-error
* t
)
36 (setf test-util
:*break-on-failure
* t
))
37 ((string= arg
"--break-on-expected-failure")
38 (setf test-util
:*break-on-expected-failure
* t
))
39 ((string= arg
"--report-skipped-tests")
40 (setf *report-skipped-tests
* t
))
41 ((string= arg
"--no-color"))
43 (push (truename (parse-namestring arg
)) *explicit-test-files
*))))
44 (setf *explicit-test-files
* (nreverse *explicit-test-files
*))
45 (pure-runner (pure-load-files) #'load-test
)
46 (pure-runner (pure-cload-files) #'cload-test
)
47 (impure-runner (impure-load-files) #'load-test
)
48 (impure-runner (impure-cload-files) #'cload-test
)
49 #-win32
(impure-runner (sh-files) #'sh-test
)
51 (sb-ext:exit
:code
(if (unexpected-failures)
57 (format t
"Finished running tests.~%")
61 (format t
"Status:~%")
62 (dolist (fail (reverse *all-failures
*))
63 (cond ((eq (car fail
) :unhandled-error
)
64 (output-colored-text (car fail
)
67 (enough-namestring (second fail
))))
68 ((eq (car fail
) :invalid-exit-status
)
69 (output-colored-text (car fail
)
70 " Invalid exit status:")
72 (enough-namestring (second fail
))))
73 ((eq (car fail
) :skipped-disabled
)
74 (when *report-skipped-tests
*
75 (format t
" ~20a ~a / ~a~%"
76 "Skipped (irrelevant):"
77 (enough-namestring (second fail
))
84 (:expected-failure
" Expected failure:")
85 (:unexpected-failure
" Failure:")
86 (:leftover-thread
" Leftover thread (broken):")
87 (:unexpected-success
" Unexpected success:")
88 (:skipped-broken
" Skipped (broken):")
89 (:skipped-disabled
" Skipped (irrelevant):")))
90 (format t
" ~a / ~a~%"
91 (enough-namestring (second fail
))
94 (format t
" (~a tests skipped for this combination of platform and features)~%"
97 (format t
"All tests succeeded~%")))))
99 (defun pure-runner (files test-fun
)
101 (format t
"// Running pure tests (~a)~%" test-fun
)
102 (let ((*package
* (find-package :cl-user
))
106 (format t
"// Running ~a in ~a evaluator mode~%"
107 file
*test-evaluator-mode
*)
109 (handler-bind ((error (make-error-handler file
)))
110 (let* ((sb-ext:*evaluator-mode
* *test-evaluator-mode
*)
112 (if (eq sb-ext
:*evaluator-mode
* :interpret
)
113 (cons :interpreter
*features
*)
115 (eval (funcall test-fun file
))))
119 (defun run-in-child-sbcl (load-forms forms
)
120 ;; We used to fork() for POSIX platforms, and use this for Windows.
121 ;; However, it seems better to use the same solution everywhere.
123 (#-win32 with-open-file
#-win32
(devnull "/dev/null") #+win32 progn
127 (list "--core" SB-INT
:*CORE-STRING
*
132 "--disable-debugger")
133 (loop for form in
(append load-forms forms
)
135 collect
(write-to-string form
)))
136 :output sb-sys
:*stdout
*
137 :input
#-win32 devnull
#+win32 sb-sys
:*stdin
*))))
139 (defun clear-test-status ()
140 (with-open-file (stream "test-status.lisp-expr"
142 :if-exists
:supersede
)
143 (write-line "NIL" stream
)))
145 (defun run-impure-in-child-sbcl (test-file test-code
)
150 (defpackage :run-tests
151 (:use
:cl
:test-util
:sb-ext
)))
153 `((in-package :cl-user
)
154 (use-package :test-util
)
155 (use-package :assertoid
)
156 (setf test-util
:*break-on-failure
* ,test-util
:*break-on-failure
*)
157 (setf test-util
:*break-on-expected-failure
*
158 ,test-util
:*break-on-expected-failure
*)
159 (let* ((file ,test-file
)
160 (sb-ext:*evaluator-mode
* ,*test-evaluator-mode
*)
162 (if (eq sb-ext
:*evaluator-mode
* :interpret
)
163 (cons :interpreter
*features
*)
165 (*break-on-error
* ,run-tests
::*break-on-error
*))
166 (declare (special *break-on-error
*))
167 (format t
"// Running ~a in ~a evaluator mode~%"
168 file sb-ext
:*evaluator-mode
*)
171 ((error (lambda (condition)
172 (push (list :unhandled-error file
)
173 test-util
::*failures
*)
174 (cond (*break-on-error
*
175 (test-util:really-invoke-debugger condition
))
177 (format *error-output
* "~&Unhandled ~a: ~a~%"
178 (type-of condition
) condition
)
179 (sb-debug:print-backtrace
)))
180 (invoke-restart 'skip-file
))))
183 (format t
">>>~a<<<~%" test-util
::*failures
*)))
184 (test-util:report-test-status
)
185 (sb-ext:exit
:code
104)))))
187 (defun impure-runner (files test-fun
)
189 (format t
"// Running impure tests (~a)~%" test-fun
)
190 (let ((*package
* (find-package :cl-user
)))
194 (let ((exit-code (run-impure-in-child-sbcl file
195 (funcall test-fun file
))))
196 (if (= exit-code
104)
197 (with-open-file (stream "test-status.lisp-expr"
199 :if-does-not-exist
:error
)
200 (append-failures (read stream
)))
201 (push (list :invalid-exit-status file
)
202 *all-failures
*)))))))
204 (defun make-error-handler (file)
206 (push (list :unhandled-error file
) *failures
*)
207 (cond (*break-on-error
*
208 (test-util:really-invoke-debugger condition
))
210 (format *error-output
* "~&Unhandled ~a: ~a~%"
211 (type-of condition
) condition
)
212 (sb-debug:print-backtrace
)))
213 (invoke-restart 'skip-file
)))
215 (defun append-failures (&optional
(failures *failures
*))
216 (setf *all-failures
* (append failures
*all-failures
*)))
218 (defun unexpected-failures ()
219 (remove-if (lambda (x)
220 (or (eq (car x
) :expected-failure
)
221 (eq (car x
) :unexpected-success
)
222 (eq (car x
) :skipped-broken
)
223 (eq (car x
) :skipped-disabled
)))
226 (defun setup-cl-user ()
227 (use-package :test-util
)
228 (use-package :assertoid
))
230 (defun load-test (file)
231 `(load ,file
:external-format
:utf-8
))
233 (defun cload-test (file)
234 `(let ((compile-name (compile-file-pathname ,file
)))
240 (delete-file compile-name
)))))
242 (defun sh-test (file)
243 ;; What? No SB-POSIX:EXECV?
246 (sb-posix:setenv
"TEST_SBCL_EVALUATOR_MODE"
247 (string-downcase ,*test-evaluator-mode
*)
249 (let ((process (sb-ext:run-program
"/bin/sh"
250 (list (native-namestring ,file
))
251 :output
*error-output
*)))
252 (let ((*failures
* nil
))
253 (test-util:report-test-status
))
254 (sb-ext:exit
:code
(process-exit-code process
)))))
256 (defun filter-test-files (wild-mask)
257 (if *explicit-test-files
*
258 (loop for file in
*explicit-test-files
*
259 when
(pathname-match-p file wild-mask
)
261 (directory wild-mask
)))
263 (defun pure-load-files ()
264 (filter-test-files "*.pure.lisp"))
266 (defun pure-cload-files ()
267 (filter-test-files "*.pure-cload.lisp"))
269 (defun impure-load-files ()
270 (filter-test-files "*.impure.lisp"))
272 (defun impure-cload-files ()
273 (filter-test-files "*.impure-cload.lisp"))
276 (filter-test-files "*.test.sh"))