mirror of
https://github.com/golang/go
synced 2024-11-26 13:08:08 -07:00
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 <iant@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Tobias Klauser <tobias.klauser@gmail.com>
This commit is contained in:
parent
892cad7a9b
commit
b161b57c3f
@ -486,11 +486,7 @@ func TestImportDirNotExist(t *testing.T) {
|
|||||||
testenv.MustHaveGoBuild(t) // really must just have source
|
testenv.MustHaveGoBuild(t) // really must just have source
|
||||||
ctxt := Default
|
ctxt := Default
|
||||||
|
|
||||||
emptyDir, err := os.MkdirTemp("", t.Name())
|
emptyDir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(emptyDir)
|
|
||||||
|
|
||||||
ctxt.GOPATH = emptyDir
|
ctxt.GOPATH = emptyDir
|
||||||
ctxt.Dir = 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
|
// Create a GOPATH in a temporary directory. We don't use testdata
|
||||||
// because it's in GOROOT, which interferes with the module heuristic.
|
// because it's in GOROOT, which interferes with the module heuristic.
|
||||||
gopath, err := os.MkdirTemp("", "gobuild-notmodule")
|
gopath := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(gopath)
|
|
||||||
if err := os.MkdirAll(filepath.Join(gopath, "src/example.com/p"), 0777); err != nil {
|
if err := os.MkdirAll(filepath.Join(gopath, "src/example.com/p"), 0777); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -688,11 +680,7 @@ func TestIssue23594(t *testing.T) {
|
|||||||
// Verifies golang.org/issue/34752.
|
// Verifies golang.org/issue/34752.
|
||||||
func TestMissingImportErrorRepetition(t *testing.T) {
|
func TestMissingImportErrorRepetition(t *testing.T) {
|
||||||
testenv.MustHaveGoBuild(t) // need 'go list' internally
|
testenv.MustHaveGoBuild(t) // need 'go list' internally
|
||||||
tmp, err := os.MkdirTemp("", "")
|
tmp := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(tmp)
|
|
||||||
if err := os.WriteFile(filepath.Join(tmp, "go.mod"), []byte("module m"), 0666); err != nil {
|
if err := os.WriteFile(filepath.Join(tmp, "go.mod"), []byte("module m"), 0666); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -707,7 +695,7 @@ func TestMissingImportErrorRepetition(t *testing.T) {
|
|||||||
ctxt.Dir = tmp
|
ctxt.Dir = tmp
|
||||||
|
|
||||||
pkgPath := "example.com/hello"
|
pkgPath := "example.com/hello"
|
||||||
_, err = ctxt.Import(pkgPath, tmp, FindOnly)
|
_, err := ctxt.Import(pkgPath, tmp, FindOnly)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("unexpected success")
|
t.Fatal("unexpected success")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user