]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: allow arguments to 'go test' and 'go vet' to duplicate or override flags...
authorBryan C. Mills <bcmills@google.com>
Fri, 6 Dec 2019 18:43:23 +0000 (13:43 -0500)
committerBryan C. Mills <bcmills@google.com>
Wed, 11 Dec 2019 22:01:13 +0000 (22:01 +0000)
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>
src/cmd/go/internal/test/testflag.go
src/cmd/go/internal/vet/vetflag.go
src/cmd/go/testdata/script/goflags.txt

index 79dc5eb2a0c0a4414d2f0cd1ecf079740dc47b2d..e214b1532bdaead3ed4daabbaceb7aa028107033 100644 (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)
index 7179f73cfcd9dd91d224e00e462c8e1f2df7ac84..e3de48bbffaa4b4be2252b1d95ab197d2a10db94 100644 (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)
index fac6d807202285e365ff343b2b18bfd62105c5d9..686d1138b8318e3d0ed5affd6673ee66ead24c96 100644 (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