Skip to content

Commit

Permalink
Correctly handle FLET and dotted lists in DEFINE-TESTCASE
Browse files Browse the repository at this point in the history
  • Loading branch information
foretspaisibles committed Apr 15, 2024
1 parent d33f8cf commit 3fb8c99
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
15 changes: 8 additions & 7 deletions src/testcase.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,9 @@ guarantees that conditions triggered by the evaluation of arguments are recorded
(cond
((symbolp form)
form)
((and (listp form) (eq (first form) 'quote))
((and (listp form) (eq (first form) 'quote) (eq 2 (length form)))
(second form))
((and (listp form) (eq (first form) 'function))
((and (listp form) (eq (first form) 'function) (eq 2 (length form)))
(second form))))
(is-funcall-p (form)
"Predicate recognising forms which are function calls.
Expand All @@ -480,15 +480,16 @@ symbol of this function."
:org.melusina.confidence/assertion))
(wrap-assertion-forms (form)
(cond
((atom form)
form)
((eq 'without-confidence (is-funcall-p form))
`(progn ,@(rest form)))
((is-assert-form-p form)
`(instrument-assertion ,form))
((is-funcall-p form)
(cons (first form) (mapcar #'wrap-assertion-forms (rest form))))
(t
form))))
(mapcar #'wrap-assertion-forms body-forms)))
((consp form)
(cons (wrap-assertion-forms (car form))
(wrap-assertion-forms (cdr form)))))))
(wrap-assertion-forms body-forms)))

(defun testcase-outcome-pathname (outcome)
"The pathname used to write OUTCOME description."
Expand Down
21 changes: 17 additions & 4 deletions testsuite/testcase.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,24 @@

(define-testcase perform-many-assertions-wrapped-with-flet (&key success failure condition)
(flet ((wrapper ()
(perform-many-assertions
:success success
:failure failure
:condition condition)))
(when success
(dotimes (_ success)
(assert-t t)))
(when failure
(dotimes (_ failure)
(assert-t nil)))
(when condition
(dotimes (_ condition)
(assert-t (error "An error condition was signalled."))))))
(wrapper)))

(define-testcase ensure-that-define-testcase-handles-dotted-lists ()
(assert-t
(listp
(macroexpand-1
'(define-testcase example ()
(loop :for (a . b) :in '((1 . 1) (2 . 2)) :do (assert-equal a b)))))))

(define-testcase ensure-that-testcase-is-reported-when-wrapped-in-flet ()
(with-testcase-outcome testcase-outcome
(perform-many-assertions-wrapped-with-flet :success 100 :failure 10 :condition 1)
Expand All @@ -101,6 +113,7 @@
(validate-define-testcase)
(ensure-that-define-testcase-recognises-sharpsign-single-quote-in-function-names)
(ensure-that-testcase-is-reported-when-wrapped-in-flet)
(ensure-that-define-testcase-handles-dotted-lists)
(validate-supervise-assertion))

;;;; End of file `testcase.lisp'

0 comments on commit 3fb8c99

Please sign in to comment.