stdout ok
! stdout FAIL
+# Test that calling f.Fatal while fuzzing causes a non-zero exit status.
+! go test -fuzz Fuzz fail_fuzz_test.go
+! stdout ^ok
+stdout FAIL
+
+# Test that successful fuzzing exits cleanly.
+go test -fuzz Fuzz success_fuzz_test.go
+stdout ok
+! stdout FAIL
+
[short] stop
# Test that calling panic(nil) in a fuzz target causes a non-zero exit status.
context: f.context,
}
if innerF.chatty != nil {
- if f.fuzz {
- innerF.chatty.Updatef(name, "--- FUZZ: %s\n", name)
- } else {
- innerF.chatty.Updatef(name, "=== RUN %s\n", name)
- }
+ innerF.chatty.Updatef(name, "=== RUN %s\n", name)
}
- go runTarget(innerF, fn)
+ go innerF.runTarget(fn)
<-innerF.signal
return innerF.ran, !innerF.failed
}
// runTarget runs the given target, handling panics and exits
// within the test, and reporting errors.
-func runTarget(f *F, fn func(f *F)) {
+func (f *F) runTarget(fn func(f *F)) {
defer func() {
err := recover()
// If the function has recovered but the test hasn't finished,
}
f := &F{
common: common{
- w: os.Stdout,
+ signal: make(chan bool),
+ w: os.Stdout,
},
context: ctx,
fuzz: true,
}
if Verbose() {
f.chatty = newChattyPrinter(f.w)
+ f.chatty.Updatef(f.name, "--- FUZZ: %s\n", f.name)
}
- return f.run(ft.Name, ft.Fn)
+ go f.runTarget(ft.Fn)
+ <-f.signal
+ return f.ran, !f.failed
}
// Fuzz runs a single fuzz target. It is useful for creating