clojure-spec

About: http://clojure.org/about/spec Guide: http://clojure.org/guides/spec API: https://clojure.github.io/spec.alpha/clojure.spec.alpha-api.html
neilyio 2020-11-20T19:53:43.391600Z

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.

borkdude 2020-11-20T19:55:29.392200Z

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

borkdude 2020-11-20T19:55:42.392600Z

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

borkdude 2020-11-20T19:58:22.393300Z

@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

neilyio 2020-11-20T20:45:09.394500Z

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

neilyio 2020-11-20T20:55:22.396500Z

Actually, this is happening only on a specific spec.

neilyio 2020-11-20T20:55:30.396700Z

Will debug.

borkdude 2020-11-20T20:56:08.396900Z

Maybe you are using with-gen in this spec?

kenny 2020-11-20T21:25:46.397400Z

Could potentially be an fspec

neilyio 2020-11-20T21:49:17.397600Z

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

kenny 2020-11-20T21:50:29.398200Z

Fspec uses gen testing during explain.

neilyio 2020-11-20T21:52:16.398400Z

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)

neilyio 2020-11-20T21:52:34.398600Z

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

borkdude 2020-11-20T21:55:40.398800Z

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

borkdude 2020-11-20T21:56:39.399Z

I would have expected:

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

neilyio 2020-11-20T21:57:41.399200Z

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

neilyio 2020-11-20T21:59:04.399400Z

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.

borkdude 2020-11-20T22:00:19.399600Z

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

neilyio 2020-11-20T22:01:38.399800Z

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)

borkdude 2020-11-20T22:02:48.400Z

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

borkdude 2020-11-20T22:03:51.400200Z

I think it should be something like:

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

borkdude 2020-11-20T22:05:45.400400Z

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.

neilyio 2020-11-20T22:06:03.400700Z

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

borkdude 2020-11-20T22:06:16.400900Z

a sequential

borkdude 2020-11-20T22:06:45.401200Z

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

neilyio 2020-11-20T22:06:52.401400Z

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

borkdude 2020-11-20T22:06:57.401600Z

:args (s/cat :f ifn?)

borkdude 2020-11-20T22:07:36.401800Z

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.

neilyio 2020-11-20T22:09:55.402100Z

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

neilyio 2020-11-20T22:10:33.402300Z

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

borkdude 2020-11-20T22:10:36.402500Z

what does your ns form look like?

neilyio 2020-11-20T22:29:42.402700Z

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)

neilyio 2020-11-20T22:30:09.402900Z

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

neilyio 2020-11-20T22:31:02.403100Z

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]

neilyio 2020-11-20T22:31:31.403300Z

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

borkdude 2020-11-20T22:32:32.403700Z

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

neilyio 2020-11-20T22:32:52.403900Z

Yup, I think it's bug report time.

neilyio 2020-11-20T22:33:02.404100Z

Thanks for talking me through this @borkdude

borkdude 2020-11-20T22:33:23.404300Z

:thumbsup:

neilyio 2020-11-20T22:44:20.404500Z

https://github.com/bhauman/figwheel-main/issues/272 for all those who are lost in the future.

borkdude 2020-11-20T22:51:46.404900Z

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

neilyio 2020-11-20T22:55:50.405100Z

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

neilyio 2020-11-20T22:56:12.405300Z

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

neilyio 2020-11-20T22:56:31.405500Z

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

borkdude 2020-11-20T23:00:18.405700Z

#clojurescript

borkdude 2020-11-20T23:00:29.405900Z

you could link to the figwheel issue to explain your issue

neilyio 2020-11-20T23:00:58.406100Z

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

borkdude 2020-11-20T23:05:02.406300Z

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.

borkdude 2020-11-20T23:06:18.406500Z

Have you tried requiring cljs.test.check?

borkdude 2020-11-20T23:06:26.406700Z

instead of clojure.test.check

borkdude 2020-11-20T23:07:57.406900Z

neh, that's not it

neilyio 2020-11-20T23:15:02.407100Z

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

neilyio 2020-11-20T23:15:26.407300Z

Beer coming your way too.

borkdude 2020-11-20T23:15:56.407500Z

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