]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: reliably remove temporary directory in testDwarf
authorIan Lance Taylor <iant@golang.org>
Fri, 1 Mar 2019 20:55:43 +0000 (12:55 -0800)
committerIan Lance Taylor <iant@golang.org>
Sat, 2 Mar 2019 04:25:26 +0000 (04:25 +0000)
We were using t.Parallel in a subtest, which meant that the main test
would not wait for the subtest, so the main test would delete the
temporary directory before the subtest used it. The subtest worked
because "go build -o /tmp/x/y/p.exe p" creates /tmp/x/y as needed.

Updates #30500

Change-Id: I5904ecac748d15ded4cb609f049fa548b8916a0e
Reviewed-on: https://go-review.googlesource.com/c/164857
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/link/dwarf_test.go

index 880b2ced6d821e49d510c8ef0b90ffd01a14ef01..9c3bc624ef9234b139aad66dce9411e3e8b49055 100644 (file)
@@ -37,17 +37,17 @@ func testDWARF(t *testing.T, buildmode string, expectDWARF bool, env ...string)
                t.Fatalf("cmd/link is stale - run go install cmd/link")
        }
 
-       tmpDir, err := ioutil.TempDir("", "go-link-TestDWARF")
-       if err != nil {
-               t.Fatal("TempDir failed: ", err)
-       }
-       defer os.RemoveAll(tmpDir)
-
        for _, prog := range []string{"testprog", "testprogcgo"} {
                prog := prog
                t.Run(prog, func(t *testing.T) {
                        t.Parallel()
 
+                       tmpDir, err := ioutil.TempDir("", "go-link-TestDWARF")
+                       if err != nil {
+                               t.Fatal(err)
+                       }
+                       defer os.RemoveAll(tmpDir)
+
                        exe := filepath.Join(tmpDir, prog+".exe")
                        dir := "../../runtime/testdata/" + prog
                        cmd := exec.Command(testenv.GoToolPath(t), "build", "-o", exe)