defexpect with a single expression should behave like deftest
seancorfield opened this issue · 1 comments
Currently, a defexpect whose body is one or two expressions with no embedded expect is treated as shorthand for an expect with those expressions. That's fine for two expressions:
(defexpect my-name (expected-expr) (actual-expr))
;; becomes
(defexpect my-name (expect (expected-expr) (actual-expr)))But for a single expression, this means a difference of behavior compared to deftest:
(defexpect my-name (actual-expr))
;; becomes
(defexpect my-name (expect (actual-expr)))
;; which is treated as
(deftest my-name (is (actual-expr)))But a single expression in the body of a deftest is just "odd" and behaves like a regular function:
(deftest my-name (actual-expr))That just runs the code as-is, no assertions. I think the single-bodied defexpect above should behave the same way (perhaps with a warning on macroexpansion).
I made 0- and 1-form bodies throw exceptions as a test case for our codebase at work and ran into no issues.
(deftest foo) is legal and creates a test with an empty body -- (defexpect foo) is illegal (wrong number of arguments to expect) -- that's a bug.
I intend to make the following changes:
- Fix the bug above and make 0- and 1-form
defexpect(withoutexpect) behave exactly likedeftest
Since this is potentially breaking -- (defexpect foo (produces-falsey)) would be a failing test right now -- I'll bump to 2.x after this change but I really don't expect anyone to be relying on that (and it's never been documented).