@@ -486,11 +486,7 @@ func TestImportDirNotExist(t *testing.T) {
486
486
testenv .MustHaveGoBuild (t ) // really must just have source
487
487
ctxt := Default
488
488
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 ()
494
490
495
491
ctxt .GOPATH = emptyDir
496
492
ctxt .Dir = emptyDir
@@ -624,11 +620,7 @@ func TestImportPackageOutsideModule(t *testing.T) {
624
620
625
621
// Create a GOPATH in a temporary directory. We don't use testdata
626
622
// 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 ()
632
624
if err := os .MkdirAll (filepath .Join (gopath , "src/example.com/p" ), 0777 ); err != nil {
633
625
t .Fatal (err )
634
626
}
@@ -688,11 +680,7 @@ func TestIssue23594(t *testing.T) {
688
680
// Verifies golang.org/issue/34752.
689
681
func TestMissingImportErrorRepetition (t * testing.T ) {
690
682
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 ()
696
684
if err := os .WriteFile (filepath .Join (tmp , "go.mod" ), []byte ("module m" ), 0666 ); err != nil {
697
685
t .Fatal (err )
698
686
}
@@ -707,7 +695,7 @@ func TestMissingImportErrorRepetition(t *testing.T) {
707
695
ctxt .Dir = tmp
708
696
709
697
pkgPath := "example.com/hello"
710
- _ , err = ctxt .Import (pkgPath , tmp , FindOnly )
698
+ _ , err : = ctxt .Import (pkgPath , tmp , FindOnly )
711
699
if err == nil {
712
700
t .Fatal ("unexpected success" )
713
701
}
0 commit comments