From: Manlio Perillo Date: Tue, 13 Apr 2021 10:25:19 +0000 (+0200) Subject: go/build: replace os.MkdirTemp with T.TempDir X-Git-Tag: go1.17beta1~648 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=b161b57c3f;p=gostls13.git 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 Reviewed-by: Ian Lance Taylor Trust: Tobias Klauser --- diff --git a/src/go/build/build_test.go b/src/go/build/build_test.go index 6529b6e47e..dcd8458252 100644 --- a/src/go/build/build_test.go +++ b/src/go/build/build_test.go @@ -486,11 +486,7 @@ func TestImportDirNotExist(t *testing.T) { testenv.MustHaveGoBuild(t) // really must just have source ctxt := Default - emptyDir, err := os.MkdirTemp("", t.Name()) - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(emptyDir) + emptyDir := t.TempDir() ctxt.GOPATH = emptyDir ctxt.Dir = emptyDir @@ -624,11 +620,7 @@ func TestImportPackageOutsideModule(t *testing.T) { // Create a GOPATH in a temporary directory. We don't use testdata // because it's in GOROOT, which interferes with the module heuristic. - gopath, err := os.MkdirTemp("", "gobuild-notmodule") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(gopath) + gopath := t.TempDir() if err := os.MkdirAll(filepath.Join(gopath, "src/example.com/p"), 0777); err != nil { t.Fatal(err) } @@ -688,11 +680,7 @@ func TestIssue23594(t *testing.T) { // Verifies golang.org/issue/34752. func TestMissingImportErrorRepetition(t *testing.T) { testenv.MustHaveGoBuild(t) // need 'go list' internally - tmp, err := os.MkdirTemp("", "") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmp) + tmp := t.TempDir() if err := os.WriteFile(filepath.Join(tmp, "go.mod"), []byte("module m"), 0666); err != nil { t.Fatal(err) } @@ -707,7 +695,7 @@ func TestMissingImportErrorRepetition(t *testing.T) { ctxt.Dir = tmp pkgPath := "example.com/hello" - _, err = ctxt.Import(pkgPath, tmp, FindOnly) + _, err := ctxt.Import(pkgPath, tmp, FindOnly) if err == nil { t.Fatal("unexpected success") }