aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2019-12-06 13:43:23 -0500
committerBryan C. Mills <bcmills@google.com>2019-12-11 22:01:13 +0000
commita15b5d30925e7be1101d812311545afb82c45a68 (patch)
treeeeaf4c863d6afb954e710acca45f967eb2d1f33b
parent1b1fbb3192984624871ab92518499d4bd6e6e65c (diff)
downloadgo-a15b5d30925e7be1101d812311545afb82c45a68.tar.gz
go-a15b5d30925e7be1101d812311545afb82c45a68.zip
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>
-rw-r--r--src/cmd/go/internal/test/testflag.go6
-rw-r--r--src/cmd/go/internal/vet/vetflag.go6
-rw-r--r--src/cmd/go/testdata/script/goflags.txt8
3 files changed, 18 insertions, 2 deletions
diff --git a/src/cmd/go/internal/test/testflag.go b/src/cmd/go/internal/test/testflag.go
index 79dc5eb2a0..e214b1532b 100644
--- a/src/cmd/go/internal/test/testflag.go
+++ b/src/cmd/go/internal/test/testflag.go
@@ -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)
diff --git a/src/cmd/go/internal/vet/vetflag.go b/src/cmd/go/internal/vet/vetflag.go
index 7179f73cfc..e3de48bbff 100644
--- a/src/cmd/go/internal/vet/vetflag.go
+++ b/src/cmd/go/internal/vet/vetflag.go
@@ -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)
diff --git a/src/cmd/go/testdata/script/goflags.txt b/src/cmd/go/testdata/script/goflags.txt
index fac6d80720..686d1138b8 100644
--- a/src/cmd/go/testdata/script/goflags.txt
+++ b/src/cmd/go/testdata/script/goflags.txt
@@ -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