Welcome! Please see the About page for a little more info on how this works.

0 votes
in Clojure by
*Problem*:

A generator in a {{keys*}} spec not overridable.

*Repro*:


(require '[clojure.spec.alpha :as s])
(require '[clojure.spec.gen.alpha :as gen])
(s/def ::foo (s/keys* :req-un [::a ::b]))
(s/def ::a number?)
(s/def ::b number?)
(s/valid? ::foo [:a 1 :b 2]) ;; true
(gen/generate (s/gen ::foo {::a (fn [] (gen/return 1))})) ;;=> (:a -15164 :b 24.0)


The last expression should return a sequence where the key {{:a}} is followed by {{1}} like: {{(:a 1 :b 24.0)}}.

This may be traced back to a more general problem: overriding the generator on a spec that's made with {{with-gen}} seems to have no effect:


(gen/generate
   (s/gen (s/with-gen ::foo
            (fn []
              (s/gen (s/cat :key-a #{:a} :val-a ::a :key-b #{:b} :val-b ::b))))
          {::a (fn [] (gen/return 1))})) ;;=> (:a -1 :b "OXi2")

1 Answer

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJ-2483 (reported by borkdude)
...