1 (handler-bind (#+win32
(warning #'muffle-warning
))
4 (load "test-util.lisp")
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
)
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
)
39 (sb-ext:exit
:code
(if (unexpected-failures)
45 (format t
"Finished running tests.~%")
49 (format t
"Status:~%")
50 (dolist (fail (reverse *all-failures
*))
51 (cond ((eq (car fail
) :unhandled-error
)
52 (output-colored-text (car fail
)
55 (enough-namestring (second fail
))))
56 ((eq (car fail
) :invalid-exit-status
)
57 (output-colored-text (car fail
)
58 " Invalid exit status:")
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
))
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
))
82 (format t
" (~a tests skipped for this combination of platform and features)~%"
85 (format t
"All tests succeeded~%")))))
87 (defun pure-runner (files test-fun
)
89 (format t
"// Running pure tests (~a)~%" test-fun
)
90 (let ((*package
* (find-package :cl-user
))
94 (format t
"// Running ~a~%" file
)
96 (handler-bind ((error (make-error-handler file
)))
97 (eval (funcall test-fun file
)))
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.
105 (#-win32 with-open-file
#-win32
(devnull "/dev/null") #+win32 progn
109 (list "--core" SB-INT
:*CORE-STRING
*
114 "--disable-debugger")
115 (loop for form in
(append load-forms forms
)
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
)
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
)
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
))))
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
)
158 (format t
"// Running impure tests (~a)~%" test-fun
)
159 (let ((*package
* (find-package :cl-user
)))
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"
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)
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
)))
195 (defun setup-cl-user ()
196 (use-package :test-util
)
197 (use-package :assertoid
))
199 (defun load-test (file)
202 (defun cload-test (file)
203 `(let ((compile-name (compile-file-pathname ,file
)))
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
)
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"))
240 (filter-test-files "*.test.sh"))