flyingmutant / rapid

Rapid is a modern Go property-based testing library
https://pkg.go.dev/pgregory.net/rapid
Mozilla Public License 2.0
588 stars 25 forks source link

`rapid.StateMachine(m *Model)` discards `m` #12

Closed fenollp closed 4 years ago

fenollp commented 4 years ago
func TestBla(t *testing.T) {
    rapid.Check(t, rapid.StateMachine(&Model{
        K: 1, // K is set
    }))
}

type Model struct {
    K int
}

func (m *Model) Init(t *rapid.T) {
    // Do something with K but...
    // K is zero
}

If this is documented then I missed it! (and sorry for the noise)

I understand cloning (shallow? deep?) that pre-Init *Model so it is available to every call of Init can be a pain. The determinism guarantees of that may not even be possible to uphold... it's just that it seemed very natural to use like this. Thoughts?

flyingmutant commented 4 years ago

Thanks for reporting! This is not documented right now (but should be, of course).

Cloning is not an option, unfortunately: it can't be done in a safe and portable way. Maybe StateMachine() should ensure that the pointer it gets is nil?

fenollp commented 4 years ago

Yes ensuring the given pointer is nil is a good idea IMO.