Commit 6c9b655a authored by Ian Lance Taylor's avatar Ian Lance Taylor Committed by Tobias Klauser

os: don't create files in local directory

Also, use a random temporary directory rather than os.TempDir.  Defer
removal of existing random temporary directories.

Change-Id: Id7549031cdf78a2bab28c07b6eeff621bdf6e49c
Reviewed-on: https://go-review.googlesource.com/c/146457
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarTobias Klauser <tobias.klauser@gmail.com>
parent 01f0dbba
...@@ -8,18 +8,23 @@ import ( ...@@ -8,18 +8,23 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
. "os" . "os"
"path/filepath"
"runtime" "runtime"
"strings" "strings"
"testing" "testing"
) )
func TestRemoveAll(t *testing.T) { func TestRemoveAll(t *testing.T) {
tmpDir := TempDir() tmpDir, err := ioutil.TempDir("", "TestRemoveAll-")
// Work directory. if err != nil {
file := "file" t.Fatal(err)
path := tmpDir + "/_TestRemoveAll_" }
fpath := path + "/file" defer RemoveAll(tmpDir)
dpath := path + "/dir"
file := filepath.Join(tmpDir, "file")
path := filepath.Join(tmpDir, "_TestRemoveAll_")
fpath := filepath.Join(path, "file")
dpath := filepath.Join(path, "dir")
// Make a regular file and remove // Make a regular file and remove
fd, err := Create(file) fd, err := Create(file)
...@@ -127,9 +132,13 @@ func TestRemoveAllLarge(t *testing.T) { ...@@ -127,9 +132,13 @@ func TestRemoveAllLarge(t *testing.T) {
t.Skip("skipping in short mode") t.Skip("skipping in short mode")
} }
tmpDir := TempDir() tmpDir, err := ioutil.TempDir("", "TestRemoveAll-")
// Work directory. if err != nil {
path := tmpDir + "/_TestRemoveAllLarge_" t.Fatal(err)
}
defer RemoveAll(tmpDir)
path := filepath.Join(tmpDir, "_TestRemoveAllLarge_")
// Make directory with 1000 files and remove. // Make directory with 1000 files and remove.
if err := MkdirAll(path, 0777); err != nil { if err := MkdirAll(path, 0777); err != nil {
...@@ -168,6 +177,8 @@ func TestRemoveAllLongPath(t *testing.T) { ...@@ -168,6 +177,8 @@ func TestRemoveAllLongPath(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("Could not create TempDir: %s", err) t.Fatalf("Could not create TempDir: %s", err)
} }
defer RemoveAll(startPath)
err = Chdir(startPath) err = Chdir(startPath)
if err != nil { if err != nil {
t.Fatalf("Could not chdir %s: %s", startPath, err) t.Fatalf("Could not chdir %s: %s", startPath, err)
...@@ -215,6 +226,8 @@ func TestRemoveAllDot(t *testing.T) { ...@@ -215,6 +226,8 @@ func TestRemoveAllDot(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("Could not create TempDir: %s", err) t.Fatalf("Could not create TempDir: %s", err)
} }
defer RemoveAll(tempDir)
err = Chdir(tempDir) err = Chdir(tempDir)
if err != nil { if err != nil {
t.Fatalf("Could not chdir to tempdir: %s", err) t.Fatalf("Could not chdir to tempdir: %s", err)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment