...
1[!fuzz] skip
2[short] skip
3env GOCACHE=$WORK/cache
4
5# Cleanup should run after F.Skip.
6go test -run=FuzzTargetSkip
7stdout cleanup
8
9# Cleanup should run after F.Fatal.
10! go test -run=FuzzTargetFatal
11stdout cleanup
12
13# Cleanup should run after an unexpected runtime.Goexit.
14! go test -run=FuzzTargetGoexit
15stdout cleanup
16
17# Cleanup should run after panic.
18! go test -run=FuzzTargetPanic
19stdout cleanup
20
21# Cleanup should run in fuzz function on seed corpus.
22go test -v -run=FuzzFunction
23stdout '(?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 --
30module cleanup
31
32go 1.15
33-- cleanup_test.go --
34package cleanup
35
36import (
37 "runtime"
38 "testing"
39)
40
41func FuzzTargetSkip(f *testing.F) {
42 f.Cleanup(func() { f.Log("cleanup") })
43 f.Skip()
44}
45
46func FuzzTargetFatal(f *testing.F) {
47 f.Cleanup(func() { f.Log("cleanup") })
48 f.Fatal()
49}
50
51func FuzzTargetGoexit(f *testing.F) {
52 f.Cleanup(func() { f.Log("cleanup") })
53 runtime.Goexit()
54}
55
56func FuzzTargetPanic(f *testing.F) {
57 f.Cleanup(func() { f.Log("cleanup") })
58 panic("oh no")
59}
60
61func 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}
View as plain text