Fork me on GitHub
#test-check
<
2016-12-18
>
nberger12:12:49

Uploaded an alternative patch to http://dev.clojure.org/jira/browse/TCHECK-126 (Refactor c.t.c/quick-check as a state machine to provide more extension points). The new patch refactors c.t.c/quick-check "in-place", instead of introducing a separate namespace like in the old patch. Most important change is that it replaces the reporter-fn with a step-fn which allows feeding back the quick-check loop to drive/augment it by returning a modified quick-check state (for example, adding a timestamp, or dynamically changing the number of tests left). reporter-fn was for side-effects only, step-fn allows to do the side-effects AND modify the qc state. I understand this is not a breaking change because the reporter-fn has not been part of a release yet AFAIK

gfredericks12:12:44

so step-fn is part of the public API then?

nberger12:12:06

yes, through the new step-fn option that replaces reporter-fn. There's also a c.t.c.clojure-test/default-step-fn now

gfredericks12:12:40

I'd want to be sure that creating a well-behaved and useful step-fn isn't more difficult than a reporter-fn

nberger12:12:17

yeah, that's a risk... we could check for nil, but not sure if much more than that... maybe check that we get a map with certain keys back? But I don't know, passing a step-fn is a bit of "advanced usage", and reading a little bit about it or seeing an example is not such a big expectation, maybe... Here's an example of a step-fn: https://github.com/clojure/test.check/compare/master...nberger:test.check2-reporter-fn#diff-5eb045ad9cf20dd057f8344a877abd89R985

nberger12:12:41

perhaps we could provide some specs for the step-fn...

nberger13:12:59

another option is to keep separate functions for the side-effecty part (`reporter-fn`) and the modify-qc-state part (`step-fn`? will need help with the names 😄 )

nberger13:12:30

but I don't know... maybe that's more appropriate for a layer over this (a step-fn that composes a reporter-fn and a change-qc-state-fn or whatever)

gfredericks13:12:33

what uses do you imagine a user having for a step-fn that aren't possible with reporter-fn?

nberger13:12:35

1. implementing the stats feature 2. add timestamps at different stages of the quick-check test 3. dynamically change for how long the test should run (by changing the num-tests key, or by introducing a new abort? key in the future) 4. bound tests and shrinks in time (maybe this goes under the previous item, but it's a long-standing request in TCHECK-8 and this way it could be implemented as an extension)

nberger13:12:43

and others that users will come up with 🙂. Another benefit IMO is that it the qc state has the same shape at all stages of the quick-check run (except for added keys during shrink that don't make sense before it starts, for example), so it should make it marginally easier for say an editor to integrate with this to provide live status of the test.check progress

nberger13:12:41

Not sure if it gives any benefit for clojure.spec, that's something to be explored...

nberger13:12:53

Another benefit: the periodic reporter could be re implemented to not use a global atom quite easily

gfredericks23:12:18

I keep wondering if a rewrite of the generators namespace could result in a more coherent notion of size; it seems hard to come up with one

gfredericks23:12:22

an initial thought is that sizing generators could be easier to understand if they tried to interpret size as a suggested value for (comp count pr-str)

gfredericks23:12:45

or a suggested maximum value

gfredericks23:12:12

but there are lots of cases where that's not a useful default, so users would have to be more involved with sizing to get what they want

gfredericks23:12:46

and it would also be hard to pull off, especially for combining collection generators with custom generators using gen/bind

gfredericks23:12:09

it'd be useful to know how well the other quickchecks do at this

gfredericks23:12:59

I don't like that clojure.spec needed to do some weird depth-tracking thing