lispci / fiveam

Common Lisp regression testing framework
BSD 3-Clause "New" or "Revised" License
185 stars 31 forks source link

Difference between the macro and macroexpanded-case (handler-case) #71

Closed digikar99 closed 4 years ago

digikar99 commented 4 years ago

Consider errorp defined as:

(defmacro errorp (form)
  `(typep (handler-case ,form
              (condition (condition) condition))
          'error))

Then, of these, the first form errors when run, the second does not:

(5am:def-test my-test-1 ()
  (5am:is (errorp (error "hello"))))
(5am:def-test my-test-2 ()
  (5am:is (typep (handler-case (error "hello")
                   (condition (condition) condition))
                 'error)))

The behaviour does not occur with other things like (defun foo () (errorp (error "hello"))); (foo) runs fine and does not error, so I'm guessing this has something to do with fiveam.

EDIT: So, okay, expanding 5am:is clearly indicates the issue:

(5am:def-test my-test-1 ()
  (LET ((#:V1074 (ERROR "hello")))
    (IF (ERRORP #:V1074)
        (IT.BESE.FIVEAM::ADD-RESULT 'IT.BESE.FIVEAM::TEST-PASSED :TEST-EXPR
                                    '(ERRORP (ERROR "hello")))
        (IT.BESE.FIVEAM::PROCESS-FAILURE '(ERRORP (ERROR "hello"))
                                         "~2&~S~2% evaluated to ~2&~S~2% which does not satisfy ~2&~S~2%"
                                         '(ERROR "hello") #:V1074 'ERRORP))))

Okay, there is 5am:signals suitable for this use case:

(5am:def-test my-test-1 ()
  (5am:signals error
    (error "hello")))