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

     1  # This test demonstrates the fuzz corpus behavior for packages outside of the main module.
     2  # (See https://golang.org/issue/48495.)
     3  
     4  [short] skip
     5  
     6  # Set -modcacherw so that the test behaves the same regardless of whether the
     7  # module cache is writable. (For example, on some platforms it can always be
     8  # written if the user is running as root.) At one point, a failing fuzz test
     9  # in a writable module cache would corrupt module checksums in the cache.
    10  env GOFLAGS=-modcacherw
    11  
    12  
    13  # When the upstream module has no test corpus, running 'go test' should succeed,
    14  # but 'go test -fuzz=.' should error out before running the test.
    15  # (It should NOT corrupt the module cache by writing out new fuzz inputs,
    16  # even if the cache is writable.)
    17  
    18  go get -t example.com/fuzzfail@v0.1.0
    19  go test example.com/fuzzfail
    20  
    21  ! go test -fuzz=. example.com/fuzzfail
    22  ! stdout .
    23  stderr '^cannot use -fuzz flag on package outside the main module$'
    24  
    25  go mod verify
    26  
    27  
    28  # If the module does include a test corpus, 'go test' (without '-fuzz') should
    29  # load that corpus and run the fuzz tests against it, but 'go test -fuzz=.'
    30  # should continue to be rejected.
    31  
    32  go get -t example.com/fuzzfail@v0.2.0
    33  
    34  ! go test example.com/fuzzfail
    35  stdout '^\s*fuzzfail_test\.go:7: oops:'
    36  
    37  ! go test -fuzz=. example.com/fuzzfail
    38  ! stdout .
    39  stderr '^cannot use -fuzz flag on package outside the main module$'
    40  
    41  go mod verify
    42  
    43  
    44  # Packages in 'std' cannot be fuzzed when the corresponding GOROOT module is not
    45  # the main module — either the failures would not be recorded or the behavior of
    46  # the 'std' tests would change globally.
    47  
    48  ! go test -fuzz . encoding/json
    49  stderr '^cannot use -fuzz flag on package outside the main module$'
    50  
    51  ! go test -fuzz . cmd/buildid
    52  stderr '^cannot use -fuzz flag on package outside the main module$'
    53  
    54  
    55  -- go.mod --
    56  module example.com/m
    57  
    58  go 1.18
    59  

View as plain text