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)
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 (impure-runner (sh-files) #'sh-test)
37 (sb-ext:quit :unix-status (if (unexpected-failures)
43 (format t "Finished running tests.~%")
45 (format t "Status:~%")
46 (dolist (fail (reverse *all-failures*))
47 (cond ((eq (car fail) :unhandled-error)
48 (format t " ~20a ~a~%"
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~%"
58 (:expected-failure "Expected failure:")
59 (:unexpected-failure "Failure:")
60 (:unexpected-success "Unexpected success:"))
61 (enough-namestring (second 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))
72 (when (accept-test-file file)
73 (format t "// Running ~a~%" file)
75 (funcall test-fun file)
77 (push (list :unhandled-error file)
79 (when *break-on-error*
80 (test-util:really-invoke-debugger error))))))
83 (defun impure-runner (files test-fun)
84 (format t "// Running impure tests (~a)~%" test-fun)
85 (let ((*package* (find-package :cl-user)))
88 (when (accept-test-file file)
90 (let ((pid (sb-posix:fork)))
92 (format t "// Running ~a~%" file)
94 (funcall test-fun file)
96 (push (list :unhandled-error file) *failures*)
97 (when *break-on-error*
98 (test-util:really-invoke-debugger error))))
100 (sb-ext:quit :unix-status 104))
102 (let ((status (make-array 1 :element-type '(signed-byte 32))))
103 (sb-posix:waitpid pid 0 status)
104 (if (and (sb-posix:wifexited (aref status 0))
105 (= (sb-posix:wexitstatus (aref status 0))
107 (with-open-file (stream "test-status.lisp-expr"
109 :if-does-not-exist :error)
110 (append-failures (read stream)))
111 (push (list :invalid-exit-status file)
112 *all-failures*))))))))))
114 (defun append-failures (&optional (failures *failures*))
115 (setf *all-failures* (append failures *all-failures*)))
117 (defun unexpected-failures ()
118 (remove-if (lambda (x)
119 (or (eq (car x) :expected-failure)
120 (eq (car x) :unexpected-success)))
123 (defun setup-cl-user ()
124 (use-package :test-util)
125 (use-package :assertoid))
127 (defun load-test (file)
130 (defun cload-test (file)
131 (let ((compile-name (compile-file-pathname file)))
137 (delete-file compile-name)))))
139 (defun sh-test (file)
140 ;; What? No SB-POSIX:EXECV?
141 (let ((process (sb-ext:run-program "/bin/sh"
142 (list (namestring file))
143 :output *error-output*)))
144 (sb-ext:quit :unix-status (process-exit-code process))))
146 (defun accept-test-file (file)
148 (find (truename file) *accept-files* :test #'equalp)
151 (defun pure-load-files ()
152 (directory "*.pure.lisp"))
154 (defun pure-cload-files ()
155 (directory "*.pure-cload.lisp"))
157 (defun impure-load-files ()
158 (directory "*.impure.lisp"))
160 (defun impure-cload-files ()
161 (directory "*.impure-cload.lisp"))
164 (directory "*.test.sh"))