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

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

View as plain text