From 287c9bb8435332a4cb5f07fd4ef08c6a76c3499f Mon Sep 17 00:00:00 2001 From: Marco Baringer Date: Wed, 10 Aug 2005 12:11:54 +0200 Subject: [PATCH] Fix bugs in the handling and reporting of unexpected errors --- src/check.lisp | 4 +++- src/run.lisp | 58 +++++++++++++++++++++++++++----------------------------- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/check.lisp b/src/check.lisp index f5162f0..eba0adf 100644 --- a/src/check.lisp +++ b/src/check.lisp @@ -77,9 +77,11 @@ when appropiate.")) initialize args MAKE-INSTANCE-ARGS and adds the resulting object to the list of test results." (with-run-state (result-list current-test) - (let ((result (apply #'make-instance result-type (append make-instance-args (list :test-case current-test))))) + (let ((result (apply #'make-instance result-type + (append make-instance-args (list :test-case current-test))))) (etypecase result (test-passed (format *test-dribble* ".")) + (unexpected-test-failure (format *test-dribble* "X")) (test-failure (format *test-dribble* "f")) (test-skipped (format *test-dribble* "s"))) (push result result-list)))) diff --git a/src/run.lisp b/src/run.lisp index af9e8a5..b2bbf24 100644 --- a/src/run.lisp +++ b/src/run.lisp @@ -104,19 +104,6 @@ run.")) (and (satisfies-depends-p #'every)) (or (satisfies-depends-p #'some)) (not (satisfies-depends-p #'notany)))))) - -(defun handle-unexpected-error (test error) - "Handler for unexpected conditions raised during test - execution." - (when (not *debug-on-error*) - (format *test-dribble* "F") - (with-run-state (result-list) - (push (make-instance 'unexpected-test-failure - :test-case test - :reason (format nil "Unexpected Error: ~S." error) - :condition test) - result-list) - (throw 'run-block result-list)))) (defun results-status (result-list) "Given a list of test results (generated while running a test) @@ -136,23 +123,34 @@ run.")) (defmethod run-test-lambda ((test test-case)) (with-run-state (result-list) - (catch 'run-block - (bind-run-state ((current-test test)) - (handler-bind ((error (lambda (e) (handle-unexpected-error test e)))) - (restart-case - (let ((results (return-result-list (test-lambda test)))) - (setf (status test) (results-status results) - result-list (nconc result-list results))) - (retest () - :report (lambda (stream) - (format stream "~@" test)) - (%run test)) - (ignore () - :report (lambda (stream) - (format stream "~@" test)) - (push (make-instance 'test-failure :test-case test - :reason "Failure restart.") - result-list)))))))) + (bind-run-state ((current-test test)) + (labels ((abort-test (e) + (add-result 'unexpected-test-failure + :test-case test + :reason (format nil "Unexpected Error: ~S." e) + :condition e)) + (run-it () + (let ((result-list '())) + (declare (special result-list)) + (handler-bind ((error (lambda (e) + (unless *debug-on-error* + (abort-test e) + (return-from run-it result-list))))) + (restart-case + (funcall (test-lambda test)) + (retest () + :report (lambda (stream) + (format stream "~@" test)) + (return-from run-it (run-it))) + (ignore () + :report (lambda (stream) + (format stream "~@" test)) + (abort-test (make-instance 'test-failure :test-case test + :reason "Failure restart.")))) + result-list)))) + (let ((results (run-it))) + (setf (status test) (results-status results) + result-list (nconc result-list results))))))) (defgeneric %run (test-spec) (:documentation "Internal method for running a test. Does not -- 1.7.10.4