Skip to content

Commit cc351fd

Browse files
author
Thomas M. Hermann
committed
Define an expand-t-or-f macro to properly handle arguments in assert-true/false form.
1 parent bbf2157 commit cc351fd

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

lisp-unit.lisp

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -440,11 +440,6 @@ output if a test fails.
440440
(expand-macro-form ,form nil)
441441
',expansion ,extras))
442442

443-
(defmacro assert-false (form &rest extras)
444-
"Assert whether the form is false."
445-
(let ((extras `(,@(cdr form) ,@extras)))
446-
`(expand-assert :result ,form ,form nil ,extras)))
447-
448443
(defmacro assert-equality (test expected form &rest extras)
449444
"Assert whether expected and form are equal according to test."
450445
`(expand-assert :equal ,form ,form ,expected ,extras :test ,test))
@@ -454,10 +449,30 @@ output if a test fails.
454449
`(expand-assert :output ,form (expand-output-form ,form)
455450
,output ,extras))
456451

452+
(defmacro assert-false (form &rest extras)
453+
"Assert whether the form is false."
454+
`(expand-t-or-f nil ,form ,extras))
455+
457456
(defmacro assert-true (form &rest extras)
458457
"Assert whether the form is true."
459-
(let ((extras `(,@(cdr form) ,@extras)))
460-
`(expand-assert :result ,form ,form t ,extras)))
458+
`(expand-t-or-f t ,form ,extras))
459+
460+
(defmacro expand-t-or-f (t-or-f form extras)
461+
"Expand the true/false assertions to report the arguments."
462+
(let ((args (gensym))
463+
(fname (gensym)))
464+
`(let ((,args (list ,@(cdr form)))
465+
(,fname ',(car form)))
466+
(internal-assert
467+
:result ',form
468+
(lambda () (apply ,fname ,args)) ; Evaluate the form
469+
(lambda () ,t-or-f)
470+
;; Concatenate the args with the extras
471+
(lambda ()
472+
(nconc
473+
(mapcan #'list ',(cdr form) ,args)
474+
(funcall (expand-extras ,extras))))
475+
#'eql))))
461476

462477
(defmacro expand-assert (type form body expected extras &key (test '#'eql))
463478
"Expand the assertion to the internal format."

0 commit comments

Comments
 (0)