1
0
mirror of https://github.com/golang/go synced 2024-11-26 21:11:57 -07:00

cmd/internal/objabi: test runtime package list

This adds a test that all packages imported by runtime are marked as
runtime tests by LookupPkgSpecial. We add two packages that were
missing from the list.

Change-Id: I2545980ab09474de0181cf546541527d8baaf2e2
Reviewed-on: https://go-review.googlesource.com/c/go/+/521700
Run-TryBot: Austin Clements <austin@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
Austin Clements 2023-07-05 15:16:41 -04:00
parent fbcf43c60b
commit 3e73802c4a
2 changed files with 33 additions and 3 deletions

View File

@ -4,7 +4,12 @@
package objabi
import "testing"
import (
"internal/testenv"
"os/exec"
"strings"
"testing"
)
func TestPathToPrefix(t *testing.T) {
tests := []struct {
@ -31,3 +36,28 @@ func TestPathToPrefix(t *testing.T) {
}
}
}
func TestRuntimePackageList(t *testing.T) {
// Test that all packages imported by the runtime are marked as runtime
// packages.
testenv.MustHaveGoBuild(t)
goCmd, err := testenv.GoTool()
if err != nil {
t.Fatal(err)
}
pkgList, err := exec.Command(goCmd, "list", "-deps", "runtime").Output()
if err != nil {
if err, ok := err.(*exec.ExitError); ok {
t.Log(string(err.Stderr))
}
t.Fatal(err)
}
for _, pkg := range strings.Split(strings.TrimRight(string(pkgList), "\n"), "\n") {
if pkg == "unsafe" {
continue
}
if !LookupPkgSpecial(pkg).Runtime {
t.Errorf("package %s is imported by runtime, but not marked Runtime", pkg)
}
}
}

View File

@ -20,8 +20,6 @@ type PkgSpecial struct {
//
// This should be set for runtime and all packages it imports, and may be
// set for additional packages.
//
// TODO(austin): Test that all of `go list -deps runtime` is marked Runtime.
Runtime bool
// AllowAsmABI indicates that assembly in this package is allowed to use ABI
@ -44,6 +42,8 @@ var runtimePkgs = []string{
"internal/coverage/rtcov",
"internal/cpu",
"internal/goarch",
"internal/godebugs",
"internal/goexperiment",
"internal/goos",
}