]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link/internal/ld: simplify gobuildTestdata
authorKir Kolyshkin <kolyshkin@gmail.com>
Wed, 4 Sep 2024 02:32:40 +0000 (19:32 -0700)
committerGopher Robot <gobot@golang.org>
Wed, 4 Sep 2024 18:50:48 +0000 (18:50 +0000)
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 <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Commit-Queue: Ian Lance Taylor <iant@golang.org>

src/cmd/link/internal/ld/dwarf_test.go

index 40202bd31256bc9ff9e200e4079262af3a773390..e14e2edc8f48010655821a2791e3fefb0a98e15a 100644 (file)
@@ -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