...

Text file src/cmd/go/testdata/script/test_fuzz_multiple.txt

Documentation: cmd/go/testdata/script

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

View as plain text