Skip to content

Commit

Permalink
fixup! Break into the debugger upon error
Browse files Browse the repository at this point in the history
Simplify the INSTRUMENT-ASSERTION-1 function.
  • Loading branch information
foretspaisibles committed Apr 12, 2024
1 parent ae06df9 commit 32f965c
Showing 1 changed file with 65 additions and 64 deletions.
129 changes: 65 additions & 64 deletions src/testcase.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -319,70 +319,71 @@ instead of returning normally."))

(defun instrument-assertion-1 (&key name form type argument-names argument-lambdas assertion-lambda)
"Supervise the execution of ARGUMENTS-LAMBDA and ASSERTION-LAMBDA."
(labels ((evaluation-strategy-1 (argument-condition argument-values)
(flet ((signal-argument-condition (condition)
(signal
'assertion-condition
:path *testcase-path*
:name name
:argument-names argument-names
:argument-values argument-values
:form form
:type type
:condition condition))
(signal-unexpected-condition (condition)
(signal
'assertion-condition
:path *testcase-path*
:name name
:argument-names argument-names
:argument-values argument-values
:form form
:type type
:condition condition))
(signal-failure (description)
(signal
'assertion-failure
:path *testcase-path*
:name name
:argument-names argument-names
:argument-values argument-values
:form form
:type type
:description description))
(signal-success ()
(signal
'assertion-success
:path *testcase-path*
:name name
:argument-names argument-names
:argument-values argument-values
:form form
:type type)))
(when argument-condition
(signal-argument-condition (first argument-condition))
(return-from evaluation-strategy-1))
(multiple-value-bind (success-p description)
(handler-case (funcall assertion-lambda argument-values)
(serious-condition (unexpected-condition)
(signal-unexpected-condition unexpected-condition)
(return-from evaluation-strategy-1)))
(cond
((not success-p)
(signal-failure description))
(t
(signal-success))))))
(evaluation-strategy (argument-values)
(evaluation-strategy-1
(member-if (lambda (object) (typep object 'condition)) argument-values)
argument-values))
(supervise-evaluation-1 (argument-lambda)
(handler-case (funcall argument-lambda)
(t (unexpected-condition)
unexpected-condition)))
(supervise-evaluation (argument-lambdas)
(evaluation-strategy (mapcar #'supervise-evaluation-1 argument-lambdas))))
(supervise-evaluation argument-lambdas)))
(flet ((evaluate-assertion-lambda (argument-values argument-conditions)
(flet ((signal-argument-condition (condition)
(signal
'assertion-condition
:path *testcase-path*
:name name
:argument-names argument-names
:argument-values argument-values
:form form
:type type
:condition condition))
(signal-unexpected-condition (condition)
(signal
'assertion-condition
:path *testcase-path*
:name name
:argument-names argument-names
:argument-values argument-values
:form form
:type type
:condition condition))
(signal-failure (description)
(signal
'assertion-failure
:path *testcase-path*
:name name
:argument-names argument-names
:argument-values argument-values
:form form
:type type
:description description))
(signal-success ()
(signal
'assertion-success
:path *testcase-path*
:name name
:argument-names argument-names
:argument-values argument-values
:form form
:type type)))
(when argument-conditions
(signal-argument-condition (first argument-conditions))
(return-from evaluate-assertion-lambda))
(multiple-value-bind (success-p description)
(handler-case (funcall assertion-lambda argument-values)
(serious-condition (unexpected-condition)
(signal-unexpected-condition unexpected-condition)
(return-from evaluate-assertion-lambda)))
(cond
((not success-p)
(signal-failure description))
(t
(signal-success))))))
(evaluate-argument-lambda (argument-lambda)
(handler-case (values nil (funcall argument-lambda))
(t (unexpected-condition)
(values t unexpected-condition)))))
(loop :with argument-condition-p :and argument-value
:for argument-lambda :in argument-lambdas
:do (setf (values argument-condition-p argument-value)
(evaluate-argument-lambda argument-lambda))
:collect argument-value :into argument-values
:when argument-condition-p
:collect argument-value :into argument-conditions
:finally (evaluate-assertion-lambda argument-values argument-conditions))))

(defmacro instrument-assertion (form)
"Instrument the execution of the assertion FORM and return ASSERTION evaluation details.
Expand Down

0 comments on commit 32f965c

Please sign in to comment.