You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
clojure.test/assert-expr is clever but slightly magical, which makes it harder to work with: Where does match? come from? How does it work? Why aren't there any docstrings? Why does Clojure throw an "unable to resolve symbol: match?" error if I use this outside of is?
My proposed solution (as seen in clojure-expectations.clojure-test) is to create dummy functions with descriptive docstrings and meaningful argument names that can be referred but will throw exceptions if used outside of is calls:
(defmacrobad-usage [msg]
`(throw IllegalArgumentException ~msg))
(defnmatch?"The `matcher` should be the matcher-combinator represented the expected value, and the `actual` should be the expression being checked."
[matcher actual]
(bad-usage"match? must be used inside of `is`.))
This way, a user can write:
(nsexample.foo
(:require
[clojure.test :refer [deftest is]]
[matcher-combinators.test :refer [match?]]
[matcher-combinators.matchers :as m]))
(deftesttest-matching-with-explicit-matchers
(match? (m/equals37) (+298))
(is (match? (m/regex#"fox") "The quick brown fox jumps over the lazy dog")))
And they'll get a reasonable error message: "match? must be used inside of `is`." instead of the less helpful message Syntax error compiling at (example/foo.clj). Unable to resolve symbol: match? in this context.
If this is reasonable, I'd be willing to open a PR with these changes.
The text was updated successfully, but these errors were encountered:
I like your proposal! I agree that clojure.test/assert-expr is magical indeed, and I can see that error message being helpful for those who do not understand how things work under the hood.
clojure.test/assert-expr
is clever but slightly magical, which makes it harder to work with: Where doesmatch?
come from? How does it work? Why aren't there any docstrings? Why does Clojure throw an "unable to resolve symbol: match?" error if I use this outside ofis
?My proposed solution (as seen in clojure-expectations.clojure-test) is to create dummy functions with descriptive docstrings and meaningful argument names that can be referred but will throw exceptions if used outside of
is
calls:This way, a user can write:
And they'll get a reasonable error message:
"match? must be used inside of `is`."
instead of the less helpful messageSyntax error compiling at (example/foo.clj). Unable to resolve symbol: match? in this context.
If this is reasonable, I'd be willing to open a PR with these changes.
The text was updated successfully, but these errors were encountered: