From 1e91ffc897efb1ed298753c08f086fbc8f725025 Mon Sep 17 00:00:00 2001 From: Than McIntosh Date: Mon, 26 Sep 2022 09:17:23 -0400 Subject: [PATCH] cmd/go: avoid internal errors on "go test -testwork" Fix up the package test harness to avoid errors of the form go_test.go:NNN: internal testsuite error: path(".") with no tempdir when the "-testwork" flag is passed when running "go test". Fixes #55874. Change-Id: I76cc39902f51a62cb4cd0da8794b97d620fb4873 Reviewed-on: https://go-review.googlesource.com/c/go/+/434455 Run-TryBot: Than McIntosh Reviewed-by: Bryan Mills TryBot-Result: Gopher Robot --- src/cmd/go/go_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go index bcf2349d3b..00b29560ca 100644 --- a/src/cmd/go/go_test.go +++ b/src/cmd/go/go_test.go @@ -159,6 +159,8 @@ func TestMain(m *testing.M) { } if !*testWork { defer removeAll(topTmpdir) + } else { + fmt.Fprintf(os.Stderr, "TESTWORK: preserving top level tempdir %s\n", topTmpdir) } os.Setenv(tempEnvName(), topTmpdir) @@ -826,7 +828,9 @@ var testWork = flag.Bool("testwork", false, "") func (tg *testgoData) cleanup() { tg.t.Helper() if *testWork { - tg.t.Logf("TESTWORK=%s\n", tg.path(".")) + if tg.tempdir != "" { + tg.t.Logf("TESTWORK=%s\n", tg.path(".")) + } return } for _, path := range tg.temps { -- 2.48.1