stdout 'testdata[/\\]corpus[/\\]FuzzWithFail[/\\]'
go run check_testdata.go FuzzWithFail
+! go test -run=FuzzWithLogFail -fuzz=FuzzWithLogFail -fuzztime=5s
+stdout 'testdata[/\\]corpus[/\\]FuzzWithLogFail[/\\]'
+stdout 'logged something'
+go run check_testdata.go FuzzWithLogFail
+
! go test -run=FuzzWithErrorf -fuzz=FuzzWithErrorf -fuzztime=5s
stdout 'testdata[/\\]corpus[/\\]FuzzWithErrorf[/\\]'
-# TODO: Uncomment this part of the test once it's fixed
-# stdout 'errorf was called here'
+stdout 'errorf was called here'
go run check_testdata.go FuzzWithErrorf
! go test -run=FuzzWithFatalf -fuzz=FuzzWithFatalf -fuzztime=5s
stdout 'testdata[/\\]corpus[/\\]FuzzWithFatalf[/\\]'
-# TODO: Uncomment this part of the test once it's fixed
-# stdout 'fatalf was called here'
+stdout 'fatalf was called here'
go run check_testdata.go FuzzWithFatalf
! go test -run=FuzzWithBadExit -fuzz=FuzzWithBadExit -fuzztime=5s
})
}
+func FuzzWithLogFail(f *testing.F) {
+ f.Add([]byte("aa"))
+ f.Fuzz(func(t *testing.T, b []byte) {
+ if string(b) != "aa" {
+ t.Log("logged something")
+ t.Fail()
+ }
+ })
+}
+
func FuzzWithErrorf(f *testing.F) {
f.Add([]byte("aa"))
f.Fuzz(func(t *testing.T, b []byte) {
// first called order.
func (f *F) Cleanup(fn func()) {
if f.inFuzzFn {
- panic("testing: f.Cleanup was called inside the f.Fuzz function")
+ panic("testing: f.Cleanup was called inside the f.Fuzz function, use t.Cleanup instead")
}
f.common.Helper()
f.common.Cleanup(fn)
// Error is equivalent to Log followed by Fail.
func (f *F) Error(args ...interface{}) {
if f.inFuzzFn {
- panic("testing: f.Error was called inside the f.Fuzz function")
+ panic("testing: f.Error was called inside the f.Fuzz function, use t.Error instead")
}
f.common.Helper()
f.common.Error(args...)
// Errorf is equivalent to Logf followed by Fail.
func (f *F) Errorf(format string, args ...interface{}) {
if f.inFuzzFn {
- panic("testing: f.Errorf was called inside the f.Fuzz function")
+ panic("testing: f.Errorf was called inside the f.Fuzz function, use t.Errorf instead")
}
f.common.Helper()
f.common.Errorf(format, args...)
// Fail marks the function as having failed but continues execution.
func (f *F) Fail() {
if f.inFuzzFn {
- panic("testing: f.Fail was called inside the f.Fuzz function")
+ panic("testing: f.Fail was called inside the f.Fuzz function, use t.Fail instead")
}
f.common.Helper()
f.common.Fail()
// those other goroutines.
func (f *F) FailNow() {
if f.inFuzzFn {
- panic("testing: f.FailNow was called inside the f.Fuzz function")
+ panic("testing: f.FailNow was called inside the f.Fuzz function, use t.FailNow instead")
}
f.common.Helper()
f.common.FailNow()
// Fatal is equivalent to Log followed by FailNow.
func (f *F) Fatal(args ...interface{}) {
if f.inFuzzFn {
- panic("testing: f.Fatal was called inside the f.Fuzz function")
+ panic("testing: f.Fatal was called inside the f.Fuzz function, use t.Fatal instead")
}
f.common.Helper()
f.common.Fatal(args...)
// Fatalf is equivalent to Logf followed by FailNow.
func (f *F) Fatalf(format string, args ...interface{}) {
if f.inFuzzFn {
- panic("testing: f.Fatalf was called inside the f.Fuzz function")
+ panic("testing: f.Fatalf was called inside the f.Fuzz function, use t.Fatalf instead")
}
f.common.Helper()
f.common.Fatalf(format, args...)
// Helper may be called simultaneously from multiple goroutines.
func (f *F) Helper() {
if f.inFuzzFn {
- panic("testing: f.Helper was called inside the f.Fuzz function")
+ panic("testing: f.Helper was called inside the f.Fuzz function, use t.Helper instead")
}
// common.Helper is inlined here.
// Skip is equivalent to Log followed by SkipNow.
func (f *F) Skip(args ...interface{}) {
if f.inFuzzFn {
- panic("testing: f.Skip was called inside the f.Fuzz function")
+ panic("testing: f.Skip was called inside the f.Fuzz function, use t.Skip instead")
}
f.common.Helper()
f.common.Skip(args...)
// those other goroutines.
func (f *F) SkipNow() {
if f.inFuzzFn {
- panic("testing: f.SkipNow was called inside the f.Fuzz function")
+ panic("testing: f.SkipNow was called inside the f.Fuzz function, use t.SkipNow instead")
}
f.common.Helper()
f.common.SkipNow()
// Skipf is equivalent to Logf followed by SkipNow.
func (f *F) Skipf(format string, args ...interface{}) {
if f.inFuzzFn {
- panic("testing: f.Skipf was called inside the f.Fuzz function")
+ panic("testing: f.Skipf was called inside the f.Fuzz function, use t.Skipf instead")
}
f.common.Helper()
f.common.Skipf(format, args...)
// if the directory creation fails, TempDir terminates the test by calling Fatal.
func (f *F) TempDir() string {
if f.inFuzzFn {
- panic("testing: f.TempDir was called inside the f.Fuzz function")
+ panic("testing: f.TempDir was called inside the f.Fuzz function, use t.TempDir instead")
}
f.common.Helper()
return f.common.TempDir()
//
// TODO(jayconrod,katiehockman): dedupe testdata corpus with entries from f.Add
// TODO(jayconrod,katiehockman): handle T.Parallel calls within fuzz function.
+ // TODO(jayconrod,katiehockman): improve output when running the subtest.
+ // e.g. instead of
+ // --- FAIL: FuzzSomethingError/#00 (0.00s)
+ // do
+ // --- FAIL: FuzzSomethingError/<hash> (0.00s)
run := func(e corpusEntry) error {
if e.Values == nil {
// Every code path should have already unmarshaled Data into Values.
<-t.signal
f.inFuzzFn = false
if t.Failed() {
- return errors.New(string(t.output))
+ return errors.New(string(f.output))
}
return nil
}
err := f.fuzzContext.coordinateFuzzing(*fuzzDuration, *parallel, f.corpus, types, corpusTargetDir, cacheTargetDir)
if err != nil {
f.result = FuzzResult{Error: err}
- f.Error(err)
+ f.Fail()
+ fmt.Fprintf(f.w, "%v", err)
if crashErr, ok := err.(fuzzCrashError); ok {
crashName := crashErr.CrashName()
- f.Logf("Crash written to %s", filepath.Join("testdata/corpus", f.name, crashName))
- f.Logf("To re-run:\ngo test %s -run=%s/%s", f.fuzzContext.importPath(), f.name, crashName)
+ fmt.Fprintf(f.w, "Crash written to %s\n", filepath.Join("testdata/corpus", f.name, crashName))
+ fmt.Fprintf(f.w, "To re-run:\ngo test %s -run=%s/%s\n", f.fuzzContext.importPath(), f.name, crashName)
}
}
// TODO(jayconrod,katiehockman): Aggregate statistics across workers
}
default:
- // Fuzzing is not enabled. Only run the seed corpus.
+ // Fuzzing is not enabled, or will be done later. Only run the seed
+ // corpus now.
for _, e := range f.corpus {
run(e)
}
// If fuzzing is disabled (-test.fuzz is not set), runFuzzing
// returns immediately.
func runFuzzing(deps testDeps, fuzzTargets []InternalFuzzTarget) (ran, ok bool) {
+ // TODO(katiehockman,jayconrod): Should we do something special to make sure
+ // we don't print f.Log statements again with runFuzzing, since we already
+ // would have printed them when we ran runFuzzTargets (ie. seed corpus run)?
if len(fuzzTargets) == 0 || *matchFuzz == "" {
return false, true
}