]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/vet: accept space-separated tag lists for compatibility with cmd/go
authorRuss Cox <rsc@golang.org>
Tue, 25 Oct 2016 19:49:00 +0000 (15:49 -0400)
committerRuss Cox <rsc@golang.org>
Tue, 25 Oct 2016 20:42:01 +0000 (20:42 +0000)
Fixes #17148.

Change-Id: I4c66aa0733c249ee6019d1c4e802a7e30457d4b6
Reviewed-on: https://go-review.googlesource.com/32030
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
src/cmd/vet/main.go
src/cmd/vet/vet_test.go

index 8149ba04e01a600780e49e1738b373aaaee961d5..3da0b3ccf514854d27eae53d66fe3f3e93fa84a7 100644 (file)
@@ -25,7 +25,7 @@ import (
 
 var (
        verbose = flag.Bool("v", false, "verbose")
-       tags    = flag.String("tags", "", "comma-separated list of build tags to apply when parsing")
+       tags    = flag.String("tags", "", "space-separated list of build tags to apply when parsing")
        tagList = []string{} // exploded version of tags flag; set in main
 )
 
@@ -208,7 +208,10 @@ func main() {
                }
        }
 
-       tagList = strings.Split(*tags, ",")
+       // Accept space-separated tags because that matches
+       // the go command's other subcommands.
+       // Accept commas because go tool vet traditionally has.
+       tagList = strings.Fields(strings.Replace(*tags, ",", " ", -1))
 
        initPrintFlags()
        initUnusedFlags()
index 9f8fc107b4560888f30bc9154edf23dee07b3235..b4b909e0e23b4107b67cc13809cccf5fae41fa26 100644 (file)
@@ -128,21 +128,24 @@ func run(c *exec.Cmd, t *testing.T) bool {
 // TestTags verifies that the -tags argument controls which files to check.
 func TestTags(t *testing.T) {
        Build(t)
-       args := []string{
-               "-tags=testtag",
-               "-v", // We're going to look at the files it examines.
-               "testdata/tagtest",
-       }
-       cmd := exec.Command("./"+binary, args...)
-       output, err := cmd.CombinedOutput()
-       if err != nil {
-               t.Fatal(err)
-       }
-       // file1 has testtag and file2 has !testtag.
-       if !bytes.Contains(output, []byte(filepath.Join("tagtest", "file1.go"))) {
-               t.Error("file1 was excluded, should be included")
-       }
-       if bytes.Contains(output, []byte(filepath.Join("tagtest", "file2.go"))) {
-               t.Error("file2 was included, should be excluded")
+       for _, tag := range []string{"testtag", "x testtag y", "x,testtag,y"} {
+               t.Logf("-tags=%s", tag)
+               args := []string{
+                       "-tags=" + tag,
+                       "-v", // We're going to look at the files it examines.
+                       "testdata/tagtest",
+               }
+               cmd := exec.Command("./"+binary, args...)
+               output, err := cmd.CombinedOutput()
+               if err != nil {
+                       t.Fatal(err)
+               }
+               // file1 has testtag and file2 has !testtag.
+               if !bytes.Contains(output, []byte(filepath.Join("tagtest", "file1.go"))) {
+                       t.Error("file1 was excluded, should be included")
+               }
+               if bytes.Contains(output, []byte(filepath.Join("tagtest", "file2.go"))) {
+                       t.Error("file2 was included, should be excluded")
+               }
        }
 }