diff options
| author | apocelipes <seve3r@outlook.com> | 2025-09-17 09:47:20 +0000 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2025-09-17 08:48:07 -0700 |
| commit | 3db5979e8cc4cc86c4fefb4cecc5a2041b32404d (patch) | |
| tree | a81d2b04af5cea20015d6329e1953423ee68e592 /src/testing/fuzz.go | |
| parent | 6a8dbbecbfc32650841e737271384ffaba433292 (diff) | |
| download | go-3db5979e8cc4cc86c4fefb4cecc5a2041b32404d.tar.xz | |
testing: use reflect.TypeAssert and reflect.TypeFor
To simplify the code.
Updates #62121
Updates #60088
Change-Id: I1cef27b19961721b89a965c708320072a052d9af
GitHub-Last-Rev: ffd07a74da87b84b457246b2c94d4ee7540c8e8b
GitHub-Pull-Request: golang/go#75494
Reviewed-on: https://go-review.googlesource.com/c/go/+/704575
Reviewed-by: Alan Donovan <adonovan@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/testing/fuzz.go')
| -rw-r--r-- | src/testing/fuzz.go | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/src/testing/fuzz.go b/src/testing/fuzz.go index c07d6a0604..5867935b81 100644 --- a/src/testing/fuzz.go +++ b/src/testing/fuzz.go @@ -163,23 +163,23 @@ func (f *F) Add(args ...any) { // supportedTypes represents all of the supported types which can be fuzzed. var supportedTypes = map[reflect.Type]bool{ - reflect.TypeOf(([]byte)("")): true, - reflect.TypeOf((string)("")): true, - reflect.TypeOf((bool)(false)): true, - reflect.TypeOf((byte)(0)): true, - reflect.TypeOf((rune)(0)): true, - reflect.TypeOf((float32)(0)): true, - reflect.TypeOf((float64)(0)): true, - reflect.TypeOf((int)(0)): true, - reflect.TypeOf((int8)(0)): true, - reflect.TypeOf((int16)(0)): true, - reflect.TypeOf((int32)(0)): true, - reflect.TypeOf((int64)(0)): true, - reflect.TypeOf((uint)(0)): true, - reflect.TypeOf((uint8)(0)): true, - reflect.TypeOf((uint16)(0)): true, - reflect.TypeOf((uint32)(0)): true, - reflect.TypeOf((uint64)(0)): true, + reflect.TypeFor[[]byte](): true, + reflect.TypeFor[string](): true, + reflect.TypeFor[bool](): true, + reflect.TypeFor[byte](): true, + reflect.TypeFor[rune](): true, + reflect.TypeFor[float32](): true, + reflect.TypeFor[float64](): true, + reflect.TypeFor[int](): true, + reflect.TypeFor[int8](): true, + reflect.TypeFor[int16](): true, + reflect.TypeFor[int32](): true, + reflect.TypeFor[int64](): true, + reflect.TypeFor[uint](): true, + reflect.TypeFor[uint8](): true, + reflect.TypeFor[uint16](): true, + reflect.TypeFor[uint32](): true, + reflect.TypeFor[uint64](): true, } // Fuzz runs the fuzz function, ff, for fuzz testing. If ff fails for a set of @@ -224,7 +224,7 @@ func (f *F) Fuzz(ff any) { if fnType.Kind() != reflect.Func { panic("testing: F.Fuzz must receive a function") } - if fnType.NumIn() < 2 || fnType.In(0) != reflect.TypeOf((*T)(nil)) { + if fnType.NumIn() < 2 || fnType.In(0) != reflect.TypeFor[*T]() { panic("testing: fuzz target must receive at least two arguments, where the first argument is a *T") } if fnType.NumOut() != 0 { |
