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
)
123 (list* "--core" SB-INT
:*CORE-STRING
*
129 (loop for form in
(append load-forms forms
)
131 collect
(write-to-string form
)))
135 (defun clear-test-status ()
136 (with-open-file (stream "test-status.lisp-expr"
138 :if-exists
:supersede
)
139 (write-line "NIL" stream
)))
141 (defun run-impure-in-child-sbcl (test-file test-code
)
146 (defpackage :run-tests
147 (:use
:cl
:test-util
:sb-ext
)))
149 `((in-package :cl-user
)
150 (use-package :test-util
)
151 (use-package :assertoid
)
152 (setf test-util
:*break-on-failure
* ,test-util
:*break-on-failure
*)
153 (setf test-util
:*break-on-expected-failure
*
154 ,test-util
:*break-on-expected-failure
*)
155 (let* ((file ,test-file
)
156 (sb-ext:*evaluator-mode
* ,*test-evaluator-mode
*)
158 (if (eq sb-ext
:*evaluator-mode
* :interpret
)
159 (cons :interpreter
*features
*)
161 (*break-on-error
* ,run-tests
::*break-on-error
*))
162 (declare (special *break-on-error
*))
163 (format t
"// Running ~a in ~a evaluator mode~%"
164 file sb-ext
:*evaluator-mode
*)
167 ((error (lambda (condition)
168 (push (list :unhandled-error file
)
169 test-util
::*failures
*)
170 (cond (*break-on-error
*
171 (test-util:really-invoke-debugger condition
))
173 (format *error-output
* "~&Unhandled ~a: ~a~%"
174 (type-of condition
) condition
)
175 (sb-debug:print-backtrace
)))
176 (invoke-restart 'skip-file
))))
179 (format t
">>>~a<<<~%" test-util
::*failures
*)))
180 (test-util:report-test-status
)
181 (sb-ext:exit
:code
104)))))
183 (defun impure-runner (files test-fun
)
185 (format t
"// Running impure tests (~a)~%" test-fun
)
186 (let ((*package
* (find-package :cl-user
)))
190 (let ((exit-code (run-impure-in-child-sbcl file
191 (funcall test-fun file
))))
192 (if (= exit-code
104)
193 (with-open-file (stream "test-status.lisp-expr"
195 :if-does-not-exist
:error
)
196 (append-failures (read stream
)))
197 (push (list :invalid-exit-status file
)
198 *all-failures
*)))))))
200 (defun make-error-handler (file)
202 (push (list :unhandled-error file
) *failures
*)
203 (cond (*break-on-error
*
204 (test-util:really-invoke-debugger condition
))
206 (format *error-output
* "~&Unhandled ~a: ~a~%"
207 (type-of condition
) condition
)
208 (sb-debug:print-backtrace
)))
209 (invoke-restart 'skip-file
)))
211 (defun append-failures (&optional
(failures *failures
*))
212 (setf *all-failures
* (append failures
*all-failures
*)))
214 (defun unexpected-failures ()
215 (remove-if (lambda (x)
216 (or (eq (car x
) :expected-failure
)
217 (eq (car x
) :unexpected-success
)
218 (eq (car x
) :skipped-broken
)
219 (eq (car x
) :skipped-disabled
)))
222 (defun setup-cl-user ()
223 (use-package :test-util
)
224 (use-package :assertoid
))
226 (defun load-test (file)
227 `(load ,file
:external-format
:utf-8
))
229 (defun cload-test (file)
230 `(let ((compile-name (compile-file-pathname ,file
)))
233 (compile-file ,file
:print nil
)
236 (delete-file compile-name
)))))
238 (defun sh-test (file)
239 ;; What? No SB-POSIX:EXECV?
242 (sb-posix:setenv
"TEST_SBCL_EVALUATOR_MODE"
243 (string-downcase ,*test-evaluator-mode
*)
245 (let ((process (sb-ext:run-program
"/bin/sh"
246 (list (native-namestring ,file
))
247 :output
*error-output
*)))
248 (let ((*failures
* nil
))
249 (test-util:report-test-status
))
250 (sb-ext:exit
:code
(process-exit-code process
)))))
252 (defun filter-test-files (wild-mask)
253 (if *explicit-test-files
*
254 (loop for file in
*explicit-test-files
*
255 when
(pathname-match-p file wild-mask
)
257 (directory wild-mask
)))
259 (defun pure-load-files ()
260 (filter-test-files "*.pure.lisp"))
262 (defun pure-cload-files ()
263 (filter-test-files "*.pure-cload.lisp"))
265 (defun impure-load-files ()
266 (filter-test-files "*.impure.lisp"))
268 (defun impure-cload-files ()
269 (filter-test-files "*.impure-cload.lisp"))
272 (filter-test-files "*.test.sh"))