flyingmutant / rapid

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

Accept interfaces instead of concrete *testing.T #50

Closed mirandaconrado closed 1 year ago

mirandaconrado commented 1 year ago

I've noticed that the concrete type *testing.T is used as argument in many places, like rapid.Check. But in the implementation, it almost immediately calls checkTB which converts it to the interface tb, which is a mirror of TB.

We would like to be able to pass a rapid.TB instead of *testing.T so that we can wrap the testing structure with additional information and behavior. Would you be opposed to changing the signature of the functions to accept rapid.TB instead of *testing.T? I believe this would be a transparent change to the user given that *testing.T satisfies rapid.TB. We'd be willing to do the work if approved.

flyingmutant commented 1 year ago

The proposal sounds logical, but I am a bit vary of making the Check signature less obvious. What additional information/behavior do you want to attach?

worr commented 1 year ago

One big benefit of doing this is that it allows rapid to be more easily used when using a framework like ginkgo. The easiest way to do this in Ginkgo is to use GinkgoT() to get a struct that isn't exactly a *testing.T, but implements all of the methods (and some extras) of *testing.T.

See: https://onsi.github.io/ginkgo/#third-party-integrations https://pkg.go.dev/github.com/onsi/ginkgo/v2#GinkgoT

flyingmutant commented 1 year ago

Does f4756c7c719173865211e7a6e92ec0e8ce78366c look like a proper fix, or is anything still missing?

worr commented 1 year ago

Just checked it out on a test project, and this solution works perfectly (at least for my purposes using it with Ginkgo). Thanks a ton.

conradoverta commented 1 year ago

Awesome, thanks!