17 May 2012 15:01
Re: Re: testing/quick, help needed
Implementing the quick.Generator interface for MyInt, as described in the godoc for quick.Value(), seems to work: http://play.golang.org/p/MiVBYKw5wJ
That being said, I also have doubts whether the panic in your example is the intended behavior; returning false for "ok" would seem more sensible.
Hope that helps,
Peter
On Thu, May 17, 2012 at 10:16 AM, Dave Cheney <dave-7L4Cwp9BzA+sTnJN9+BGXg@public.gmane.org> wrote:
Hello,I hit a problem adding more test cases to a test that uses testing/quick. Here is a small example of the problem I hit. Is anyone able to offer any suggestions how I can use testing/quick when the structs contain derived types.% cat quicktest.gopackage mainimport ("math/rand""testing/quick""reflect")type Works struct {A intB stringC float64}type MyInt inttype Fails struct {A MyIntB stringC float64}var types = []interface{} {Works{},Fails{},}func main() {rand := rand.New(rand.NewSource(0))for _, iface := range types {ty := reflect.ValueOf(iface).Type()quick.Value(ty, rand)}}% go run quicktest.gopanic: reflect.Set: value of type int is not assignable to type main.MyIntgoroutine 1 [running]:reflect.Value.assignTo(0x63348, 0xedf354c3, 0x20, 0xa71a4, 0x6c6665720000000b, ...)/Users/dfc/go/src/pkg/reflect/value.go:1781 +0x41areflect.Value.Set(0x63528, 0x421544c0, 0x26, 0x63348, 0xedf354c3, ...)/Users/dfc/go/src/pkg/reflect/value.go:1197 +0xa2testing/quick.Value(0x42174000, 0x915c8, 0x42155220, 0x0, 0x0, ...)/Users/dfc/go/src/pkg/testing/quick/quick.go:137 +0x10e5main.main()/Users/dfc/devel/src/quicktest.go:32 +0x130goroutine 2 [syscall]:created by runtime.main/Users/dfc/go/src/pkg/runtime/proc.c:221exit status 2
RSS Feed