From: Brad Fitzpatrick Date: Mon, 21 Jul 2014 19:06:30 +0000 (-0700) Subject: cmd/api: ignore internal packages X-Git-Tag: go1.4beta1~1043 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=4676e260e3b0f285037bf357e1b91ffb6135273c;p=gostls13.git 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 --- diff --git a/src/cmd/api/goapi.go b/src/cmd/api/goapi.go index 508056a937..007601328c 100644 --- a/src/cmd/api/goapi.go +++ b/src/cmd/api/goapi.go @@ -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 diff --git a/src/cmd/api/goapi_test.go b/src/cmd/api/goapi_test.go index b909c32b34..cb68769c8f 100644 --- a/src/cmd/api/goapi_test.go +++ b/src/cmd/api/goapi_test.go @@ -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 {