Could anyone give me a hand with this error?
Var clojure.test.check.generators/simple-type-printable does not exist, clojure.test.check.generators never required
happens every time I call `(spec/explain ::my-spec my-val)` in ClojureScript. I don't have instrumentation turned on.
I've followed the advice at https://stackoverflow.com/questions/57877004/how-to-fix-clojure-test-check-generators-never-required-when-exercising-a-func and added `org.clojure/test.check` to my `deps.edn` dependencies, but it hasn't fixed the problem.
when you see this message, in CLJS you should require the ns yourself.
but it surprises me that s/explain needs test.check, that should not be the case I think
@neil.hansen.31 which version of CLJS are you using?
borkdude@MBP2019 /tmp $ clj -A:test -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version "1.10.597"}}}' -m cljs.main -re node
WARNING: When invoking clojure.main, use -M
ClojureScript 1.10.597
cljs.user=> (require '[clojure.spec.alpha :as s])
nil
cljs.user=> (s/def ::foo int?)
:cljs.user/foo
cljs.user=> (s/explain ::foo 1)
Success!
nil
@borkdude I'm on 1.10.773. I'm trying it on an empty REPL now and it's working as your example is... I guess something is going on in my Figwheel build that I'll have to figure out...
Actually, this is happening only on a specific spec.
Will debug.
Maybe you are using with-gen in this spec?
Could potentially be an fspec
Yes, it's definitely something to do with fspec. It also seems to act strange in this case:
(spec/fdef foo
:args (spec/fspec :args (spec/cat)))
Fspec uses gen testing during explain.
When I instrument these functions:
(defn foo []
nil)
(defn bar []
nil)
I get a "spec failed... should satisfy ifn?" expound error with this:
(foo bar)
I would expect that to Success!
. Am I misunderstanding something?
@neil.hansen.31 Why are you using fspec
here?
I would have expected:
(spec/fdef foo
:args (spec/cat))
Yup, I'm starting to realize I'm doing something seriously wrong here 😛
I made an assumption from the https://clojure.org/guides/spec#_higher_order_functions that fspec
would work for :args
, but it seems like it's only for :ret
. I was hoping that spec could check that the arguments to my function would receive only certain arguments.
spec can check that. it does when you instrument the function
Oh, also my example for foo was wrong up above, sorry, it should have been something like:
(defn foo [f]
(f))
(defn bar []
nil)
(foo bar)
Then your spec may have been correct, and the error message makes sense. Foo wasn't passed an IFn
I think it should be something like:
(spec/fdef foo
:args (spec/cat :f (spec/fspec :args (spec/cat))))
In Clojure:
user=> (require '[clojure.spec.alpha :as spec])
nil
user=> (spec/fdef foo
#_=> :args (spec/cat :f (spec/fspec :args (spec/cat))))
user/foo
user=> (defn foo [f] (f))
#'user/foo
user=> (stest/instrument 'user/foo)
[user/foo]
user=> (foo identity)
Execution error (FileNotFoundException) at user/eval35926 (form-init3141792093562271177.clj:1).
Could not locate clojure/test/check/generators__init.class, clojure/test/check/generators.clj or clojure/test/check/generators.cljc on classpath.
user=> (foo (fn []))
Execution error (FileNotFoundException) at user/eval35926 (form-init3141792093562271177.clj:1).
Could not locate clojure/test/check/generators__init.class, clojure/test/check/generators.clj or clojure/test/check/generators.cljc on classpath.
Oh my goodness, you're right, thank you so much. The :args
always have to bee a tuple don't they.
a sequential
btw, you can also check for a function using fn?
or ifn?
.
Got it. Funny enough, when I instrument that spec you gave me, I get the error again:
Var clojure.test.check.generators/simple-type-printable does not exist, clojure.test.check.generators never required
:args (s/cat :f ifn?)
yeah, it seems fspec somehow needs test.check. I've never used fspec personally. It seems to be the same in CLJ:
user=> (foo (fn []))
Execution error (FileNotFoundException) at user/eval35926 (form-init3141792093562271177.clj:1).
Could not locate clojure/test/check/generators__init.class, clojure/test/check/generators.clj or clojure/test/check/generators.cljc on classpath.
My issue is that I've installed test.check, I've even required it in my namespace.
So not sure what's happening... For now I'll take your advice and check for ifn?
in my :args
instead.
what does your ns form look like?
Hmm it looks like this is a Figwheel-specific problem. I've made a very minimal test file:
(ns cards.core
(:require
[clojure.test.check :as check]
[clojure.spec.test.alpha :as stest]
[clojure.spec.alpha :as spec]))
(spec/fdef foo
:args (spec/cat :f (spec/fspec
:args (spec/cat))))
(defn foo [f] f)
(defn bar [] nil)
(stest/instrument)
(foo bar)
Evaluating the final (foo bar)
with clj
returns the function object.
Evaluating (foo bar)
with clj -m figwheel.main
returns #object[Error Error: Var clojure.test.check.properties/for-all* does not exist, clojure.test.check.properties never required]
Slightly different error from my original one, but I'd think the problem comes from the same place?
You can try to compile this without figwheel and see if that's it. And then file a bug report with figwheel
Yup, I think it's bug report time.
Thanks for talking me through this @borkdude
:thumbsup:
https://github.com/bhauman/figwheel-main/issues/272 for all those who are lost in the future.
Have you also tried to compile this without Figwheel, but using regular CLJS? That's not clear from this issue
Oh geez, you're right, I get the same error running with clj -m cljs.main
.
I'm just so used to starting cljs with figwheel. Thanks for following up on that.
I'll close the Figwheel issue, what do you think I should do with this?
#clojurescript
you could link to the figwheel issue to explain your issue
I'll do that, I'll close the figwheel issue when someone advises. Thanks again for everything.
I think it would be good to close the figwheel issue and comment that it's not an issue with figwheel, else you might be wasting the maintainer's time.
Have you tried requiring cljs.test.check
?
instead of clojure.test.check
neh, that's not it
Closed it up, posted in #clojurescript. Will buy Bruce Hauman beer someday, will give you full credit for helping me recover from this.
Beer coming your way too.
Sounds good ;) Have a nice weekend! 🍻 I'm off, getting late over here in Europe