Skip to content

Commit b161b57

Browse files
perilloianlancetaylor
authored andcommitted
go/build: replace os.MkdirTemp with T.TempDir
Updates #45402 Change-Id: Ic2f696837034de17333a6a53127a4bfd301e96a4 Reviewed-on: https://go-review.googlesource.com/c/go/+/309354 Run-TryBot: Ian Lance Taylor <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Trust: Tobias Klauser <[email protected]>
1 parent 892cad7 commit b161b57

File tree

1 file changed

+4
-16
lines changed

1 file changed

+4
-16
lines changed

src/go/build/build_test.go

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -486,11 +486,7 @@ func TestImportDirNotExist(t *testing.T) {
486486
testenv.MustHaveGoBuild(t) // really must just have source
487487
ctxt := Default
488488

489-
emptyDir, err := os.MkdirTemp("", t.Name())
490-
if err != nil {
491-
t.Fatal(err)
492-
}
493-
defer os.RemoveAll(emptyDir)
489+
emptyDir := t.TempDir()
494490

495491
ctxt.GOPATH = emptyDir
496492
ctxt.Dir = emptyDir
@@ -624,11 +620,7 @@ func TestImportPackageOutsideModule(t *testing.T) {
624620

625621
// Create a GOPATH in a temporary directory. We don't use testdata
626622
// because it's in GOROOT, which interferes with the module heuristic.
627-
gopath, err := os.MkdirTemp("", "gobuild-notmodule")
628-
if err != nil {
629-
t.Fatal(err)
630-
}
631-
defer os.RemoveAll(gopath)
623+
gopath := t.TempDir()
632624
if err := os.MkdirAll(filepath.Join(gopath, "src/example.com/p"), 0777); err != nil {
633625
t.Fatal(err)
634626
}
@@ -688,11 +680,7 @@ func TestIssue23594(t *testing.T) {
688680
// Verifies golang.org/issue/34752.
689681
func TestMissingImportErrorRepetition(t *testing.T) {
690682
testenv.MustHaveGoBuild(t) // need 'go list' internally
691-
tmp, err := os.MkdirTemp("", "")
692-
if err != nil {
693-
t.Fatal(err)
694-
}
695-
defer os.RemoveAll(tmp)
683+
tmp := t.TempDir()
696684
if err := os.WriteFile(filepath.Join(tmp, "go.mod"), []byte("module m"), 0666); err != nil {
697685
t.Fatal(err)
698686
}
@@ -707,7 +695,7 @@ func TestMissingImportErrorRepetition(t *testing.T) {
707695
ctxt.Dir = tmp
708696

709697
pkgPath := "example.com/hello"
710-
_, err = ctxt.Import(pkgPath, tmp, FindOnly)
698+
_, err := ctxt.Import(pkgPath, tmp, FindOnly)
711699
if err == nil {
712700
t.Fatal("unexpected success")
713701
}

0 commit comments

Comments
 (0)