mirror of
https://github.com/rwinkhart/sys.git
synced 2026-09-05 08:37:31 -04:00
all: use t.TempDir in tests
This removes all usage of ioutil.TempDir in tests (and a few cases of os.TempDir as well, while we're at it), which simplifies test cleanup a lot. Compile tested (go test -c) for most platforms (except zos). Change-Id: I9178f5ec615c0a6cfef36e8de78c6b72e055b7cb Reviewed-on: https://go-review.googlesource.com/c/sys/+/526297 Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: qiulaidongfeng <2645477756@qq.com> Auto-Submit: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
committed by
Gopher Robot
parent
0514fecd90
commit
0e97d69659
+5
-15
@@ -21,14 +21,16 @@ import (
|
||||
)
|
||||
|
||||
func TestMmap(t *testing.T) {
|
||||
tmpdir := mktmpdir(t)
|
||||
filename := filepath.Join(filepath.Join(tmpdir, "testdata"), "memmapped_file")
|
||||
tmpdir := filepath.Join(t.TempDir(), "testdata")
|
||||
if err := os.Mkdir(tmpdir, 0700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
filename := filepath.Join(tmpdir, "memmapped_file")
|
||||
destination, err := os.Create(filename)
|
||||
if err != nil {
|
||||
t.Fatal("os.Create:", err)
|
||||
return
|
||||
}
|
||||
defer os.RemoveAll(tmpdir)
|
||||
|
||||
fmt.Fprintf(destination, "%s\n", "0 <- Flipped between 0 and 1 when test runs successfully")
|
||||
fmt.Fprintf(destination, "%s\n", "//Do not change contents - mmap test relies on this")
|
||||
@@ -73,15 +75,3 @@ func TestMmap(t *testing.T) {
|
||||
t.Fatalf("Munmap: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func mktmpdir(t *testing.T) string {
|
||||
tmpdir, err := ioutil.TempDir("", "memmapped_file")
|
||||
if err != nil {
|
||||
t.Fatal("mktmpdir:", err)
|
||||
}
|
||||
if err := os.Mkdir(filepath.Join(tmpdir, "testdata"), 0700); err != nil {
|
||||
os.RemoveAll(tmpdir)
|
||||
t.Fatal("mktmpdir:", err)
|
||||
}
|
||||
return tmpdir
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user