From f5d0fa82af1dbb752bb256f0761ec3f50f58db8f Mon Sep 17 00:00:00 2001 From: Katie Hockman Date: Mon, 19 Oct 2020 11:04:37 -0400 Subject: [PATCH] [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 Run-TryBot: Katie Hockman TryBot-Result: Go Bot Reviewed-by: Jay Conrod --- src/testing/fuzz.go | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/src/testing/fuzz.go b/src/testing/fuzz.go index ff13e0b4e0..ce66000a3a 100644 --- a/src/testing/fuzz.go +++ b/src/testing/fuzz.go @@ -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 -} -- 2.48.1