1
0
mirror of https://github.com/golang/go synced 2024-09-29 08:14:29 -06:00

cmd/go: allow arguments to 'go test' and 'go vet' to duplicate or override flags from GOFLAGS

This is a minimal fix for Go 1.14, but this parsing logic is much too
complex and seems like it will cause more trouble going forward.

I intend to mail a followup change to refactor this logic for 1.15.

Updates #32471

Change-Id: I00ed07dcf3a23c9cd4ffa8cf764921fb5c18bcd6
Reviewed-on: https://go-review.googlesource.com/c/go/+/210940
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
This commit is contained in:
Bryan C. Mills 2019-12-06 13:43:23 -05:00
parent 1b1fbb3192
commit a15b5d3092
3 changed files with 18 additions and 2 deletions

View File

@ -88,7 +88,8 @@ func init() {
// go test fmt -custom-flag-for-fmt-test
// go test -x math
func testFlags(usage func(), args []string) (packageNames, passToTest []string) {
args = str.StringList(cmdflag.FindGOFLAGS(testFlagDefn), args)
goflags := cmdflag.FindGOFLAGS(testFlagDefn)
args = str.StringList(goflags, args)
inPkg := false
var explicitArgs []string
for i := 0; i < len(args); i++ {
@ -127,6 +128,9 @@ func testFlags(usage func(), args []string) (packageNames, passToTest []string)
passToTest = append(passToTest, args[i])
continue
}
if i < len(goflags) {
f.Present = false // Not actually present on the command line.
}
if f.Value != nil {
if err := f.Value.Set(value); err != nil {
base.Fatalf("invalid flag argument for -%s: %v", f.Name, err)

View File

@ -126,7 +126,8 @@ func vetFlags(usage func(), args []string) (passToVet, packageNames []string) {
})
// Process args.
args = str.StringList(cmdflag.FindGOFLAGS(vetFlagDefn), args)
goflags := cmdflag.FindGOFLAGS(vetFlagDefn)
args = str.StringList(goflags, args)
for i := 0; i < len(args); i++ {
if !strings.HasPrefix(args[i], "-") {
return args[:i], args[i:]
@ -139,6 +140,9 @@ func vetFlags(usage func(), args []string) (passToVet, packageNames []string) {
base.SetExitStatus(2)
base.Exit()
}
if i < len(goflags) {
f.Present = false // Not actually present on the command line.
}
if f.Value != nil {
if err := f.Value.Set(value); err != nil {
base.Fatalf("invalid flag argument for -%s: %v", f.Name, err)

View File

@ -49,3 +49,11 @@ stderr '^go: invalid boolean value \"asdf\" for flag -e \(from (\$GOFLAGS|%GOFLA
go env
stdout GOFLAGS
# Flags listed in GOFLAGS should be safe to duplicate on the command line.
env GOFLAGS=-tags=magic
go list -tags=magic
go test -tags=magic -c -o $devnull
go vet -tags=magic
-- foo_test.go --
package foo