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

     1  env GO111MODULE=on
     2  
     3  # Issue 35837: "go vet -<analyzer> <std package>" should use the requested
     4  # analyzers, not the default analyzers for 'go test'.
     5  go vet -n -buildtags=false runtime
     6  stderr '-buildtags=false'
     7  ! stderr '-unsafeptr=false'
     8  
     9  # Issue 37030: "go vet <std package>" without other flags should disable the
    10  # unsafeptr check by default.
    11  go vet -n runtime
    12  stderr '-unsafeptr=false'
    13  ! stderr '-unreachable=false'
    14  
    15  # However, it should be enabled if requested explicitly.
    16  go vet -n -unsafeptr runtime
    17  stderr '-unsafeptr'
    18  ! stderr '-unsafeptr=false'
    19  
    20  # -unreachable is disabled during test but on during plain vet.
    21  go test -n runtime
    22  stderr '-unreachable=false'
    23  
    24  # A flag terminator should be allowed before the package list.
    25  go vet -n -- .
    26  
    27  [short] stop
    28  
    29  # Analyzer flags should be included from GOFLAGS, and should override
    30  # the defaults.
    31  go vet .
    32  env GOFLAGS='-tags=buggy'
    33  ! go vet .
    34  stderr 'possible Printf formatting directive'
    35  
    36  # Enabling one analyzer in GOFLAGS should disable the rest implicitly...
    37  env GOFLAGS='-tags=buggy -unsafeptr'
    38  go vet .
    39  
    40  # ...but enabling one on the command line should not disable the analyzers
    41  # enabled via GOFLAGS.
    42  env GOFLAGS='-tags=buggy -printf'
    43  ! go vet -unsafeptr
    44  stderr 'possible Printf formatting directive'
    45  
    46  # Analyzer flags don't exist unless we're running 'go vet',
    47  # and we shouldn't run the vet tool to discover them otherwise.
    48  # (Maybe someday we'll hard-code the analyzer flags for the default vet
    49  # tool to make this work, but not right now.)
    50  env GOFLAGS='-unsafeptr'
    51  ! go list .
    52  stderr 'go: parsing \$GOFLAGS: unknown flag -unsafeptr'
    53  env GOFLAGS=
    54  
    55  # "go test" on a user package should by default enable an explicit list of analyzers.
    56  go test -n -run=none .
    57  stderr '[/\\]vet'$GOEXE'["]? .* -errorsas .* ["]?\$WORK[/\\][^ ]*[/\\]vet\.cfg'
    58  
    59  # An explicitly-empty -vet argument should imply the default analyzers.
    60  go test -n -vet= -run=none .
    61  stderr '[/\\]vet'$GOEXE'["]? .* -errorsas .* ["]?\$WORK[/\\][^ ]*[/\\]vet\.cfg'
    62  
    63  # "go test" on a standard package should by default disable an explicit list.
    64  go test -n -run=none encoding/binary
    65  stderr '[/\\]vet'$GOEXE'["]? -unsafeptr=false -unreachable=false ["]?\$WORK[/\\][^ ]*[/\\]vet\.cfg'
    66  
    67  go test -n -vet= -run=none encoding/binary
    68  stderr '[/\\]vet'$GOEXE'["]? -unsafeptr=false -unreachable=false ["]?\$WORK[/\\][^ ]*[/\\]vet\.cfg'
    69  
    70  # Both should allow users to override via the -vet flag.
    71  go test -n -vet=unreachable -run=none .
    72  stderr '[/\\]vet'$GOEXE'["]? -unreachable ["]?\$WORK[/\\][^ ]*[/\\]vet\.cfg'
    73  go test -n -vet=unreachable -run=none encoding/binary
    74  stderr '[/\\]vet'$GOEXE'["]? -unreachable ["]?\$WORK[/\\][^ ]*[/\\]vet\.cfg'
    75  
    76  -- go.mod --
    77  module example.com/x
    78  -- x.go --
    79  package x
    80  -- x_test.go --
    81  package x
    82  -- x_tagged.go --
    83  // +build buggy
    84  
    85  package x
    86  
    87  import "fmt"
    88  
    89  func init() {
    90  	fmt.Sprint("%s") // oops!
    91  }
    92  

View as plain text