@@ -11,7 +11,6 @@ import (
11
11
"internal/testenv"
12
12
"io"
13
13
"io/fs"
14
- "os"
15
14
. "os"
16
15
"os/exec"
17
16
"path/filepath"
@@ -29,8 +28,8 @@ import (
29
28
30
29
func TestMain (m * testing.M ) {
31
30
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 )
34
33
Exit (0 )
35
34
}
36
35
@@ -153,15 +152,15 @@ func localTmp() string {
153
152
}
154
153
155
154
func newFile (testName string , t * testing.T ) (f * File ) {
156
- f , err := os . CreateTemp (localTmp (), "_Go_" + testName )
155
+ f , err := CreateTemp (localTmp (), "_Go_" + testName )
157
156
if err != nil {
158
157
t .Fatalf ("TempFile %s: %s" , testName , err )
159
158
}
160
159
return
161
160
}
162
161
163
162
func newDir (testName string , t * testing.T ) (name string ) {
164
- name , err := os . MkdirTemp (localTmp (), "_Go_" + testName )
163
+ name , err := MkdirTemp (localTmp (), "_Go_" + testName )
165
164
if err != nil {
166
165
t .Fatalf ("TempDir %s: %s" , testName , err )
167
166
}
@@ -229,19 +228,19 @@ func TestStatSymlinkLoop(t *testing.T) {
229
228
230
229
defer chtmpdir (t )()
231
230
232
- err := os . Symlink ("x" , "y" )
231
+ err := Symlink ("x" , "y" )
233
232
if err != nil {
234
233
t .Fatal (err )
235
234
}
236
- defer os . Remove ("y" )
235
+ defer Remove ("y" )
237
236
238
- err = os . Symlink ("y" , "x" )
237
+ err = Symlink ("y" , "x" )
239
238
if err != nil {
240
239
t .Fatal (err )
241
240
}
242
- defer os . Remove ("x" )
241
+ defer Remove ("x" )
243
242
244
- _ , err = os . Stat ("x" )
243
+ _ , err = Stat ("x" )
245
244
if _ , ok := err .(* fs.PathError ); ! ok {
246
245
t .Errorf ("expected *PathError, got %T: %v\n " , err , err )
247
246
}
@@ -818,7 +817,7 @@ func TestReaddirStatFailures(t *testing.T) {
818
817
func TestReaddirOfFile (t * testing.T ) {
819
818
t .Parallel ()
820
819
821
- f , err := os . CreateTemp (t .TempDir (), "_Go_ReaddirOfFile" )
820
+ f , err := CreateTemp (t .TempDir (), "_Go_ReaddirOfFile" )
822
821
if err != nil {
823
822
t .Fatal (err )
824
823
}
@@ -908,7 +907,7 @@ func chtmpdir(t *testing.T) func() {
908
907
if err != nil {
909
908
t .Fatalf ("chtmpdir: %v" , err )
910
909
}
911
- d , err := os . MkdirTemp ("" , "test" )
910
+ d , err := MkdirTemp ("" , "test" )
912
911
if err != nil {
913
912
t .Fatalf ("chtmpdir: %v" , err )
914
913
}
@@ -1033,12 +1032,12 @@ func TestRenameOverwriteDest(t *testing.T) {
1033
1032
toData := []byte ("to" )
1034
1033
fromData := []byte ("from" )
1035
1034
1036
- err := os . WriteFile (to , toData , 0777 )
1035
+ err := WriteFile (to , toData , 0777 )
1037
1036
if err != nil {
1038
1037
t .Fatalf ("write file %q failed: %v" , to , err )
1039
1038
}
1040
1039
1041
- err = os . WriteFile (from , fromData , 0777 )
1040
+ err = WriteFile (from , fromData , 0777 )
1042
1041
if err != nil {
1043
1042
t .Fatalf ("write file %q failed: %v" , from , err )
1044
1043
}
@@ -1340,18 +1339,18 @@ func TestTruncateNonexistentFile(t *testing.T) {
1340
1339
1341
1340
assertPathError := func (t testing.TB , path string , err error ) {
1342
1341
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 {
1344
1343
t .Errorf ("got error: %v\n want an ErrNotExist PathError with path %q" , err , path )
1345
1344
}
1346
1345
}
1347
1346
1348
1347
path := filepath .Join (t .TempDir (), "nonexistent" )
1349
1348
1350
- err := os . Truncate (path , 1 )
1349
+ err := Truncate (path , 1 )
1351
1350
assertPathError (t , path , err )
1352
1351
1353
1352
// Truncate shouldn't create any new file.
1354
- _ , err = os . Stat (path )
1353
+ _ , err = Stat (path )
1355
1354
assertPathError (t , path , err )
1356
1355
}
1357
1356
@@ -1415,7 +1414,7 @@ func testChtimes(t *testing.T, name string) {
1415
1414
// the contents are accessed; also, it is set
1416
1415
// whenever mtime is set.
1417
1416
case "netbsd" :
1418
- mounts , _ := os . ReadFile ("/proc/mounts" )
1417
+ mounts , _ := ReadFile ("/proc/mounts" )
1419
1418
if strings .Contains (string (mounts ), "noatime" ) {
1420
1419
t .Logf ("AccessTime didn't go backwards, but see a filesystem mounted noatime; ignoring. Issue 19293." )
1421
1420
} else {
@@ -1487,7 +1486,7 @@ func TestChdirAndGetwd(t *testing.T) {
1487
1486
case "ios" :
1488
1487
dirs = nil
1489
1488
for _ , d := range []string {"d1" , "d2" } {
1490
- dir , err := os . MkdirTemp ("" , d )
1489
+ dir , err := MkdirTemp ("" , d )
1491
1490
if err != nil {
1492
1491
t .Fatalf ("TempDir: %v" , err )
1493
1492
}
@@ -1580,7 +1579,7 @@ func TestProgWideChdir(t *testing.T) {
1580
1579
c <- true
1581
1580
t .Fatalf ("Getwd: %v" , err )
1582
1581
}
1583
- d , err := os . MkdirTemp ("" , "test" )
1582
+ d , err := MkdirTemp ("" , "test" )
1584
1583
if err != nil {
1585
1584
c <- true
1586
1585
t .Fatalf ("TempDir: %v" , err )
@@ -1649,7 +1648,7 @@ func TestSeek(t *testing.T) {
1649
1648
off , err := f .Seek (tt .in , tt .whence )
1650
1649
if off != tt .out || err != nil {
1651
1650
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" )
1653
1652
if strings .Contains (string (mounts ), "reiserfs" ) {
1654
1653
// Reiserfs rejects the big seeks.
1655
1654
t .Skipf ("skipping test known to fail on reiserfs; https://golang.org/issue/91" )
@@ -1949,7 +1948,7 @@ func TestWriteAt(t *testing.T) {
1949
1948
t .Fatalf ("WriteAt 7: %d, %v" , n , err )
1950
1949
}
1951
1950
1952
- b , err := os . ReadFile (f .Name ())
1951
+ b , err := ReadFile (f .Name ())
1953
1952
if err != nil {
1954
1953
t .Fatalf ("ReadFile %s: %v" , f .Name (), err )
1955
1954
}
@@ -1999,7 +1998,7 @@ func writeFile(t *testing.T, fname string, flag int, text string) string {
1999
1998
t .Fatalf ("WriteString: %d, %v" , n , err )
2000
1999
}
2001
2000
f .Close ()
2002
- data , err := os . ReadFile (fname )
2001
+ data , err := ReadFile (fname )
2003
2002
if err != nil {
2004
2003
t .Fatalf ("ReadFile: %v" , err )
2005
2004
}
@@ -2332,7 +2331,7 @@ func TestLongPath(t *testing.T) {
2332
2331
t .Fatalf ("MkdirAll failed: %v" , err )
2333
2332
}
2334
2333
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 {
2336
2335
t .Fatalf ("os.WriteFile() failed: %v" , err )
2337
2336
}
2338
2337
if err := Rename (sizedTempDir + "/foo.txt" , sizedTempDir + "/bar.txt" ); err != nil {
@@ -2529,7 +2528,7 @@ func TestRemoveAllRace(t *testing.T) {
2529
2528
2530
2529
n := runtime .GOMAXPROCS (16 )
2531
2530
defer runtime .GOMAXPROCS (n )
2532
- root , err := os . MkdirTemp ("" , "issue" )
2531
+ root , err := MkdirTemp ("" , "issue" )
2533
2532
if err != nil {
2534
2533
t .Fatal (err )
2535
2534
}
@@ -2666,7 +2665,7 @@ func TestUserHomeDir(t *testing.T) {
2666
2665
2667
2666
fi , err := Stat (dir )
2668
2667
if err != nil {
2669
- if os . IsNotExist (err ) {
2668
+ if IsNotExist (err ) {
2670
2669
// The user's home directory has a well-defined location, but does not
2671
2670
// exist. (Maybe nothing has written to it yet? That could happen, for
2672
2671
// example, on minimal VM images used for CI testing.)
@@ -2751,7 +2750,7 @@ func TestReaddirSmallSeek(t *testing.T) {
2751
2750
}
2752
2751
}
2753
2752
2754
- // isDeadlineExceeded reports whether err is or wraps os. ErrDeadlineExceeded.
2753
+ // isDeadlineExceeded reports whether err is or wraps ErrDeadlineExceeded.
2755
2754
// We also check that the error has a Timeout method that returns true.
2756
2755
func isDeadlineExceeded (err error ) bool {
2757
2756
if ! IsTimeout (err ) {
@@ -2861,7 +2860,7 @@ func TestDirFS(t *testing.T) {
2861
2860
func TestDirFSRootDir (t * testing.T ) {
2862
2861
t .Parallel ()
2863
2862
2864
- cwd , err := os . Getwd ()
2863
+ cwd , err := Getwd ()
2865
2864
if err != nil {
2866
2865
t .Fatal (err )
2867
2866
}
@@ -2882,7 +2881,7 @@ func TestDirFSEmptyDir(t *testing.T) {
2882
2881
t .Parallel ()
2883
2882
2884
2883
d := DirFS ("" )
2885
- cwd , _ := os . Getwd ()
2884
+ cwd , _ := Getwd ()
2886
2885
for _ , path := range []string {
2887
2886
"testdata/dirfs/a" , // not DirFS(".")
2888
2887
filepath .ToSlash (cwd ) + "/testdata/dirfs/a" , // not DirFS("/")
@@ -2901,14 +2900,14 @@ func TestDirFSPathsValid(t *testing.T) {
2901
2900
t .Parallel ()
2902
2901
2903
2902
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 {
2905
2904
t .Fatal (err )
2906
2905
}
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 {
2908
2907
t .Fatal (err )
2909
2908
}
2910
2909
2911
- fsys := os . DirFS (d )
2910
+ fsys := DirFS (d )
2912
2911
err := fs .WalkDir (fsys , "." , func (path string , e fs.DirEntry , err error ) error {
2913
2912
if fs .ValidPath (e .Name ()) {
2914
2913
t .Logf ("%q ok" , e .Name ())
0 commit comments