test-check

arohner 2020-05-11T12:56:55.059400Z

What’s the best way to test properties on a collection? I typically write

(prop/for-all [in generator] (let [ret (foo in)] (every? (fn [r] ...) ret))
, and this works, but the output on failure isn’t very nice, because test.check doesn’t know how to show the offending element

arohner 2020-05-11T12:57:59.060100Z

oh, one other wrinkle, the spec for each item is dynamic:

(every? (fn [m]
              (s/valid? (s/spec (::p/message-type m)) m)) msgs)

arohner 2020-05-11T12:58:34.060700Z

so I can’t easily use (s/valid? (s/coll-of ::foo) msgs)

2020-05-11T13:15:46.061100Z

> test.check doesn’t know how to show the offending element this can be remedied by returning a custom Result object

2020-05-11T13:16:14.061700Z

you could imagine a helper for this, a variant of every? , provided by a library or test.check itself

2020-05-11T13:16:24.062Z

but the plumbing is there for getting better output