Closed
Description
Using 529e5d0.
Consider this snippet:
func FuzzFoo(f *testing.F) {
for _, td := range myTestdata {
f.Add(0, []byte(td))
}
f.Fuzz(func(t *testing.T, seed int64, b []byte) {
...
})
}
Currently, this crashes with:
panic: reflect: Call using int as type int64 [recovered]
panic: reflect: Call using int as type int64
goroutine 54 [running]:
testing.tRunner.func1.2(0x5fd600, 0xc00058e220)
testing/testing.go:1153 +0x34b
testing.tRunner.func1(0xc0000f8300)
testing/testing.go:1156 +0x4b6
panic(0x5fd600, 0xc00058e220)
runtime/panic.go:972 +0x1d4
reflect.Value.call(0x603a20, 0x653690, 0x13, 0x64222a, 0x4, 0xc001c9c240, 0x3, 0x4, 0x4, 0x30, ...)
reflect/value.go:409 +0x1917
reflect.Value.Call(0x603a20, 0x653690, 0x13, 0xc001c9c240, 0x3, 0x4, 0x2, 0x4, 0x786c00)
reflect/value.go:338 +0xb9
testing.(*F).Fuzz.func1.1(0xc0000f8300)
testing/fuzz.go:343 +0x225
testing.tRunner(0xc0000f8300, 0xc001c9c1e0)
testing/testing.go:1203 +0xef
created by testing.(*F).Fuzz.func1
testing/fuzz.go:338 +0x370
The cause of the crash is because testing.F.Add
is called with an int
, while the Fuzz function itself is expecting an int64
.
Either, the testing framework should:
- report an with a more clearer message about what's wrong, or
- automatically convert assignable values.
Also, with generics on the horizon, is there an API design that would guarantee type safety between testing.F.Add
and testing.F.Fuzz
? It's probably better to statically prevent type errors like than to have it occur at runtime.