[dev.fuzz] testing: cleanup a few small things

Deletes the exported testing.Fuzz function
which would run a standalone fuzz target.
Similar to RunFuzzing and RunFuzzTargets,
which were previously removed, this will
likely be too complex to support.

Moves the deferred Exit in f.Fuzz higher up
the function so it is always run.

Change-Id: I9ea6210dc30dee8c2a943bfb8077225c369cfb95
Reviewed-on: https://go-review.googlesource.com/c/go/+/263642
Trust: Katie Hockman <katie@golang.org>
Run-TryBot: Katie Hockman <katie@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
This commit is contained in:
Katie Hockman 2020-10-19 11:04:37 -04:00 committed by Filippo Valsorda
parent 9f3aa113a9
commit f5d0fa82af
1 changed files with 2 additions and 18 deletions

View File

@ -79,6 +79,8 @@ func (f *F) Add(args ...interface{}) {
// target by calling runtime.Goexit. To run any code after this function, use
// Cleanup.
func (f *F) Fuzz(ff interface{}) {
defer runtime.Goexit() // exit after this function
fn, ok := ff.(func(*T, []byte))
if !ok {
panic("testing: Fuzz function must have type func(*testing.T, []byte)")
@ -92,8 +94,6 @@ func (f *F) Fuzz(ff interface{}) {
f.corpus = append(f.corpus, bytesToCorpus(c)...)
// TODO(jayconrod,katiehockman): dedupe testdata corpus with entries from f.Add
defer runtime.Goexit() // exit after this function
var errStr string
run := func(t *T, b []byte) {
defer func() {
@ -364,19 +364,3 @@ func runFuzzing(deps testDeps, fuzzTargets []InternalFuzzTarget) (ran, ok bool)
<-f.signal
return f.ran, !f.failed
}
// Fuzz runs a single fuzz target. It is useful for creating
// custom fuzz targets that do not use the "go test" command.
//
// If fn depends on testing flags, then Init must be used to register
// those flags before calling Fuzz and before calling flag.Parse.
func Fuzz(fn func(f *F)) FuzzResult {
f := &F{
common: common{
w: discard{},
},
fuzzFunc: fn,
}
// TODO(katiehockman): run the test
return f.result
}