-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add spec-assertion-thrown? test helper #55
Conversation
Seems unlikely to conflict, but just in case I'll review after the bigger PR |
It was https://github.com/nedap/utils.spec/pull/54 Yours is the only PR now, feel free to rebase :) |
48b47f4
to
9cbd456
Compare
I can't seem to get the cljs case working. for some reason the according to this page it should be possible; but I can't seem to get it to work. @vemv would you care to take a look some time? |
The defmethod should work indeed, Will review |
src/nedap/utils/spec/api.cljc
Outdated
@@ -27,3 +30,24 @@ | |||
(let [m (coerce/coerce spec m)] | |||
(cond-> m | |||
(not (spec/valid? spec m)) (assoc ::invalid? true)))) | |||
|
|||
; note that cljs.test/assert-expr expects 3 params, clojure.test/assert-expr 2 | |||
(defmethod test/assert-expr 'check-violated? [& params] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason of your issue appears to be that you should only target the JVM:
Note the #?(:clj
wrapping at L5
It kind of makes sense: I don't expect something that uses syntax-quote, unquote-splicing, etc to work in vanilla cljs (similarly to how you don't have defmacro
in vanilla cljs)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did find a very similar example in cljs.test.cljc as well; so while I'm happy to just target the jvm for this helper, I figured it would just be possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that the cljs compiler can host itself, but we aren't targeting self-hosted cljs - only vanilla one.
So afaict that's an inaccurate example.
cljfmt can be run from JVM-compiled ("vanilla") clojurescript, so when I said "target the JVM", you are not excluding vanilla cljs.
Sorry for the confusion!
9cbd456
to
ee0cb6a
Compare
Had some trouble because of the 'expansion' of specs in speced/defn. It'd require the user of (is (spec-assertion-thrown? 'number? (accepts-number "1234"))) Would fail ( To mitigate this, I check for either an exact match; or a derived match (using the same fn as defn does; |
e290250
to
a66f9da
Compare
@@ -0,0 +1,19 @@ | |||
(ns unit.nedap.utils.speced.spec-assertion |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this test be a .cljc one and added to the runner
ns?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have had little luck getting any of this run on cljs. If i convert to cljc
the jvm / cljs compiler throws the following error;
Syntax error (IllegalAccessError) compiling at (nedap/utils/spec/impl/spec_assertion.cljc:1:1).
infer-spec-from-symbol does not exist
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I managed to narrow this behavior down to a local issue. This suggestion has been addressed.
note that the assertions only run in clj.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have had little luck getting any of this run on cljs.
Can give it a shot after a last round of feedback
[nedap.utils.spec.impl.parsing :refer [infer-spec-from-symbol]]) | ||
#?(:clj (:import (clojure.lang ExceptionInfo)))) | ||
|
||
(defn assert-spec-failure [msg spec-sym body] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a check!
for these args
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't use speced/defn
because it'll be a circular dep; but neither does manually using check! seem to work; after importing like this:
[nedap.utils.spec.impl.check #?(:clj :refer :cljs :refer-macros) [check!]]
it throws;
Syntax error compiling at (nedap/utils/spec/impl/spec_assertion.cljc:9:1).
Can't take value of a macro: #'nedap.utils.spec.impl.check/check!
- support expanded defn specs - rename fns - remove import aliases
f38e163
to
03bf52b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm after final coverage. Thanks for this one!
I'm ok with having this feature as JVM only for now (which should be cleanly offered: no cljs version should be provided at all). A few other things aren't offered for cljs either currently.
Accordingly please create an issue for cljs compat, and include as part of that task adding the check!
that was tricky
Migrated from nedap/utils.test#2