1
2
3
4
5 package test
6
7 import (
8 "cmd/go/internal/test/internal/genflags"
9 "flag"
10 "reflect"
11 "strings"
12 "testing"
13 )
14
15 func TestPassFlagToTestIncludesAllTestFlags(t *testing.T) {
16 flag.VisitAll(func(f *flag.Flag) {
17 if !strings.HasPrefix(f.Name, "test.") {
18 return
19 }
20 name := strings.TrimPrefix(f.Name, "test.")
21 switch name {
22 case "testlogfile", "paniconexit0", "fuzzcachedir", "fuzzworker":
23
24 default:
25 if !passFlagToTest[name] {
26 t.Errorf("passFlagToTest missing entry for %q (flag test.%s)", name, name)
27 t.Logf("(Run 'go generate cmd/go/internal/test' if it should be added.)")
28 }
29 }
30 })
31
32 for name := range passFlagToTest {
33 if flag.Lookup("test."+name) == nil {
34 t.Errorf("passFlagToTest contains %q, but flag -test.%s does not exist in test binary", name, name)
35 }
36
37 if CmdTest.Flag.Lookup(name) == nil {
38 t.Errorf("passFlagToTest contains %q, but flag -%s does not exist in 'go test' subcommand", name, name)
39 }
40 }
41 }
42
43 func TestVetAnalyzersSetIsCorrect(t *testing.T) {
44 vetAns, err := genflags.VetAnalyzers()
45 if err != nil {
46 t.Fatal(err)
47 }
48
49 want := make(map[string]bool)
50 for _, a := range vetAns {
51 want[a] = true
52 }
53
54 if !reflect.DeepEqual(want, passAnalyzersToVet) {
55 t.Errorf("stale vet analyzers: want %v; got %v", want, passAnalyzersToVet)
56 t.Logf("(Run 'go generate cmd/go/internal/test' to refresh the set of analyzers.)")
57 }
58 }
59
View as plain text