Skip to content

Commit

Permalink
Optionally signal results.
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas M. Hermann committed Feb 1, 2013
1 parent 2e29706 commit ae37843
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions lisp-unit.lisp
Expand Up @@ -91,7 +91,8 @@ functions or even macros does not require reloading any tests.
:print-errors
:summarize-results)
;; Functions for extensibility via signals
(:export :test-run-complete
(:export :signal-results
:test-run-complete
:results)
;; Utility predicates
(:export :logically-equal :set-equal))
Expand Down Expand Up @@ -125,6 +126,9 @@ functions or even macros does not require reloading any tests.
"If not NIL, enter the debugger when an error is encountered in an
assertion.")

(defparameter *signal-results* nil
"Signal the result if non NIL.")

(defun use-debugger-p (condition)
"Debug or ignore errors."
(cond
Expand All @@ -136,6 +140,17 @@ assertion.")
"Use the debugger when testing, or not."
(setq *use-debugger* flag))

(defun signal-results (&optional (flag t))
"Signal the results for extensibility."
(setq *signal-results* flag))

(define-condition test-run-complete ()
((results
:initarg :results
:reader results))
(:documentation
"Signaled when a test run is finished."))

;;; Global unit test database

(defparameter *test-db* (make-hash-table :test #'eq)
Expand Down Expand Up @@ -636,9 +651,6 @@ assertion.")
(length (missing-tests results)))))

;;; Run the tests
(define-condition test-run-complete ()
((results :initarg :results :reader results))
(:documentation "signaled when a test run is finished"))

(defun %run-all-thunks (&optional (package *package*))
"Run all of the test thunks in the package."
Expand All @@ -652,8 +664,9 @@ assertion.")
(push test-name (missing-tests results))
;; Summarize and return the test results
finally
(when *signal-results*
(signal 'test-run-complete :results results))
(summarize-results results)
(signal 'test-run-complete :results results)
(return results)))

(defun %run-thunks (test-names &optional (package *package*))
Expand All @@ -668,8 +681,9 @@ assertion.")
else do
(push test-name (missing-tests results))
finally
(when *signal-results*
(signal 'test-run-complete :results results))
(summarize-results results)
(signal 'test-run-complete :results results)
(return results)))

(defun run-tests (test-names &optional (package *package*))
Expand Down

0 comments on commit ae37843

Please sign in to comment.