...
Run Format

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

Documentation: cmd/go/testdata/script

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

View as plain text