Skip to content

Commit

Permalink
testing: clean up remaining TempDir issues from CL 231958
Browse files Browse the repository at this point in the history
Updates golang#38850

Change-Id: I33f48762f5520eb0c0a841d8ca1ccdd65ecc20c8
Reviewed-on: https://go-review.googlesource.com/c/go/+/234583
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
  • Loading branch information
Bryan C. Mills committed May 19, 2020
1 parent 2dbbc86 commit 1361738
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
7 changes: 4 additions & 3 deletions src/math/big/link_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ func TestLinkerGC(t *testing.T) {
t.Skip("skipping in short mode")
}
t.Parallel()
tmp := t.TempDir()
goBin := testenv.GoToolPath(t)
goFile := filepath.Join(t.TempDir(), "x.go")
goFile := filepath.Join(tmp, "x.go")
file := []byte(`package main
import _ "math/big"
func main() {}
Expand All @@ -30,13 +31,13 @@ func main() {}
t.Fatal(err)
}
cmd := exec.Command(goBin, "build", "-o", "x.exe", "x.go")
cmd.Dir = t.TempDir()
cmd.Dir = tmp
if out, err := cmd.CombinedOutput(); err != nil {
t.Fatalf("compile: %v, %s", err, out)
}

cmd = exec.Command(goBin, "tool", "nm", "x.exe")
cmd.Dir = t.TempDir()
cmd.Dir = tmp
nm, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("nm: %v, %s", err, nm)
Expand Down
5 changes: 3 additions & 2 deletions src/os/readfrom_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,15 @@ func newCopyFileRangeTest(t *testing.T, size int64) (dst, src *File, data []byte
t.Helper()

hook = hookCopyFileRange(t)
tmp := t.TempDir()

src, err := Create(filepath.Join(t.TempDir(), "src"))
src, err := Create(filepath.Join(tmp, "src"))
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { src.Close() })

dst, err = Create(filepath.Join(t.TempDir(), "dst"))
dst, err = Create(filepath.Join(tmp, "dst"))
if err != nil {
t.Fatal(err)
}
Expand Down
5 changes: 2 additions & 3 deletions src/testing/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -822,11 +822,10 @@ var tempDirReplacer struct {
}

// TempDir returns a temporary directory for the test to use.
// It is lazily created on first access, and calls t.Fatal if the directory
// creation fails.
// Subsequent calls to t.TempDir return the same directory.
// The directory is automatically removed by Cleanup when the test and
// all its subtests complete.
// Each subsequent call to t.TempDir returns a unique directory;
// if the directory creation fails, TempDir terminates the test by calling Fatal.
func (c *common) TempDir() string {
// Use a single parent directory for all the temporary directories
// created by a test, each numbered sequentially.
Expand Down

0 comments on commit 1361738

Please sign in to comment.