Commit a850dbde authored by Russ Cox's avatar Russ Cox

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 <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarRob Pike <r@golang.org>
parent e24ccfc6
...@@ -25,7 +25,7 @@ import ( ...@@ -25,7 +25,7 @@ import (
var ( var (
verbose = flag.Bool("v", false, "verbose") 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 tagList = []string{} // exploded version of tags flag; set in main
) )
...@@ -208,7 +208,10 @@ func 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() initPrintFlags()
initUnusedFlags() initUnusedFlags()
......
...@@ -128,21 +128,24 @@ func run(c *exec.Cmd, t *testing.T) bool { ...@@ -128,21 +128,24 @@ func run(c *exec.Cmd, t *testing.T) bool {
// TestTags verifies that the -tags argument controls which files to check. // TestTags verifies that the -tags argument controls which files to check.
func TestTags(t *testing.T) { func TestTags(t *testing.T) {
Build(t) Build(t)
args := []string{ for _, tag := range []string{"testtag", "x testtag y", "x,testtag,y"} {
"-tags=testtag", t.Logf("-tags=%s", tag)
"-v", // We're going to look at the files it examines. args := []string{
"testdata/tagtest", "-tags=" + tag,
} "-v", // We're going to look at the files it examines.
cmd := exec.Command("./"+binary, args...) "testdata/tagtest",
output, err := cmd.CombinedOutput() }
if err != nil { cmd := exec.Command("./"+binary, args...)
t.Fatal(err) output, err := cmd.CombinedOutput()
} if err != nil {
// file1 has testtag and file2 has !testtag. t.Fatal(err)
if !bytes.Contains(output, []byte(filepath.Join("tagtest", "file1.go"))) { }
t.Error("file1 was excluded, should be included") // file1 has testtag and file2 has !testtag.
} if !bytes.Contains(output, []byte(filepath.Join("tagtest", "file1.go"))) {
if bytes.Contains(output, []byte(filepath.Join("tagtest", "file2.go"))) { t.Error("file1 was excluded, should be included")
t.Error("file2 was included, should be excluded") }
if bytes.Contains(output, []byte(filepath.Join("tagtest", "file2.go"))) {
t.Error("file2 was included, should be excluded")
}
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment