Skip to content

Commit b441eb3

Browse files
ianlancetaylorgopherbot
authored andcommitted
os: remove mixed dot- and non-dot- imports in tests
Some test files imported "os" twice, once with a dot and once without. Consolidate on importing with a dot. Change-Id: I1db31053dff9dee19a6bdfc263c7e7ef0c15ee42 Reviewed-on: https://go-review.googlesource.com/c/go/+/479995 Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> Reviewed-by: Robert Griesemer <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent f57f02f commit b441eb3

File tree

4 files changed

+43
-47
lines changed

4 files changed

+43
-47
lines changed

src/os/os_test.go

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"internal/testenv"
1212
"io"
1313
"io/fs"
14-
"os"
1514
. "os"
1615
"os/exec"
1716
"path/filepath"
@@ -29,8 +28,8 @@ import (
2928

3029
func TestMain(m *testing.M) {
3130
if Getenv("GO_OS_TEST_DRAIN_STDIN") == "1" {
32-
os.Stdout.Close()
33-
io.Copy(io.Discard, os.Stdin)
31+
Stdout.Close()
32+
io.Copy(io.Discard, Stdin)
3433
Exit(0)
3534
}
3635

@@ -153,15 +152,15 @@ func localTmp() string {
153152
}
154153

155154
func newFile(testName string, t *testing.T) (f *File) {
156-
f, err := os.CreateTemp(localTmp(), "_Go_"+testName)
155+
f, err := CreateTemp(localTmp(), "_Go_"+testName)
157156
if err != nil {
158157
t.Fatalf("TempFile %s: %s", testName, err)
159158
}
160159
return
161160
}
162161

163162
func newDir(testName string, t *testing.T) (name string) {
164-
name, err := os.MkdirTemp(localTmp(), "_Go_"+testName)
163+
name, err := MkdirTemp(localTmp(), "_Go_"+testName)
165164
if err != nil {
166165
t.Fatalf("TempDir %s: %s", testName, err)
167166
}
@@ -229,19 +228,19 @@ func TestStatSymlinkLoop(t *testing.T) {
229228

230229
defer chtmpdir(t)()
231230

232-
err := os.Symlink("x", "y")
231+
err := Symlink("x", "y")
233232
if err != nil {
234233
t.Fatal(err)
235234
}
236-
defer os.Remove("y")
235+
defer Remove("y")
237236

238-
err = os.Symlink("y", "x")
237+
err = Symlink("y", "x")
239238
if err != nil {
240239
t.Fatal(err)
241240
}
242-
defer os.Remove("x")
241+
defer Remove("x")
243242

244-
_, err = os.Stat("x")
243+
_, err = Stat("x")
245244
if _, ok := err.(*fs.PathError); !ok {
246245
t.Errorf("expected *PathError, got %T: %v\n", err, err)
247246
}
@@ -818,7 +817,7 @@ func TestReaddirStatFailures(t *testing.T) {
818817
func TestReaddirOfFile(t *testing.T) {
819818
t.Parallel()
820819

821-
f, err := os.CreateTemp(t.TempDir(), "_Go_ReaddirOfFile")
820+
f, err := CreateTemp(t.TempDir(), "_Go_ReaddirOfFile")
822821
if err != nil {
823822
t.Fatal(err)
824823
}
@@ -908,7 +907,7 @@ func chtmpdir(t *testing.T) func() {
908907
if err != nil {
909908
t.Fatalf("chtmpdir: %v", err)
910909
}
911-
d, err := os.MkdirTemp("", "test")
910+
d, err := MkdirTemp("", "test")
912911
if err != nil {
913912
t.Fatalf("chtmpdir: %v", err)
914913
}
@@ -1033,12 +1032,12 @@ func TestRenameOverwriteDest(t *testing.T) {
10331032
toData := []byte("to")
10341033
fromData := []byte("from")
10351034

1036-
err := os.WriteFile(to, toData, 0777)
1035+
err := WriteFile(to, toData, 0777)
10371036
if err != nil {
10381037
t.Fatalf("write file %q failed: %v", to, err)
10391038
}
10401039

1041-
err = os.WriteFile(from, fromData, 0777)
1040+
err = WriteFile(from, fromData, 0777)
10421041
if err != nil {
10431042
t.Fatalf("write file %q failed: %v", from, err)
10441043
}
@@ -1340,18 +1339,18 @@ func TestTruncateNonexistentFile(t *testing.T) {
13401339

13411340
assertPathError := func(t testing.TB, path string, err error) {
13421341
t.Helper()
1343-
if pe, ok := err.(*os.PathError); !ok || !os.IsNotExist(err) || pe.Path != path {
1342+
if pe, ok := err.(*PathError); !ok || !IsNotExist(err) || pe.Path != path {
13441343
t.Errorf("got error: %v\nwant an ErrNotExist PathError with path %q", err, path)
13451344
}
13461345
}
13471346

13481347
path := filepath.Join(t.TempDir(), "nonexistent")
13491348

1350-
err := os.Truncate(path, 1)
1349+
err := Truncate(path, 1)
13511350
assertPathError(t, path, err)
13521351

13531352
// Truncate shouldn't create any new file.
1354-
_, err = os.Stat(path)
1353+
_, err = Stat(path)
13551354
assertPathError(t, path, err)
13561355
}
13571356

@@ -1415,7 +1414,7 @@ func testChtimes(t *testing.T, name string) {
14151414
// the contents are accessed; also, it is set
14161415
// whenever mtime is set.
14171416
case "netbsd":
1418-
mounts, _ := os.ReadFile("/proc/mounts")
1417+
mounts, _ := ReadFile("/proc/mounts")
14191418
if strings.Contains(string(mounts), "noatime") {
14201419
t.Logf("AccessTime didn't go backwards, but see a filesystem mounted noatime; ignoring. Issue 19293.")
14211420
} else {
@@ -1487,7 +1486,7 @@ func TestChdirAndGetwd(t *testing.T) {
14871486
case "ios":
14881487
dirs = nil
14891488
for _, d := range []string{"d1", "d2"} {
1490-
dir, err := os.MkdirTemp("", d)
1489+
dir, err := MkdirTemp("", d)
14911490
if err != nil {
14921491
t.Fatalf("TempDir: %v", err)
14931492
}
@@ -1580,7 +1579,7 @@ func TestProgWideChdir(t *testing.T) {
15801579
c <- true
15811580
t.Fatalf("Getwd: %v", err)
15821581
}
1583-
d, err := os.MkdirTemp("", "test")
1582+
d, err := MkdirTemp("", "test")
15841583
if err != nil {
15851584
c <- true
15861585
t.Fatalf("TempDir: %v", err)
@@ -1649,7 +1648,7 @@ func TestSeek(t *testing.T) {
16491648
off, err := f.Seek(tt.in, tt.whence)
16501649
if off != tt.out || err != nil {
16511650
if e, ok := err.(*PathError); ok && e.Err == syscall.EINVAL && tt.out > 1<<32 && runtime.GOOS == "linux" {
1652-
mounts, _ := os.ReadFile("/proc/mounts")
1651+
mounts, _ := ReadFile("/proc/mounts")
16531652
if strings.Contains(string(mounts), "reiserfs") {
16541653
// Reiserfs rejects the big seeks.
16551654
t.Skipf("skipping test known to fail on reiserfs; https://golang.org/issue/91")
@@ -1949,7 +1948,7 @@ func TestWriteAt(t *testing.T) {
19491948
t.Fatalf("WriteAt 7: %d, %v", n, err)
19501949
}
19511950

1952-
b, err := os.ReadFile(f.Name())
1951+
b, err := ReadFile(f.Name())
19531952
if err != nil {
19541953
t.Fatalf("ReadFile %s: %v", f.Name(), err)
19551954
}
@@ -1999,7 +1998,7 @@ func writeFile(t *testing.T, fname string, flag int, text string) string {
19991998
t.Fatalf("WriteString: %d, %v", n, err)
20001999
}
20012000
f.Close()
2002-
data, err := os.ReadFile(fname)
2001+
data, err := ReadFile(fname)
20032002
if err != nil {
20042003
t.Fatalf("ReadFile: %v", err)
20052004
}
@@ -2332,7 +2331,7 @@ func TestLongPath(t *testing.T) {
23322331
t.Fatalf("MkdirAll failed: %v", err)
23332332
}
23342333
data := []byte("hello world\n")
2335-
if err := os.WriteFile(sizedTempDir+"/foo.txt", data, 0644); err != nil {
2334+
if err := WriteFile(sizedTempDir+"/foo.txt", data, 0644); err != nil {
23362335
t.Fatalf("os.WriteFile() failed: %v", err)
23372336
}
23382337
if err := Rename(sizedTempDir+"/foo.txt", sizedTempDir+"/bar.txt"); err != nil {
@@ -2529,7 +2528,7 @@ func TestRemoveAllRace(t *testing.T) {
25292528

25302529
n := runtime.GOMAXPROCS(16)
25312530
defer runtime.GOMAXPROCS(n)
2532-
root, err := os.MkdirTemp("", "issue")
2531+
root, err := MkdirTemp("", "issue")
25332532
if err != nil {
25342533
t.Fatal(err)
25352534
}
@@ -2666,7 +2665,7 @@ func TestUserHomeDir(t *testing.T) {
26662665

26672666
fi, err := Stat(dir)
26682667
if err != nil {
2669-
if os.IsNotExist(err) {
2668+
if IsNotExist(err) {
26702669
// The user's home directory has a well-defined location, but does not
26712670
// exist. (Maybe nothing has written to it yet? That could happen, for
26722671
// example, on minimal VM images used for CI testing.)
@@ -2751,7 +2750,7 @@ func TestReaddirSmallSeek(t *testing.T) {
27512750
}
27522751
}
27532752

2754-
// isDeadlineExceeded reports whether err is or wraps os.ErrDeadlineExceeded.
2753+
// isDeadlineExceeded reports whether err is or wraps ErrDeadlineExceeded.
27552754
// We also check that the error has a Timeout method that returns true.
27562755
func isDeadlineExceeded(err error) bool {
27572756
if !IsTimeout(err) {
@@ -2861,7 +2860,7 @@ func TestDirFS(t *testing.T) {
28612860
func TestDirFSRootDir(t *testing.T) {
28622861
t.Parallel()
28632862

2864-
cwd, err := os.Getwd()
2863+
cwd, err := Getwd()
28652864
if err != nil {
28662865
t.Fatal(err)
28672866
}
@@ -2882,7 +2881,7 @@ func TestDirFSEmptyDir(t *testing.T) {
28822881
t.Parallel()
28832882

28842883
d := DirFS("")
2885-
cwd, _ := os.Getwd()
2884+
cwd, _ := Getwd()
28862885
for _, path := range []string{
28872886
"testdata/dirfs/a", // not DirFS(".")
28882887
filepath.ToSlash(cwd) + "/testdata/dirfs/a", // not DirFS("/")
@@ -2901,14 +2900,14 @@ func TestDirFSPathsValid(t *testing.T) {
29012900
t.Parallel()
29022901

29032902
d := t.TempDir()
2904-
if err := os.WriteFile(filepath.Join(d, "control.txt"), []byte(string("Hello, world!")), 0644); err != nil {
2903+
if err := WriteFile(filepath.Join(d, "control.txt"), []byte(string("Hello, world!")), 0644); err != nil {
29052904
t.Fatal(err)
29062905
}
2907-
if err := os.WriteFile(filepath.Join(d, `e:xperi\ment.txt`), []byte(string("Hello, colon and backslash!")), 0644); err != nil {
2906+
if err := WriteFile(filepath.Join(d, `e:xperi\ment.txt`), []byte(string("Hello, colon and backslash!")), 0644); err != nil {
29082907
t.Fatal(err)
29092908
}
29102909

2911-
fsys := os.DirFS(d)
2910+
fsys := DirFS(d)
29122911
err := fs.WalkDir(fsys, ".", func(path string, e fs.DirEntry, err error) error {
29132912
if fs.ValidPath(e.Name()) {
29142913
t.Logf("%q ok", e.Name())

src/os/os_unix_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ package os_test
88

99
import (
1010
"io"
11-
"os"
1211
. "os"
1312
"path/filepath"
1413
"runtime"
@@ -196,7 +195,7 @@ func TestReaddirRemoveRace(t *testing.T) {
196195
}
197196
dir := newDir("TestReaddirRemoveRace", t)
198197
defer RemoveAll(dir)
199-
if err := os.WriteFile(filepath.Join(dir, "some-file"), []byte("hello"), 0644); err != nil {
198+
if err := WriteFile(filepath.Join(dir, "some-file"), []byte("hello"), 0644); err != nil {
200199
t.Fatal(err)
201200
}
202201
d, err := Open(dir)

src/os/readfrom_linux_test.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"io"
1313
"math/rand"
1414
"net"
15-
"os"
1615
. "os"
1716
"path/filepath"
1817
"runtime"
@@ -85,13 +84,13 @@ func TestCopyFileRange(t *testing.T) {
8584
t.Run("CopyFileItself", func(t *testing.T) {
8685
hook := hookCopyFileRange(t)
8786

88-
f, err := os.CreateTemp("", "file-readfrom-itself-test")
87+
f, err := CreateTemp("", "file-readfrom-itself-test")
8988
if err != nil {
9089
t.Fatalf("failed to create tmp file: %v", err)
9190
}
9291
t.Cleanup(func() {
9392
f.Close()
94-
os.Remove(f.Name())
93+
Remove(f.Name())
9594
})
9695

9796
data := []byte("hello world!")
@@ -231,7 +230,7 @@ func TestCopyFileRange(t *testing.T) {
231230
})
232231
t.Run("Nil", func(t *testing.T) {
233232
var nilFile *File
234-
anyFile, err := os.CreateTemp("", "")
233+
anyFile, err := CreateTemp("", "")
235234
if err != nil {
236235
t.Fatal(err)
237236
}
@@ -721,17 +720,17 @@ func TestProcCopy(t *testing.T) {
721720
t.Parallel()
722721

723722
const cmdlineFile = "/proc/self/cmdline"
724-
cmdline, err := os.ReadFile(cmdlineFile)
723+
cmdline, err := ReadFile(cmdlineFile)
725724
if err != nil {
726725
t.Skipf("can't read /proc file: %v", err)
727726
}
728-
in, err := os.Open(cmdlineFile)
727+
in, err := Open(cmdlineFile)
729728
if err != nil {
730729
t.Fatal(err)
731730
}
732731
defer in.Close()
733732
outFile := filepath.Join(t.TempDir(), "cmdline")
734-
out, err := os.Create(outFile)
733+
out, err := Create(outFile)
735734
if err != nil {
736735
t.Fatal(err)
737736
}
@@ -741,7 +740,7 @@ func TestProcCopy(t *testing.T) {
741740
if err := out.Close(); err != nil {
742741
t.Fatal(err)
743742
}
744-
copy, err := os.ReadFile(outFile)
743+
copy, err := ReadFile(outFile)
745744
if err != nil {
746745
t.Fatal(err)
747746
}
@@ -766,7 +765,7 @@ func testGetPollFromReader(t *testing.T, proto string) {
766765
t.Fatalf("server SyscallConn error: %v", err)
767766
}
768767
if err = rc.Control(func(fd uintptr) {
769-
pfd := os.GetPollFDForTest(server)
768+
pfd := GetPollFDForTest(server)
770769
if pfd == nil {
771770
t.Fatalf("GetPollFDForTest didn't return poll.FD")
772771
}

src/os/removeall_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"bytes"
99
"fmt"
1010
"internal/testenv"
11-
"os"
1211
. "os"
1312
"path/filepath"
1413
"runtime"
@@ -165,7 +164,7 @@ func TestRemoveAllLongPath(t *testing.T) {
165164
t.Fatalf("Could not get wd: %s", err)
166165
}
167166

168-
startPath, err := os.MkdirTemp("", "TestRemoveAllLongPath-")
167+
startPath, err := MkdirTemp("", "TestRemoveAllLongPath-")
169168
if err != nil {
170169
t.Fatalf("Could not create TempDir: %s", err)
171170
}
@@ -207,7 +206,7 @@ func TestRemoveAllDot(t *testing.T) {
207206
if err != nil {
208207
t.Fatalf("Could not get wd: %s", err)
209208
}
210-
tempDir, err := os.MkdirTemp("", "TestRemoveAllDot-")
209+
tempDir, err := MkdirTemp("", "TestRemoveAllDot-")
211210
if err != nil {
212211
t.Fatalf("Could not create TempDir: %s", err)
213212
}
@@ -407,7 +406,7 @@ func TestRemoveAllWithMoreErrorThanReqSize(t *testing.T) {
407406
}
408407

409408
// Make the parent directory read-only. On some platforms, this is what
410-
// prevents os.Remove from removing the files within that directory.
409+
// prevents Remove from removing the files within that directory.
411410
if err := Chmod(path, 0555); err != nil {
412411
t.Fatal(err)
413412
}

0 commit comments

Comments
 (0)