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
)
}
}
- 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()
// 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")
+ }
}
}