Fork me on GitHub
#clojure-spec
<
2017-01-28
>
adambros00:01:26

@alexmiller getting weird behavior when trying to conform this:

(s/def ::thing (s/cat
                 :a (s/? string?)
                 :b (s/+ number?)))
(s/def ::seq-of (s/+ ::thing))

(s/conform ::seq-of '(”foo” 1 “bar” 2 3 “qux” 4))
;=> [{:a "foo", :b [1]} [{:a "bar", :b [2 3]} {:a "qux", :b [4]}]]

;expected
;=> [{:a "foo", :b [1]} {:a "bar", :b [2 3]} {:a "qux", :b [4]}]

;; ONLY 2nd thing matters?
(s/conform ::seq-of '(”foo” 1 2 “ bar 3))
;=> [{:a "foo", :b [1 2]} {:a "bar", :b [2]}]

;; NO OPTIONAL
(s/def ::thing (s/cat
                 :a string?
                 :b (s/+ number?)))
(s/def ::seq-of (s/+ ::thing))

(s/conform ::seq-of '(”foo” 1 “bar” 2 3 “qux” 4))
;=> [{:a "foo", :b [1]} {:a "bar", :b [2 3]} {:a "qux", :b [4]}]
This also only shows up if there are 2+ numbers in the 2nd or later ::thing AND the problem goes away if I make :a not optional… is this at all related to http://dev.clojure.org/jira/browse/CLJ-2003 ?

ag00:01:20

is it possible to “redef” the spec? if I have a spec that depends on other spec and that one uses a function as a predicate and I want to predicate to be something else in the test

hiredman00:01:35

@adambros that looks like what phil brown mentions in the comment on that, but alex says it isn't actually related to that issue and he should open a new issue for it

hiredman00:01:40

a cons somewhere there should be a concat

Alex Miller (Clojure team)00:01:52

@adambros not sure if that’s the same or not, feel free to log

nblumoe09:01:46

I ran into some issues with spec.test/check not terminating when using a coll-of spec with :kind:

(s/def ::bar (s/coll-of number? :kind vector?))

(defn foo [a]
  (reduce + 0 a))

(s/fdef foo
  :args (s/cat :a ::bar)
  :ret number?)

(first (stest/check `foo))
The last call does not terminate, just keeps heating my CPU. When removing the :kind vector? constraint from the spec ::bar everything works fine. With :kind list? I also get the erroneous behaviour.

nblumoe09:01:34

Wondering If I am doing something wrong, if this is a bug and if it was filed on Jira already

schmee09:01:16

nblumoe try adding :gen-max 3 to the ::bar definition

schmee09:01:45

it could be that it is generating some crazy big collections

nblumoe09:01:40

thanks, but still the same issue

leongrapenthin23:01:05

@nblumoe If you don't provide :into [] to s/coll-of spec will generate a vector every time just to call empty on it to then generate the stuff into it. Apparently these "generated constructor vectors" explode and you can't control their sizing. So you have to provide :into. @alexmiller Is this intended or ticketworthy?

gfredericks23:01:27

sounds like a ticket to me

Alex Miller (Clojure team)23:01:04

Not sure I understand all that without looking at the code but doesn't sound right