aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/testdata/script/test_fuzz_cache.txt
blob: 10e4c2926f44073d04f7b9e685bc2c5e06325468 (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# TODO(jayconrod): support shared memory on more platforms.
[!darwin] [!linux] [!windows] skip

[short] skip
env GOCACHE=$WORK/cache

# Fuzz cache should not exist after a regular test run.
go test .
exists $GOCACHE
! exists $GOCACHE/fuzz

# Fuzzing should write interesting values to the cache.
go test -fuzz=FuzzY -fuzztime=100x .
go run ./contains_files $GOCACHE/fuzz/example.com/y/FuzzY

# 'go clean -cache' should not delete the fuzz cache.
go clean -cache
exists $GOCACHE/fuzz

# 'go clean -fuzzcache' should delete the fuzz cache but not the build cache.
go list -f {{.Stale}} ./empty
stdout true
go install ./empty
go list -f {{.Stale}} ./empty
stdout false
go clean -fuzzcache
! exists $GOCACHE/fuzz
go list -f {{.Stale}} ./empty
stdout false

-- go.mod --
module example.com/y

go 1.16
-- y_test.go --
package y

import (
	"io"
	"testing"
)

func FuzzY(f *testing.F) {
	f.Add([]byte("y"))
	f.Fuzz(func(t *testing.T, b []byte) { Y(io.Discard, b) })
}
-- y.go --
package y

import (
	"bytes"
	"io"
)

func Y(w io.Writer, b []byte) {
	if !bytes.Equal(b, []byte("y")) {
		w.Write([]byte("not equal"))
	}
}
-- empty/empty.go --
package empty
-- contains_files/contains_files.go --
package main

import (
	"fmt"
	"path/filepath"
	"io/ioutil"
	"os"
)

func main() {
	infos, err := ioutil.ReadDir(filepath.Clean(os.Args[1]))
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
	if len(infos) == 0 {
		os.Exit(1)
	}
}