Fork me on GitHub
#clojure-spec
<
2020-11-20
>
neilyio19:11:43

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.

borkdude19:11:29

when you see this message, in CLJS you should require the ns yourself.

borkdude19:11:42

but it surprises me that s/explain needs test.check, that should not be the case I think

borkdude19:11:22

@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

neilyio20:11:09

@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...

neilyio20:11:22

Actually, this is happening only on a specific spec.

neilyio20:11:30

Will debug.

borkdude20:11:08

Maybe you are using with-gen in this spec?

kenny21:11:46

Could potentially be an fspec

neilyio21:11:17

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)))

kenny21:11:29

Fspec uses gen testing during explain.

neilyio21:11:16

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)

neilyio21:11:34

I would expect that to Success!. Am I misunderstanding something?

borkdude21:11:40

@neil.hansen.31 Why are you using fspec here?

borkdude21:11:39

I would have expected:

(spec/fdef foo
  :args (spec/cat))

neilyio21:11:41

Yup, I'm starting to realize I'm doing something seriously wrong here 😛

neilyio21:11:04

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.

borkdude22:11:19

spec can check that. it does when you instrument the function

neilyio22:11:38

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)

borkdude22:11:48

Then your spec may have been correct, and the error message makes sense. Foo wasn't passed an IFn

borkdude22:11:51

I think it should be something like:

(spec/fdef foo
  :args (spec/cat :f (spec/fspec :args (spec/cat))))

borkdude22:11:45

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.

neilyio22:11:03

Oh my goodness, you're right, thank you so much. The :args always have to bee a tuple don't they.

borkdude22:11:16

a sequential

borkdude22:11:45

btw, you can also check for a function using fn? or ifn?.

neilyio22:11:52

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

borkdude22:11:57

:args (s/cat :f ifn?)

borkdude22:11:36

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.

neilyio22:11:55

My issue is that I've installed test.check, I've even required it in my namespace.

neilyio22:11:33

So not sure what's happening... For now I'll take your advice and check for ifn? in my :args instead.

borkdude22:11:36

what does your ns form look like?

neilyio22:11:42

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)

neilyio22:11:09

Evaluating the final (foo bar) with clj returns the function object.

neilyio22:11:02

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]

neilyio22:11:31

Slightly different error from my original one, but I'd think the problem comes from the same place?

borkdude22:11:32

You can try to compile this without figwheel and see if that's it. And then file a bug report with figwheel

neilyio22:11:52

Yup, I think it's bug report time.

neilyio22:11:02

Thanks for talking me through this @borkdude

borkdude22:11:46

Have you also tried to compile this without Figwheel, but using regular CLJS? That's not clear from this issue

neilyio22:11:50

Oh geez, you're right, I get the same error running with clj -m cljs.main.

neilyio22:11:12

I'm just so used to starting cljs with figwheel. Thanks for following up on that.

neilyio22:11:31

I'll close the Figwheel issue, what do you think I should do with this?

borkdude23:11:18

#clojurescript

borkdude23:11:29

you could link to the figwheel issue to explain your issue

neilyio23:11:58

I'll do that, I'll close the figwheel issue when someone advises. Thanks again for everything.

borkdude23:11:02

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.

borkdude23:11:18

Have you tried requiring cljs.test.check?

borkdude23:11:26

instead of clojure.test.check

borkdude23:11:57

neh, that's not it

neilyio23:11:02

Closed it up, posted in #clojurescript. Will buy Bruce Hauman beer someday, will give you full credit for helping me recover from this.

neilyio23:11:26

Beer coming your way too.

borkdude23:11:56

Sounds good ;) Have a nice weekend! 🍻 I'm off, getting late over here in Europe