Skip to content

Fix issue 48 #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions lisp-unit.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ assertion.")

(defmacro define-test (name &body body)
"Store the test in the test database."
(format t "defining test ~A~%" name)
(let ((qname (gensym "NAME-")))
(multiple-value-bind (doc tag code) (parse-body body)
`(let* ((,qname (valid-test-name ',name))
Expand Down Expand Up @@ -783,6 +784,7 @@ assertion.")

(defun record-result (test-name code results)
"Run the test code and record the result."
(format t "Beginning test ~A~%" test-name)
(let ((result (run-test-thunk test-name code)))
;; Store the result
(setf (gethash test-name (database results)) result)
Expand All @@ -808,6 +810,13 @@ assertion.")
"Print a summary of all results to the stream."
(let ((pass (pass results))
(fail (fail results)))
;; fixing issue #48
(maphash (lambda (test-name result)
(when (fail result)
(format stream " | failed: ~A~%" test-name))) (database results))
(maphash (lambda (test-name result)
(when (exerr result)
(format stream " | error: ~A~%" test-name))) (database results))
(format stream "~&Unit Test Summary~%")
(format stream " | ~D assertions total~%" (+ pass fail))
(format stream " | ~D passed~%" pass)
Expand Down Expand Up @@ -916,7 +925,12 @@ If MERGE is NIL, then an error is signalled when a conflict occurs."
for test-name being each hash-key in table
using (hash-value unit-test)
if unit-test do
(record-result test-name (code unit-test) results)
(let ((start-time (get-internal-real-time)))
(prog2 (format t "~A ~A~%" package test-name)
(record-result test-name (code unit-test) results)
(format t "~A ~A ~F seconds~%~%" package test-name
(/ (- (get-internal-real-time) start-time)
internal-time-units-per-second))))
else do
(push test-name (missing-tests results))
;; Summarize and return the test results
Expand All @@ -935,7 +949,12 @@ If MERGE is NIL, then an error is signalled when a conflict occurs."
for test-name in test-names
as unit-test = (gethash test-name table)
if unit-test do
(record-result test-name (code unit-test) results)
(let ((start-time (get-internal-real-time)))
(prog2 (format t "~A ~A~%" package test-name)
(record-result test-name (code unit-test) results)
(format t "~A ~A ~F seconds~%~%" package test-name
(/ (- (get-internal-real-time) start-time)
internal-time-units-per-second))))
else do
(push test-name (missing-tests results))
finally
Expand Down Expand Up @@ -969,7 +988,7 @@ If MERGE is NIL, then an error is signalled when a conflict occurs."
(format stream "~& | Failed Form: ~S" (form result))
(call-next-method)
(when (extras result)
(format stream "~{~& | ~S => ~S~}~%" (extras result)))
(format stream "~{~& | ~S ~% => ~S~}~%" (extras result)))
(format stream "~& |~%"))

(defmethod print-failures ((result failure-result) &optional
Expand Down