]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/objabi: test runtime package list
authorAustin Clements <austin@google.com>
Wed, 5 Jul 2023 19:16:41 +0000 (15:16 -0400)
committerAustin Clements <austin@google.com>
Tue, 22 Aug 2023 19:18:30 +0000 (19:18 +0000)
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>

src/cmd/internal/objabi/path_test.go
src/cmd/internal/objabi/pkgspecial.go

index 05d7fb436e33e22f5fbcb4c2a33f5639955da7d9..78b94a32669bdcc5940c38b18d6489bba7fdda1d 100644 (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)
+               }
+       }
+}
index 22b974a06c7e6a66595a74dcf9717413912a036d..144110b75510ef0f7ff7afe8042824d6cad2a809 100644 (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",
 }