-
Notifications
You must be signed in to change notification settings - Fork 24
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
Handle printing of clojure.spec.test.alpha/check results #72
Comments
For example, take this simple function: (defn fabulous
[x y]
nil)
(s/fdef fabulous
:args (s/cat :x number? :y number?)
:ret string?) Running We can do a little better by passing some data from the returned list to expound:
|
@kennyjwilli Thanks for reporting this! I haven't used |
OMG yes please! |
@kennyjwilli @aviflax I've added a few functions: (require '[clojure.spec.alpha :as s])
(require '[clojure.spec.test.alpha :as st])
(require '[expound.alpha :as expound])
(defn fabulous
[x y]
nil)
(s/fdef fabulous
:args (s/cat :x number? :y number?)
:ret string?)
(set! s/*explain-out* expound/printer)
(expound/explain-results (st/check `fabulous))
;;== Checked expound.alpha/fabulous ===========
;;
;;-- Function spec failed -----------
;;
;; nil
;;
;;returned an invalid value
;;
;; nil
;;
;;should satisfy
;;
;; string?
;;
;;
;;
;;-------------------------
;;Detected 1 error As you can see, you can pass the results from If you're so inclined, you can try it by installing "0.5.1-SNAPSHOT" |
The approach seems good - that's is exactly how I'd use it. I know you said the error messages need some work, but I thought I'd still let you know of a couple cases that aren't reported correctly. This example fails with an ClassCastException but Expound thinks it was successful. (defn my-add2
[x y]
(+ (str x) y))
(s/fdef my-add2
:args (s/cat :x number? :y number?)
:ret string?)
(expound/explain-results (st/check `my-add2))
== Checked user/my-add2 =
Success!
=> nil Sometimes test.check may fail to generate. In this case we get an exception that says "Unable to construct gen at: [:f] for: fn?". This exception is thrown from text.check and is stored in the path (defn takes-fn
[f]
(f 1))
(s/fdef takes-fn
:args (s/cat :f fn?)
:ret any?)
(st/check `takes-fn)
=>
({:spec #object[clojure.spec.alpha$fspec_impl$reify__2451
0x2c417d47
"clojure.spec.alpha$fspec_impl$reify__2451@2c417d47"],
:clojure.spec.test.check/ret {:result #error{:cause "Unable to construct gen at: [:f] for: fn?",
:data #:clojure.spec.alpha{:path [:f],
:form clojure.core/fn?,
:failure :no-gen}}},
:sym user/takes-fn,
:failure #error{:cause "Unable to construct gen at: [:f] for: fn?",
:data #:clojure.spec.alpha{:path [:f], :form clojure.core/fn?, :failure :no-gen}}})
(expound/explain-results (st/check `takes-fn))
== Checked user/takes-fn
=> nil |
@kennyjwilli This is extremely helpful feedback. Thanks! |
@kennyjwilli @aviflax Thanks for the detailed help on how failure modes of |
Looks good. Here's another example that isn't working correctly. (defn my-broken-add
[x y]
(+ (str x) y))
(s/fdef my-broken-add
:args (s/cat :x number? :y number?)
:ret string?)
(expound/explain-results (st/check `my-broken-add))
== Checked user/my-broken-add
Success!
=> nil Running (defn ithrow
[x]
(throw (ex-info "ithrow" {})))
(s/fdef ithrow
:args (s/cat :x number?)
:ret string?)
(expound/explain-results (st/check `ithrow))
== Checked user/ithrow ==
Success!
=> nil |
@kennyjwilli That's weird, I see different behavior locally. When I try, I get
Is it possible that your local version of |
Perhaps try |
Running with |
@kennyjwilli Hmm, this is very strange. I fear that I've done something wrong here, or there is some context that I'm missing. I appreciate your help on this! What happens if you do the following?
And then, in the REPL, you do: (require '[expound.alpha :as expound]
'[clojure.spec.test.alpha :as st]
'[clojure.spec.alpha :as s]
'[clojure.test.check])
(set! s/*explain-out* (expound/custom-printer {:theme :figwheel-theme}))
(defn ithrow
[x]
(throw (ex-info "ithrow" {})))
(s/fdef ithrow
:args (s/cat :x number?)
:ret string?)
(expound/explain-results (st/check `ithrow)) Do you see the same behavior as before? Thanks for your continued help! |
@kennyjwilli What's weird is that I thought I saw the behavior you reported at one point, but now I cannot reproduce. I wonder if there is something weird with |
|
@kennyjwilli Excellent, glad to hear it worked. Thanks for all your help! |
@kennyjwilli @aviflax This feature is in expound 0.6.0. Thanks for all your help! |
@bhb Thanks for your responsiveness and great work. Looking forward to using this feature! |
The output from
clojure.spec.test.alpha/check
is unwieldy. Seems like Expound could provide a way to cleanly print these results.The text was updated successfully, but these errors were encountered: