1 [!fuzz] skip
2 [short] skip
3
4 # Cleanup should run after F.Skip.
5 go test -run=FuzzTargetSkip
6 stdout cleanup
7
8 # Cleanup should run after F.Fatal.
9 ! go test -run=FuzzTargetFatal
10 stdout cleanup
11
12 # Cleanup should run after an unexpected runtime.Goexit.
13 ! go test -run=FuzzTargetGoexit
14 stdout cleanup
15
16 # Cleanup should run after panic.
17 ! go test -run=FuzzTargetPanic
18 stdout cleanup
19
20 # Cleanup should run in fuzz function on seed corpus.
21 go test -v -run=FuzzFunction
22 stdout '(?s)inner.*outer'
23
24 # TODO(jayconrod): test cleanup while fuzzing. For now, the worker process's
25 # stdout and stderr is connected to the coordinator's, but it should eventually
26 # be connected to os.DevNull, so we wouldn't see t.Log output.
27
28 -- go.mod --
29 module cleanup
30
31 go 1.15
32 -- cleanup_test.go --
33 package cleanup
34
35 import (
36 "runtime"
37 "testing"
38 )
39
40 func FuzzTargetSkip(f *testing.F) {
41 f.Cleanup(func() { f.Log("cleanup") })
42 f.Skip()
43 }
44
45 func FuzzTargetFatal(f *testing.F) {
46 f.Cleanup(func() { f.Log("cleanup") })
47 f.Fatal()
48 }
49
50 func FuzzTargetGoexit(f *testing.F) {
51 f.Cleanup(func() { f.Log("cleanup") })
52 runtime.Goexit()
53 }
54
55 func FuzzTargetPanic(f *testing.F) {
56 f.Cleanup(func() { f.Log("cleanup") })
57 panic("oh no")
58 }
59
60 func FuzzFunction(f *testing.F) {
61 f.Add([]byte{0})
62 f.Cleanup(func() { f.Log("outer") })
63 f.Fuzz(func(t *testing.T, b []byte) {
64 t.Cleanup(func() { t.Logf("inner") })
65 })
66 }
67
View as plain text