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 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 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  env GOCACHE=$WORK/gocache
    56  
    57  # "go test" on a user package should by default enable an explicit list of analyzers.
    58  go test -x -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 -x -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 -x -run=none encoding/binary
    67  stderr '[/\\]vet'$GOEXE'["]? -unsafeptr=false -unreachable=false ["]?\$WORK[/\\][^ ]*[/\\]vet\.cfg'
    68  
    69  go test -x -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 -x -vet=unreachable -run=none .
    74  stderr '[/\\]vet'$GOEXE'["]? -unreachable ["]?\$WORK[/\\][^ ]*[/\\]vet\.cfg'
    75  go test -x -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