Commit 4676e260 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

cmd/api: ignore internal packages

We might want to add a go/build.IsInternal(pkg string) bool
later, but this works for now.

LGTM=dave, rsc
R=rsc, dave
CC=golang-codereviews
https://golang.org/cl/113300044
parent 2ac289c4
......@@ -107,6 +107,8 @@ func setContexts() {
}
}
var internalPkg = regexp.MustCompile(`(^|/)internal($|/)`)
func main() {
flag.Parse()
......@@ -132,7 +134,11 @@ func main() {
if err != nil {
log.Fatal(err)
}
pkgNames = strings.Fields(string(stds))
for _, pkg := range strings.Fields(string(stds)) {
if !internalPkg.MatchString(pkg) {
pkgNames = append(pkgNames, pkg)
}
}
}
var featureCtx = make(map[string]map[string]bool) // feature -> context name -> true
......
......@@ -142,6 +142,26 @@ func TestCompareAPI(t *testing.T) {
}
}
func TestSkipInternal(t *testing.T) {
tests := []struct {
pkg string
want bool
}{
{"net/http", true},
{"net/http/internal-foo", true},
{"net/http/internal", false},
{"net/http/internal/bar", false},
{"internal/foo", false},
{"internal", false},
}
for _, tt := range tests {
got := !internalPkg.MatchString(tt.pkg)
if got != tt.want {
t.Errorf("%s is internal = %v; want %v", tt.pkg, got, tt.want)
}
}
}
func BenchmarkAll(b *testing.B) {
stds, err := exec.Command("go", "list", "std").Output()
if err != nil {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment