Fork me on GitHub
#clojure-spec
<
2019-09-25
>
sundbp17:09:08

I’ve got a question about spec2, how do I do something like this: (s/def ::foo (partial bar 1)) - in spec2 that fails. Wrapping the partial in e.g. s/spec is no solution.

seancorfield17:09:53

I believe function literals are accepted @sundbp -- try (s/def ::foo #(bar 1 %))

sundbp14:09:20

Thanks. Will give that a go

seancorfield18:09:20

Yeah, that works:

user=> (require '[clojure.spec-alpha2 :as s])
nil
user=> (defn bar [n y] (< n y))
#'user/bar
user=> (s/def ::foo #(bar 1 %))
:user/foo
user=> (s/conform ::foo 2)
2
user=> (s/conform ::foo 1)
:clojure.spec-alpha2/invalid
user=> 

andy.fingerhut19:09:19

I can dig into the implementation and find out, but does anyone happen to know whether test.check/quick-check calls clojure.test/is or clojure.test/are internally, and thus is intended to be called inside of a clojure.test/deftest form directly?

andy.fingerhut19:09:39

The doc string says it runs multiple tests, but isn't clear about whether there is a return value

andy.fingerhut19:09:50

Perhaps one reasonable way to use test.check/quick-check inside of a clojure.test/deftest would be (is (:pass? (test.check/quick-check ...))) ?

andy.fingerhut19:09:34

Ah, from looking at test.check's own deftest's, it appears that it often uses (is (:result (test.check/quick-check ...))). I will use that, too.

andy.fingerhut19:09:49

Is there some existing test.check docs that describe the return value of quick-check that I could learn this from? Or perhaps a small addition to the quick-check doc string might be welcome?

gfredericks19:09:00

The docstring of the latest version is pretty explicit about the return value

gfredericks19:09:49

You're correct that the quickcheck function is unrelated to clojure.test; you can integrate manually as you noted, or by using the t.c.clojure-test namespace

andy.fingerhut19:09:23

ok, I may have been checking the quick-check doc string of an older version that core.rrb-vector is using. Let me look at the latest.

👍 4
gfredericks19:09:56

The past was a terrible time

andy.fingerhut19:09:18

OK, much better now. Thanks!