...

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

Documentation: cmd/go/testdata/script

     1[!fuzz] skip
     2[short] skip
     3env GOCACHE=$WORK/cache
     4
     5# Tests which verify the behavior and command line output when
     6# running a fuzz target as a unit test.
     7
     8# Tests without -run.
     9
    10! go test
    11stdout FAIL
    12stdout 'error here'
    13
    14! go test -v
    15stdout FAIL
    16stdout 'error here'
    17stdout '=== RUN   FuzzFoo/thisfails'
    18stdout '--- FAIL: FuzzFoo/thisfails'
    19stdout '=== RUN   FuzzFoo/thispasses'
    20stdout '--- PASS: FuzzFoo/thispasses'
    21
    22# Tests where -run matches all seed corpora.
    23
    24! go test -run FuzzFoo/this
    25stdout FAIL
    26stdout 'error here'
    27! stdout 'no tests to run'
    28
    29! go test -run /this
    30stdout FAIL
    31stdout 'error here'
    32! stdout 'no tests to run'
    33
    34! go test -v -run FuzzFoo/this
    35stdout FAIL
    36stdout 'error here'
    37stdout '=== RUN   FuzzFoo/thisfails'
    38stdout '--- FAIL: FuzzFoo/thisfails'
    39stdout '=== RUN   FuzzFoo/thispasses'
    40stdout '--- PASS: FuzzFoo/thispasses'
    41! stdout 'no tests to run'
    42
    43! go test -v -run /this
    44stdout FAIL
    45stdout 'error here'
    46stdout '=== RUN   FuzzFoo/thisfails'
    47stdout '--- FAIL: FuzzFoo/thisfails'
    48stdout '=== RUN   FuzzFoo/thispasses'
    49stdout '--- PASS: FuzzFoo/thispasses'
    50! stdout 'no tests to run'
    51
    52# Tests where -run only matches one seed corpus which passes.
    53
    54go test -run FuzzFoo/thispasses
    55stdout ok
    56! stdout 'no tests to run'
    57
    58go test -run /thispasses
    59stdout ok
    60! stdout 'no tests to run'
    61
    62# Same tests in verbose mode
    63go test -v -run FuzzFoo/thispasses
    64stdout '=== RUN   FuzzFoo/thispasses'
    65stdout '--- PASS: FuzzFoo/thispasses'
    66! stdout '=== RUN   FuzzFoo/thisfails'
    67! stdout 'no tests to run'
    68
    69go test -v -run /thispasses
    70stdout '=== RUN   FuzzFoo/thispasses'
    71stdout '--- PASS: FuzzFoo/thispasses'
    72! stdout '=== RUN   FuzzFoo/thisfails'
    73! stdout 'no tests to run'
    74
    75# Tests where -run only matches one seed corpus which fails.
    76
    77! go test -run FuzzFoo/thisfails
    78stdout FAIL
    79stdout 'error here'
    80! stdout 'no tests to run'
    81
    82! go test -run /thisfails
    83stdout FAIL
    84stdout 'error here'
    85! stdout 'no tests to run'
    86
    87! go test -v -run FuzzFoo/thisfails
    88stdout 'error here'
    89stdout '=== RUN   FuzzFoo/thisfails'
    90stdout '--- FAIL: FuzzFoo/thisfails'
    91! stdout '=== RUN   FuzzFoo/thispasses'
    92! stdout 'no tests to run'
    93
    94! go test -v -run /thisfails
    95stdout 'error here'
    96stdout '=== RUN   FuzzFoo/thisfails'
    97stdout '--- FAIL: FuzzFoo/thisfails'
    98! stdout '=== RUN   FuzzFoo/thispasses'
    99! stdout 'no tests to run'
   100
   101# Tests where -run doesn't match any seed corpora.
   102
   103go test -run FuzzFoo/nomatch
   104stdout ok
   105
   106go test -run /nomatch
   107stdout ok
   108
   109go test -v -run FuzzFoo/nomatch
   110stdout '=== RUN   FuzzFoo'
   111stdout '--- PASS: FuzzFoo'
   112stdout ok
   113! stdout 'no tests to run'
   114
   115go test -v -run /nomatch
   116stdout '=== RUN   FuzzFoo'
   117stdout '--- PASS: FuzzFoo'
   118stdout ok
   119! stdout 'no tests to run'
   120
   121-- go.mod --
   122module example.com/x
   123
   124go 1.16
   125-- x_test.go --
   126package x
   127
   128import "testing"
   129
   130func FuzzFoo(f *testing.F) {
   131    f.Add("this is fine")
   132    f.Fuzz(func(t *testing.T, s string) {
   133        if s == "fails" {
   134            t.Error("error here")
   135        }
   136    })
   137}
   138-- testdata/fuzz/FuzzFoo/thisfails --
   139go test fuzz v1
   140string("fails")
   141-- testdata/fuzz/FuzzFoo/thispasses --
   142go test fuzz v1
   143string("passes")

View as plain text