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

     1  [!fuzz] skip
     2  [short] skip
     3  env 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
    11  stdout FAIL
    12  stdout 'error here'
    13  
    14  ! go test -v
    15  stdout FAIL
    16  stdout 'error here'
    17  stdout '=== RUN   FuzzFoo/thisfails'
    18  stdout '--- FAIL: FuzzFoo/thisfails'
    19  stdout '=== RUN   FuzzFoo/thispasses'
    20  stdout '--- PASS: FuzzFoo/thispasses'
    21  
    22  # Tests where -run matches all seed corpora.
    23  
    24  ! go test -run FuzzFoo/this
    25  stdout FAIL
    26  stdout 'error here'
    27  ! stdout 'no tests to run'
    28  
    29  ! go test -run /this
    30  stdout FAIL
    31  stdout 'error here'
    32  ! stdout 'no tests to run'
    33  
    34  ! go test -v -run FuzzFoo/this
    35  stdout FAIL
    36  stdout 'error here'
    37  stdout '=== RUN   FuzzFoo/thisfails'
    38  stdout '--- FAIL: FuzzFoo/thisfails'
    39  stdout '=== RUN   FuzzFoo/thispasses'
    40  stdout '--- PASS: FuzzFoo/thispasses'
    41  ! stdout 'no tests to run'
    42  
    43  ! go test -v -run /this
    44  stdout FAIL
    45  stdout 'error here'
    46  stdout '=== RUN   FuzzFoo/thisfails'
    47  stdout '--- FAIL: FuzzFoo/thisfails'
    48  stdout '=== RUN   FuzzFoo/thispasses'
    49  stdout '--- PASS: FuzzFoo/thispasses'
    50  ! stdout 'no tests to run'
    51  
    52  # Tests where -run only matches one seed corpus which passes.
    53  
    54  go test -run FuzzFoo/thispasses
    55  stdout ok
    56  ! stdout 'no tests to run'
    57  
    58  go test -run /thispasses
    59  stdout ok
    60  ! stdout 'no tests to run'
    61  
    62  # Same tests in verbose mode
    63  go test -v -run FuzzFoo/thispasses
    64  stdout '=== RUN   FuzzFoo/thispasses'
    65  stdout '--- PASS: FuzzFoo/thispasses'
    66  ! stdout '=== RUN   FuzzFoo/thisfails'
    67  ! stdout 'no tests to run'
    68  
    69  go test -v -run /thispasses
    70  stdout '=== RUN   FuzzFoo/thispasses'
    71  stdout '--- 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
    78  stdout FAIL
    79  stdout 'error here'
    80  ! stdout 'no tests to run'
    81  
    82  ! go test -run /thisfails
    83  stdout FAIL
    84  stdout 'error here'
    85  ! stdout 'no tests to run'
    86  
    87  ! go test -v -run FuzzFoo/thisfails
    88  stdout 'error here'
    89  stdout '=== RUN   FuzzFoo/thisfails'
    90  stdout '--- FAIL: FuzzFoo/thisfails'
    91  ! stdout '=== RUN   FuzzFoo/thispasses'
    92  ! stdout 'no tests to run'
    93  
    94  ! go test -v -run /thisfails
    95  stdout 'error here'
    96  stdout '=== RUN   FuzzFoo/thisfails'
    97  stdout '--- 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  
   103  go test -run FuzzFoo/nomatch
   104  stdout ok
   105  
   106  go test -run /nomatch
   107  stdout ok
   108  
   109  go test -v -run FuzzFoo/nomatch
   110  stdout '=== RUN   FuzzFoo'
   111  stdout '--- PASS: FuzzFoo'
   112  stdout ok
   113  ! stdout 'no tests to run'
   114  
   115  go test -v -run /nomatch
   116  stdout '=== RUN   FuzzFoo'
   117  stdout '--- PASS: FuzzFoo'
   118  stdout ok
   119  ! stdout 'no tests to run'
   120  
   121  -- go.mod --
   122  module example.com/x
   123  
   124  go 1.16
   125  -- x_test.go --
   126  package x
   127  
   128  import "testing"
   129  
   130  func 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 --
   139  go test fuzz v1
   140  string("fails")
   141  -- testdata/fuzz/FuzzFoo/thispasses --
   142  go test fuzz v1
   143  string("passes")
   144  

View as plain text