aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/testdata/script/test_fuzz_cleanup.txt
blob: 88625916bab97b25a9fe2471fd11942a48ad8ea9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# TODO(jayconrod): support shared memory on more platforms.
[!darwin] [!linux] [!windows] skip
[short] skip

# Cleanup should run after F.Skip.
go test -run=FuzzTargetSkip
stdout cleanup

# Cleanup should run after F.Fatal.
! go test -run=FuzzTargetFatal
stdout cleanup

# Cleanup should run after an unexpected runtime.Goexit.
! go test -run=FuzzTargetGoexit
stdout cleanup

# Cleanup should run after panic.
! go test -run=FuzzTargetPanic
stdout cleanup

# Cleanup should run in fuzz function on seed corpus.
go test -v -run=FuzzFunction
stdout '(?s)inner.*outer'

# TODO(jayconrod): test cleanup while fuzzing. For now, the worker process's
# stdout and stderr is connected to the coordinator's, but it should eventually
# be connected to os.DevNull, so we wouldn't see t.Log output.

-- go.mod --
module cleanup

go 1.15
-- cleanup_test.go --
package cleanup

import (
	"runtime"
	"testing"
)

func FuzzTargetSkip(f *testing.F) {
	f.Cleanup(func() { f.Log("cleanup") })
	f.Skip()
}

func FuzzTargetFatal(f *testing.F) {
	f.Cleanup(func() { f.Log("cleanup") })
	f.Fatal()
}

func FuzzTargetGoexit(f *testing.F) {
	f.Cleanup(func() { f.Log("cleanup") })
	runtime.Goexit()
}

func FuzzTargetPanic(f *testing.F) {
	f.Cleanup(func() { f.Log("cleanup") })
	panic("oh no")
}

func FuzzFunction(f *testing.F) {
	f.Add([]byte{0})
	f.Cleanup(func() { f.Log("outer") })
	f.Fuzz(func(t *testing.T, b []byte) {
		t.Cleanup(func() { t.Logf("inner") })
	})
}