| 1 |
// Copyright 2019 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 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 |
// TestPassFlagToTest ensures that the generated table of flags is |
| 22 |
// consistent with output of "go tool vet -flags", using the installed |
| 23 |
// go command---so if it fails, you may need to re-run make.bash. |
| 24 |
func TestPassFlagToTest(t *testing.T) { |
| 25 |
wantNames := genflags.ShortTestFlags() |
| 26 |
|
| 27 |
missing := map[string]bool{} |
| 28 |
for _, name := range wantNames { |
| 29 |
if !passFlagToTest[name] { |
| 30 |
missing[name] = true |
| 31 |
} |
| 32 |
} |
| 33 |
if len(missing) > 0 { |
| 34 |
t.Errorf("passFlagToTest is missing entries: %v", missing) |
| 35 |
} |
| 36 |
|
| 37 |
extra := maps.Clone(passFlagToTest) |
| 38 |
for _, name := range wantNames { |
| 39 |
delete(extra, name) |
| 40 |
} |
| 41 |
if len(extra) > 0 { |
| 42 |
t.Errorf("passFlagToTest contains extra entries: %v", extra) |
| 43 |
} |
| 44 |
|
| 45 |
if t.Failed() { |
| 46 |
t.Logf("To regenerate:\n\tgo generate cmd/go/internal/test") |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
func TestPassAnalyzersToVet(t *testing.T) { |
| 51 |
testenv.MustHaveGoBuild(t) // runs 'go tool vet -flags' |
| 52 |
|
| 53 |
wantNames, err := genflags.VetAnalyzers() |
| 54 |
if err != nil { |
| 55 |
t.Fatal(err) |
| 56 |
} |
| 57 |
|
| 58 |
missing := map[string]bool{} |
| 59 |
for _, name := range wantNames { |
| 60 |
if !passAnalyzersToVet[name] { |
| 61 |
missing[name] = true |
| 62 |
} |
| 63 |
} |
| 64 |
if len(missing) > 0 { |
| 65 |
t.Errorf("passAnalyzersToVet is missing entries: %v", missing) |
| 66 |
} |
| 67 |
|
| 68 |
extra := maps.Clone(passAnalyzersToVet) |
| 69 |
for _, name := range wantNames { |
| 70 |
delete(extra, name) |
| 71 |
} |
| 72 |
if len(extra) > 0 { |
| 73 |
t.Errorf("passFlagToTest contains extra entries: %v", extra) |
| 74 |
} |
| 75 |
|
| 76 |
if t.Failed() { |
| 77 |
t.Logf("To regenerate:\n\tgo generate cmd/go/internal/test") |
| 78 |
} |
| 79 |
} |