]> Cypherpunks repositories - gostls13.git/commitdiff
go/build: replace os.MkdirTemp with T.TempDir
authorManlio Perillo <manlio.perillo@gmail.com>
Tue, 13 Apr 2021 10:25:19 +0000 (12:25 +0200)
committerIan Lance Taylor <iant@golang.org>
Wed, 14 Apr 2021 19:38:22 +0000 (19:38 +0000)
Updates #45402

Change-Id: Ic2f696837034de17333a6a53127a4bfd301e96a4
Reviewed-on: https://go-review.googlesource.com/c/go/+/309354
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Tobias Klauser <tobias.klauser@gmail.com>

src/go/build/build_test.go

index 6529b6e47efe3b690d00fabaf29e52035188fc45..dcd845825250bac289e06064707a4843f43cfa4a 100644 (file)
@@ -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")
        }