...
1
2
3
4
5 package test
6
7 import (
8 "cmd/go/internal/cfg"
9 "cmd/go/internal/test/internal/genflags"
10 "internal/testenv"
11 "maps"
12 "os"
13 "testing"
14 )
15
16 func TestMain(m *testing.M) {
17 cfg.SetGOROOT(testenv.GOROOT(nil), false)
18 os.Exit(m.Run())
19 }
20
21 func TestPassFlagToTest(t *testing.T) {
22 wantNames := genflags.ShortTestFlags()
23
24 missing := map[string]bool{}
25 for _, name := range wantNames {
26 if !passFlagToTest[name] {
27 missing[name] = true
28 }
29 }
30 if len(missing) > 0 {
31 t.Errorf("passFlagToTest is missing entries: %v", missing)
32 }
33
34 extra := maps.Clone(passFlagToTest)
35 for _, name := range wantNames {
36 delete(extra, name)
37 }
38 if len(extra) > 0 {
39 t.Errorf("passFlagToTest contains extra entries: %v", extra)
40 }
41
42 if t.Failed() {
43 t.Logf("To regenerate:\n\tgo generate cmd/go/internal/test")
44 }
45 }
46
47 func TestPassAnalyzersToVet(t *testing.T) {
48 testenv.MustHaveGoBuild(t)
49
50 wantNames, err := genflags.VetAnalyzers()
51 if err != nil {
52 t.Fatal(err)
53 }
54
55 missing := map[string]bool{}
56 for _, name := range wantNames {
57 if !passAnalyzersToVet[name] {
58 missing[name] = true
59 }
60 }
61 if len(missing) > 0 {
62 t.Errorf("passAnalyzersToVet is missing entries: %v", missing)
63 }
64
65 extra := maps.Clone(passAnalyzersToVet)
66 for _, name := range wantNames {
67 delete(extra, name)
68 }
69 if len(extra) > 0 {
70 t.Errorf("passFlagToTest contains extra entries: %v", extra)
71 }
72
73 if t.Failed() {
74 t.Logf("To regenerate:\n\tgo generate cmd/go/internal/test")
75 }
76 }
77
View as plain text