From: Kir Kolyshkin Date: Wed, 4 Sep 2024 02:32:40 +0000 (-0700) Subject: cmd/link/internal/ld: simplify gobuildTestdata X-Git-Tag: go1.24rc1~1016 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=dfae83c9db334477ba3f3ab9df4f174e7f778e55;p=gostls13.git cmd/link/internal/ld: simplify gobuildTestdata Drop the second argument, which is is always a one-time temporary directory, thus it can be created right here. Change-Id: I73e5be2ccd4bddec249c7cb2a8ff9242d99f7e20 Reviewed-on: https://go-review.googlesource.com/c/go/+/610037 LUCI-TryBot-Result: Go LUCI Reviewed-by: Cherry Mui Reviewed-by: Dmitri Shuralyov Auto-Submit: Ian Lance Taylor Commit-Queue: Ian Lance Taylor --- diff --git a/src/cmd/link/internal/ld/dwarf_test.go b/src/cmd/link/internal/ld/dwarf_test.go index 40202bd312..e14e2edc8f 100644 --- a/src/cmd/link/internal/ld/dwarf_test.go +++ b/src/cmd/link/internal/ld/dwarf_test.go @@ -131,8 +131,8 @@ func gobuild(t *testing.T, dir string, testfile string, gcflags string) *builtFi // Similar to gobuild() above, but uses a main package instead of a test.go file. -func gobuildTestdata(t *testing.T, tdir string, pkgDir string, gcflags string) *builtFile { - dst := filepath.Join(tdir, "out.exe") +func gobuildTestdata(t *testing.T, pkgDir string, gcflags string) *builtFile { + dst := filepath.Join(t.TempDir(), "out.exe") // Run a build with an updated GOPATH cmd := testenv.Command(t, testenv.GoToolPath(t), "build", gcflags, "-o", dst) @@ -762,10 +762,8 @@ func main() { func abstractOriginSanity(t *testing.T, pkgDir string, flags string) { t.Parallel() - dir := t.TempDir() - // Build with inlining, to exercise DWARF inlining support. - f := gobuildTestdata(t, dir, filepath.Join(pkgDir, "main"), flags) + f := gobuildTestdata(t, filepath.Join(pkgDir, "main"), flags) defer f.Close() d, err := f.DWARF() @@ -1231,14 +1229,12 @@ func TestMachoIssue32233(t *testing.T) { t.Skip("skipping; test only interesting on darwin") } - tmpdir := t.TempDir() - wd, err := os.Getwd() if err != nil { t.Fatalf("where am I? %v", err) } pdir := filepath.Join(wd, "testdata", "issue32233", "main") - f := gobuildTestdata(t, tmpdir, pdir, DefaultOpt) + f := gobuildTestdata(t, pdir, DefaultOpt) f.Close() } @@ -1313,13 +1309,12 @@ func TestIssue38192(t *testing.T) { // Build a test program that contains a translation unit whose // text (from am assembly source) contains only a single instruction. - tmpdir := t.TempDir() wd, err := os.Getwd() if err != nil { t.Fatalf("where am I? %v", err) } pdir := filepath.Join(wd, "testdata", "issue38192") - f := gobuildTestdata(t, tmpdir, pdir, DefaultOpt) + f := gobuildTestdata(t, pdir, DefaultOpt) defer f.Close() // Open the resulting binary and examine the DWARF it contains. @@ -1431,14 +1426,12 @@ func TestIssue39757(t *testing.T) { // compiler/runtime in ways that aren't happening now, so this // might be something to check for if it does start failing. - tmpdir := t.TempDir() - wd, err := os.Getwd() if err != nil { t.Fatalf("where am I? %v", err) } pdir := filepath.Join(wd, "testdata", "issue39757") - f := gobuildTestdata(t, tmpdir, pdir, DefaultOpt) + f := gobuildTestdata(t, pdir, DefaultOpt) defer f.Close() syms, err := f.Symbols() @@ -1529,17 +1522,12 @@ func TestIssue42484(t *testing.T) { t.Parallel() - tmpdir, err := os.MkdirTemp("", "TestIssue42484") - if err != nil { - t.Fatalf("could not create directory: %v", err) - } - defer os.RemoveAll(tmpdir) wd, err := os.Getwd() if err != nil { t.Fatalf("where am I? %v", err) } pdir := filepath.Join(wd, "testdata", "issue42484") - f := gobuildTestdata(t, tmpdir, pdir, NoOpt) + f := gobuildTestdata(t, pdir, NoOpt) var lastAddr uint64 var lastFile string