From a850dbdef2f1875d81ad09024480f648ce3eac32 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Tue, 25 Oct 2016 15:49:00 -0400 Subject: [PATCH] cmd/vet: accept space-separated tag lists for compatibility with cmd/go Fixes #17148. Change-Id: I4c66aa0733c249ee6019d1c4e802a7e30457d4b6 Reviewed-on: https://go-review.googlesource.com/32030 Run-TryBot: Russ Cox TryBot-Result: Gobot Gobot Reviewed-by: Rob Pike --- src/cmd/vet/main.go | 7 +++++-- src/cmd/vet/vet_test.go | 35 +++++++++++++++++++---------------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/cmd/vet/main.go b/src/cmd/vet/main.go index 8149ba04e0..3da0b3ccf5 100644 --- a/src/cmd/vet/main.go +++ b/src/cmd/vet/main.go @@ -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() diff --git a/src/cmd/vet/vet_test.go b/src/cmd/vet/vet_test.go index 9f8fc107b4..b4b909e0e2 100644 --- a/src/cmd/vet/vet_test.go +++ b/src/cmd/vet/vet_test.go @@ -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") + } } } -- 2.48.1