From: Than McIntosh Date: Mon, 26 Sep 2022 13:17:23 +0000 (-0400) Subject: cmd/go: avoid internal errors on "go test -testwork" X-Git-Tag: go1.20rc1~944 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=1e91ffc897efb1ed298753c08f086fbc8f725025;p=gostls13.git 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 --- 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 {