Is there a reason that clojure.test.check.generators/let
was left out of clojure.spec.gen.alpha/lazy-combinators
?
It’s a macro iirc
I think there’s actually a ticket about this
As a macro, you can’t do the same dynaload we do with the other combinators
https://ask.clojure.org/index.php/4633/let-ported-from-test-check-let-to-clojure-spec-gen
Thank you
This is what I could come up with, it feels unwieldly:
(try
(requiring-resolve 'clojure.test.check.generators/let)
(catch Exception _))
(s/def ::prodquint
(s/with-gen
(s/and string? #(re-matches pro-dquint-regex %))
(fn []
(clojure.test.check.generators/let
[pro-quint-hi (s/gen ::proquint)
pro-quint-lo (s/gen ::proquint)]
(str pro-quint-hi "-" pro-quint-lo)))))
are you trying to produce code that still works if test.check isn't available? if so I can't see how your code accomplishes that
and if not, then I'd think you could just require let
in the more vanilla fashion and everything would be fine
That is what I am trying, and failing, to accomplish. I want the spec to be there with its generator attached to it. Knowing that the generator will only be used int dev/test.
if you want the let
call in the same spot as your spec then I think you basically end up needing eval
or something equivalent
well maybe not
this might work
(defmacro tclet
[& args]
(let [e (try
(requiring-resolve 'clojure.test.check.generators/let)
nil
(catch Exception e e))]
(if e
`(throw (Exception. ~(.getMessage e)))
`(clojure.test.check.generators/let ~@args))))
Thank you @gfredericks!
does it work does it work?
It does!
(turns out I had test.check on the prod classpath all along, now it breaks and works in expected ways)