1 # This test checks that 'go test' prints a reasonable error when fuzzing is
2 # enabled, and multiple package or multiple fuzz targets match.
3 # TODO(#46312): support fuzzing multiple targets in multiple packages.
4
5 [!fuzz] skip
6 [short] skip
7
8 # With fuzzing disabled, multiple targets can be tested.
9 go test ./...
10
11 # With fuzzing enabled, at most one package may be tested,
12 # even if only one package contains fuzz targets.
13 ! go test -fuzz=. ./...
14 stderr '^cannot use -fuzz flag with multiple packages$'
15 ! go test -fuzz=. ./zero ./one
16 stderr '^cannot use -fuzz flag with multiple packages$'
17 go test -fuzz=. -fuzztime=1x ./one
18
19 # With fuzzing enabled, at most one target in the same package may match.
20 ! go test -fuzz=. ./two
21 stdout '^testing: will not fuzz, -fuzz matches more than one fuzz test: \[FuzzOne FuzzTwo\]$'
22 go test -fuzz=FuzzTwo -fuzztime=1x ./two
23
24 -- go.mod --
25 module fuzz
26
27 go 1.18
28 -- zero/zero.go --
29 package zero
30 -- one/one_test.go --
31 package one
32
33 import "testing"
34
35 func FuzzOne(f *testing.F) {
36 f.Fuzz(func(*testing.T, []byte) {})
37 }
38 -- two/two_test.go --
39 package two
40
41 import "testing"
42
43 func FuzzOne(f *testing.F) {
44 f.Fuzz(func(*testing.T, []byte) {})
45 }
46
47 func FuzzTwo(f *testing.F) {
48 f.Fuzz(func(*testing.T, []byte) {})
49 }
50
View as plain text