1
0
mirror of https://github.com/golang/go synced 2024-11-24 06:50:17 -07:00

internal/fuzz: improve error for mismatched types

Fixes #48635

Change-Id: Ia3cde119d5eb31bc771fe3a39acb2372dbd988ff
Reviewed-on: https://go-review.googlesource.com/c/go/+/361114
Trust: Katie Hockman <katie@golang.org>
Trust: Daniel Martí <mvdan@mvdan.cc>
Run-TryBot: Katie Hockman <katie@golang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
This commit is contained in:
Katie Hockman 2021-11-03 10:58:59 -04:00
parent 5f0e5d21bb
commit e0e6e4d23f
2 changed files with 10 additions and 5 deletions

View File

@ -152,6 +152,7 @@ stdout FAIL
# Test that the wrong type given with f.Add will fail.
! go test -run FuzzWrongType fuzz_add_test.go
! stdout ^ok
stdout '\[string int\], want \[\[\]uint8 int8\]'
stdout FAIL
# Test fatal with testdata seed corpus
@ -435,8 +436,8 @@ func FuzzAddDifferentType(f *testing.F) {
}
func FuzzWrongType(f *testing.F) {
f.Add("hello")
f.Fuzz(func(*testing.T, []byte) {})
f.Add("hello", 50)
f.Fuzz(func(*testing.T, []byte, int8) {})
}
-- corpustesting/fuzz_testdata_corpus_test.go --

View File

@ -997,11 +997,15 @@ func readCorpusData(data []byte, types []reflect.Type) ([]interface{}, error) {
// provided.
func CheckCorpus(vals []interface{}, types []reflect.Type) error {
if len(vals) != len(types) {
return fmt.Errorf("wrong number of values in corpus entry %v: want %v", vals, types)
return fmt.Errorf("wrong number of values in corpus entry: %d, want %d", len(vals), len(types))
}
valsT := make([]reflect.Type, len(vals))
for valsI, v := range vals {
valsT[valsI] = reflect.TypeOf(v)
}
for i := range types {
if reflect.TypeOf(vals[i]) != types[i] {
return fmt.Errorf("mismatched types in corpus entry: %v, want %v", vals, types)
if valsT[i] != types[i] {
return fmt.Errorf("mismatched types in corpus entry: %v, want %v", valsT, types)
}
}
return nil