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