mirror of https://github.com/golang/go.git
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: Rob Pike <r@golang.org>
This commit is contained in:
parent
e24ccfc6fc
commit
a850dbdef2
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue