Skip to content

Commit

Permalink
internal/tests/deps: add more information to error message
Browse files Browse the repository at this point in the history
For golang/go#64807

Change-Id: Ie2b95ccf0c77ceb8d4a138a767937e3751db7a76
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/553516
LUCI-TryBot-Result: Go LUCI <[email protected]>
Run-TryBot: Michael Matloob <[email protected]>
Reviewed-by: Jonathan Amsterdam <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: Bryan Mills <[email protected]>
kokoro-CI: kokoro <[email protected]>
  • Loading branch information
matloob committed Jan 3, 2024
1 parent e232f56 commit eb2fcc3
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions internal/tests/deps/cmd_pkgsite_deps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@ var additionalAllowedTestModDeps = map[string]bool{

func TestCmdPkgsiteDeps(t *testing.T) {
// First, list all dependencies of pkgsite.
out, err := exec.Command("go", "list", "-deps", "golang.org/x/pkgsite/cmd/pkgsite").Output()
out, err := exec.Command("go", "list", "-e", "-deps", "golang.org/x/pkgsite/cmd/pkgsite").Output()
if err != nil {
t.Fatal("running go list: ", err)
if ee, ok := err.(*exec.ExitError); ok && len(ee.Stderr) > 0 {
t.Fatalf("running go list -test -deps on package golang.org/x/pkgsite/cmd/pkgsite:\n%s", ee.Stderr)
}
t.Fatalf("running go list -test -deps on package golang.org/x/pkgsite/cmd/pkgsite: %v", err)

}
pkgs := strings.Fields(string(out))
for _, pkg := range pkgs {
Expand All @@ -43,9 +47,12 @@ func TestCmdPkgsiteDeps(t *testing.T) {
}

// Get the test module deps and check them against allowedTestModDeps.
out, err := exec.Command("go", "list", "-deps", "-test", "-f", "{{if .Module}}{{.Module.Path}}{{end}}", pkg).Output()
out, err := exec.Command("go", "list", "-e", "-deps", "-test", "-f", "{{if .Module}}{{.Module.Path}}{{end}}", pkg).Output()
if err != nil {
t.Fatal(err)
if ee, ok := err.(*exec.ExitError); ok && len(ee.Stderr) > 0 {
t.Fatalf("running go list -test -deps on package %s:\n%s", pkg, ee.Stderr)
}
t.Fatalf("running go list -test -deps on package %s: %v", pkg, err)
}
testmodules := strings.Fields(string(out))
for _, m := range testmodules {
Expand All @@ -55,9 +62,12 @@ func TestCmdPkgsiteDeps(t *testing.T) {
}

// Get the module deps and check them against allowedModDeps
out, err = exec.Command("go", "list", "-deps", "-f", "{{if .Module}}{{.Module.Path}}{{end}}", pkg).Output()
out, err = exec.Command("go", "list", "-e", "-deps", "-f", "{{if .Module}}{{.Module.Path}}{{end}}", pkg).Output()
if err != nil {
t.Fatal(err)
if ee, ok := err.(*exec.ExitError); ok && len(ee.Stderr) > 0 {
t.Fatalf("running go list -deps on package %s:\n%s", pkg, ee.Stderr)
}
t.Fatalf("running go list -deps on package %s: %v", pkg, err)
}
modules := strings.Fields(string(out))
for _, m := range modules {
Expand Down

0 comments on commit eb2fcc3

Please sign in to comment.