]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: avoid internal errors on "go test -testwork"
authorThan McIntosh <thanm@google.com>
Mon, 26 Sep 2022 13:17:23 +0000 (09:17 -0400)
committerThan McIntosh <thanm@google.com>
Mon, 26 Sep 2022 14:16:42 +0000 (14:16 +0000)
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 <thanm@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/cmd/go/go_test.go

index bcf2349d3bf6857583206360c5acda99d441bd66..00b29560ca18f7b522befd58f77e4e1f23494ebe 100644 (file)
@@ -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 {