| 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 |
env GOCACHE=$WORK/cache |
| 8 |
|
| 9 |
# With fuzzing disabled, multiple targets can be tested. |
| 10 |
go test ./... |
| 11 |
|
| 12 |
# With fuzzing enabled, at most one package may be tested, |
| 13 |
# even if only one package contains fuzz targets. |
| 14 |
! go test -fuzz=. ./... |
| 15 |
stderr '^cannot use -fuzz flag with multiple packages$' |
| 16 |
! go test -fuzz=. ./zero ./one |
| 17 |
stderr '^cannot use -fuzz flag with multiple packages$' |
| 18 |
go test -fuzz=. -fuzztime=1x ./one |
| 19 |
|
| 20 |
# With fuzzing enabled, at most one target in the same package may match. |
| 21 |
! go test -fuzz=. ./two |
| 22 |
stdout '^testing: will not fuzz, -fuzz matches more than one fuzz test: \[FuzzOne FuzzTwo\]$' |
| 23 |
go test -fuzz=FuzzTwo -fuzztime=1x ./two |
| 24 |
|
| 25 |
-- go.mod -- |
| 26 |
module fuzz |
| 27 |
|
| 28 |
go 1.18 |
| 29 |
-- zero/zero.go -- |
| 30 |
package zero |
| 31 |
-- one/one_test.go -- |
| 32 |
package one |
| 33 |
|
| 34 |
import "testing" |
| 35 |
|
| 36 |
func FuzzOne(f *testing.F) { |
| 37 |
f.Fuzz(func(*testing.T, []byte) {}) |
| 38 |
} |
| 39 |
-- two/two_test.go -- |
| 40 |
package two |
| 41 |
|
| 42 |
import "testing" |
| 43 |
|
| 44 |
func FuzzOne(f *testing.F) { |
| 45 |
f.Fuzz(func(*testing.T, []byte) {}) |
| 46 |
} |
| 47 |
|
| 48 |
func FuzzTwo(f *testing.F) { |
| 49 |
f.Fuzz(func(*testing.T, []byte) {}) |
| 50 |
} |