This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-07-09
Channels
- # announcements (1)
- # aws (4)
- # beginners (55)
- # calva (13)
- # cider (58)
- # clj-kondo (59)
- # cljs-dev (4)
- # clojure (21)
- # clojure-austin (1)
- # clojure-dev (2)
- # clojure-europe (4)
- # clojure-italy (9)
- # clojure-nl (13)
- # clojure-norway (4)
- # clojure-spec (12)
- # clojure-uk (15)
- # clojurescript (22)
- # cursive (11)
- # datomic (3)
- # duct (1)
- # events (1)
- # fulcro (6)
- # graalvm (28)
- # hoplon (9)
- # jobs (2)
- # jobs-discuss (21)
- # mount (14)
- # nrepl (4)
- # off-topic (38)
- # pathom (1)
- # perun (4)
- # re-frame (17)
- # reitit (32)
- # shadow-cljs (44)
- # testing (7)
- # tools-deps (62)
- # vim (10)
I have an s/keys
with a key of type uuid?
. I have a generative test where I generate a few hundred records, and insert them into postgres, where the uuid uniqueness constraint is checked. Occasionally the test fails due to duplicate uuids. Is there a way to tell spec/test.check to only generate unique uuids?
there are ways of generating unique data within spec/t.c. @arohner but for this usecase I would dedupe between generation and inserting records
It seems useful to have s/with-gen
be passed the generator for the spec it is overriding. Often I find myself generating values from the spec's gen and then fmap
'ing to ensure certain constraints are met.
It'd also be useful to have a variant of s/and that doesn't pass the conformed value to s/and
predicates. We have a lot of this in our specs:
(s/and
(s/keys :req [:metric/tags :metric/lower-bound :metric/upper-bound])
#(metric-tags-valid? (s/unform ::base-metric %))
#(metric-bounds-valid? (s/unform ::base-metric %)))
These such-that errors are quite frustrating because they provide no info:
Error printing return value (ExceptionInfo) at clojure.test.check.generators/fn (generators.cljc:417).
Couldn't satisfy such-that predicate after 100 tries.
clojure.lang.ExceptionInfo: null #:clojure.error{:phase :print-eval-result}
at clojure.main$repl$read_eval_print__9068.invoke(main.clj:419)
clojure.lang.ExceptionInfo: Couldn't satisfy such-that predicate after 100 tries. {:pred #object[clojure.spec.alpha$gensub$fn__1876 0x71807ca2 "clojure.spec.alpha$gensub$fn__1876@71807ca2"], :gen #clojure.test.check.generators.Generator{:gen #object[clojure.test.check.generators$gen_pure$fn__2974 0x39e7d8ab "clojure.test.check.generators$gen_pure$fn__2974@39e7d8ab"]}, :max-tries 100}
At the very least, including the predicate form would be extremely helpful.e.g. (fn f1 [x] (metric-tags-valid? (s/unform ::base-metric x))) instead of #(metric-tags-valid? (s/unform ::base-metric %))
it might show up in stacktrace as something like clojure.spec.alpha$gensub$f1@71807ca2 instead of clojure.spec.alpha$gensub$fn__1876@71807ca2
Yeah I suppose I could do that. It'd be great if there was a tighter integration between spec and test.check so I don't need to do that.
clojure.spec.gen.alpha/gen
should have up to 3 args (http://clojure.github.io/test.check/clojure.test.check.generators.html#var-generate) when it only has one.