From ae3ad0ab21d4c42c760332c306722581e09c9ef7 Mon Sep 17 00:00:00 2001 From: KimMachineGun Date: Mon, 30 Nov 2020 02:04:43 +0900 Subject: [PATCH 1/4] all: update references to symbols moved from io/ioutil to io --- misc/android/go_android_exec.go | 2 +- misc/cgo/testcarchive/testdata/libgo6/sigprof.go | 4 ++-- misc/cgo/testsanitizers/testdata/tsan9.go | 4 ++-- misc/linkcheck/linkcheck.go | 4 ++-- src/net/http/fs_test.go | 2 +- src/testing/fstest/testfs.go | 3 +-- test/bench/go1/gob_test.go | 4 ++-- test/bench/go1/gzip_test.go | 5 ++--- test/bench/go1/http_test.go | 4 ++-- test/bench/go1/json_test.go | 3 +-- test/bench/go1/parser_test.go | 3 +-- test/bench/go1/revcomp_test.go | 4 ++-- test/bench/go1/template_test.go | 4 ++-- test/stress/runstress.go | 3 +-- 14 files changed, 22 insertions(+), 27 deletions(-) diff --git a/misc/android/go_android_exec.go b/misc/android/go_android_exec.go index 7aa7fe56fc5e04..35b160fc9f0b04 100644 --- a/misc/android/go_android_exec.go +++ b/misc/android/go_android_exec.go @@ -276,7 +276,7 @@ func adbCopyGoroot() error { if err := syscall.Flock(int(stat.Fd()), syscall.LOCK_EX); err != nil { return err } - s, err := ioutil.ReadAll(stat) + s, err := io.ReadAll(stat) if err != nil { return err } diff --git a/misc/cgo/testcarchive/testdata/libgo6/sigprof.go b/misc/cgo/testcarchive/testdata/libgo6/sigprof.go index 4cb05dc61786ab..31527c59af1213 100644 --- a/misc/cgo/testcarchive/testdata/libgo6/sigprof.go +++ b/misc/cgo/testcarchive/testdata/libgo6/sigprof.go @@ -5,7 +5,7 @@ package main import ( - "io/ioutil" + "io" "runtime/pprof" ) @@ -13,7 +13,7 @@ import "C" //export go_start_profile func go_start_profile() { - pprof.StartCPUProfile(ioutil.Discard) + pprof.StartCPUProfile(io.Discard) } //export go_stop_profile diff --git a/misc/cgo/testsanitizers/testdata/tsan9.go b/misc/cgo/testsanitizers/testdata/tsan9.go index f166d8b495ac45..06304be751b5e2 100644 --- a/misc/cgo/testsanitizers/testdata/tsan9.go +++ b/misc/cgo/testsanitizers/testdata/tsan9.go @@ -44,7 +44,7 @@ void spin() { import "C" import ( - "io/ioutil" + "io" "runtime/pprof" "time" ) @@ -60,7 +60,7 @@ func goSpin() { } func main() { - pprof.StartCPUProfile(ioutil.Discard) + pprof.StartCPUProfile(io.Discard) go C.spin() goSpin() pprof.StopCPUProfile() diff --git a/misc/linkcheck/linkcheck.go b/misc/linkcheck/linkcheck.go index d9bfd2f767eb19..570b430da4f1cb 100644 --- a/misc/linkcheck/linkcheck.go +++ b/misc/linkcheck/linkcheck.go @@ -11,7 +11,7 @@ import ( "errors" "flag" "fmt" - "io/ioutil" + "io" "log" "net/http" "os" @@ -144,7 +144,7 @@ func doCrawl(url string) error { if res.StatusCode != 200 { return errors.New(res.Status) } - slurp, err := ioutil.ReadAll(res.Body) + slurp, err := io.ReadAll(res.Body) res.Body.Close() if err != nil { log.Fatalf("Error reading %s body: %v", url, err) diff --git a/src/net/http/fs_test.go b/src/net/http/fs_test.go index 2499051625081b..f9cfa91d4b03d3 100644 --- a/src/net/http/fs_test.go +++ b/src/net/http/fs_test.go @@ -593,7 +593,7 @@ func TestServeIndexHtml(t *testing.T) { if err != nil { t.Fatal(err) } - b, err := ioutil.ReadAll(res.Body) + b, err := io.ReadAll(res.Body) if err != nil { t.Fatal("reading Body:", err) } diff --git a/src/testing/fstest/testfs.go b/src/testing/fstest/testfs.go index e0ad60a17b6a15..80ca0e9a1d7fde 100644 --- a/src/testing/fstest/testfs.go +++ b/src/testing/fstest/testfs.go @@ -10,7 +10,6 @@ import ( "fmt" "io" "io/fs" - "io/ioutil" "path" "reflect" "sort" @@ -514,7 +513,7 @@ func (t *fsTester) checkFile(file string) { return } - data, err := ioutil.ReadAll(f) + data, err := io.ReadAll(f) if err != nil { f.Close() t.errorf("%s: Open+ReadAll: %v", file, err) diff --git a/test/bench/go1/gob_test.go b/test/bench/go1/gob_test.go index 224beff6801760..f289fcca7c7af2 100644 --- a/test/bench/go1/gob_test.go +++ b/test/bench/go1/gob_test.go @@ -10,7 +10,7 @@ import ( "bytes" "encoding/gob" "encoding/json" - "io/ioutil" + "io" "log" "reflect" "testing" @@ -73,7 +73,7 @@ func gobdec() { } func gobenc() { - if err := gob.NewEncoder(ioutil.Discard).Encode(&gobdata); err != nil { + if err := gob.NewEncoder(io.Discard).Encode(&gobdata); err != nil { panic(err) } } diff --git a/test/bench/go1/gzip_test.go b/test/bench/go1/gzip_test.go index 648eec5d457843..d3f98da11d81d6 100644 --- a/test/bench/go1/gzip_test.go +++ b/test/bench/go1/gzip_test.go @@ -10,7 +10,6 @@ import ( "bytes" gz "compress/gzip" "io" - "io/ioutil" "testing" ) @@ -28,7 +27,7 @@ func init() { } func gzip() { - c := gz.NewWriter(ioutil.Discard) + c := gz.NewWriter(io.Discard) if _, err := c.Write(jsongunz); err != nil { panic(err) } @@ -42,7 +41,7 @@ func gunzip() { if err != nil { panic(err) } - if _, err := io.Copy(ioutil.Discard, r); err != nil { + if _, err := io.Copy(io.Discard, r); err != nil { panic(err) } r.Close() diff --git a/test/bench/go1/http_test.go b/test/bench/go1/http_test.go index 7ece9b2ac54878..08583d635da3a2 100644 --- a/test/bench/go1/http_test.go +++ b/test/bench/go1/http_test.go @@ -6,7 +6,7 @@ package go1 import ( "bytes" - "io/ioutil" + "io" "net/http" "net/http/httptest" "testing" @@ -34,7 +34,7 @@ func BenchmarkHTTPClientServer(b *testing.B) { if err != nil { b.Fatal("Get:", err) } - all, err := ioutil.ReadAll(res.Body) + all, err := io.ReadAll(res.Body) if err != nil { b.Fatal("ReadAll:", err) } diff --git a/test/bench/go1/json_test.go b/test/bench/go1/json_test.go index 5ff1f8b6506874..782ef7674c1461 100644 --- a/test/bench/go1/json_test.go +++ b/test/bench/go1/json_test.go @@ -12,7 +12,6 @@ import ( "encoding/base64" "encoding/json" "io" - "io/ioutil" "testing" ) @@ -26,7 +25,7 @@ func makeJsonBytes() []byte { r = bytes.NewReader(bytes.Replace(jsonbz2_base64, []byte{'\n'}, nil, -1)) r = base64.NewDecoder(base64.StdEncoding, r) r = bzip2.NewReader(r) - b, err := ioutil.ReadAll(r) + b, err := io.ReadAll(r) if err != nil { panic(err) } diff --git a/test/bench/go1/parser_test.go b/test/bench/go1/parser_test.go index 7848cadd228e6d..8b7baa347963da 100644 --- a/test/bench/go1/parser_test.go +++ b/test/bench/go1/parser_test.go @@ -12,7 +12,6 @@ import ( "go/parser" "go/token" "io" - "io/ioutil" "strings" "testing" ) @@ -26,7 +25,7 @@ func makeParserBytes() []byte { r = strings.NewReader(parserbz2_base64) r = base64.NewDecoder(base64.StdEncoding, r) r = bzip2.NewReader(r) - b, err := ioutil.ReadAll(r) + b, err := io.ReadAll(r) if err != nil { panic(err) } diff --git a/test/bench/go1/revcomp_test.go b/test/bench/go1/revcomp_test.go index 7d57bd607b684d..c2e2c39baf736f 100644 --- a/test/bench/go1/revcomp_test.go +++ b/test/bench/go1/revcomp_test.go @@ -10,7 +10,7 @@ package go1 import ( "bufio" "bytes" - "io/ioutil" + "io" "testing" ) @@ -35,7 +35,7 @@ var revCompTable = [256]uint8{ func revcomp(data []byte) { in := bufio.NewReader(bytes.NewBuffer(data)) - out := ioutil.Discard + out := io.Discard buf := make([]byte, 1024*1024) line, err := in.ReadSlice('\n') for err == nil { diff --git a/test/bench/go1/template_test.go b/test/bench/go1/template_test.go index 10dacaa35f6dc0..b7e98d5c2099e3 100644 --- a/test/bench/go1/template_test.go +++ b/test/bench/go1/template_test.go @@ -9,7 +9,7 @@ package go1 import ( "bytes" - "io/ioutil" + "io" "strings" "testing" "text/template" @@ -63,7 +63,7 @@ func init() { } func tmplexec() { - if err := tmpl.Execute(ioutil.Discard, &jsondata); err != nil { + if err := tmpl.Execute(io.Discard, &jsondata); err != nil { panic(err) } } diff --git a/test/stress/runstress.go b/test/stress/runstress.go index 3f16fc9fb3fa87..b752fa8dbbc31f 100644 --- a/test/stress/runstress.go +++ b/test/stress/runstress.go @@ -12,7 +12,6 @@ import ( "flag" "fmt" "io" - "io/ioutil" "log" "math/rand" "net" @@ -70,7 +69,7 @@ func stressNet() { if res.StatusCode != 200 { log.Fatalf("stressNet: Status code = %d", res.StatusCode) } - n, err := io.Copy(ioutil.Discard, res.Body) + n, err := io.Copy(io.Discard, res.Body) if err != nil { log.Fatalf("stressNet: io.Copy: %v", err) } From 95457872e128192416873934526a124249d50fb1 Mon Sep 17 00:00:00 2001 From: KimMachineGun Date: Fri, 19 Mar 2021 11:06:02 +0900 Subject: [PATCH 2/4] net/http: remove unused import --- src/net/http/fs_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/src/net/http/fs_test.go b/src/net/http/fs_test.go index f9cfa91d4b03d3..0ebb511b5c5943 100644 --- a/src/net/http/fs_test.go +++ b/src/net/http/fs_test.go @@ -11,7 +11,6 @@ import ( "fmt" "io" "io/fs" - "io/ioutil" "mime" "mime/multipart" "net" From 05224305d24f1aa06cad17bdf4a50ad87135e038 Mon Sep 17 00:00:00 2001 From: KimMachineGun Date: Fri, 19 Mar 2021 11:39:09 +0900 Subject: [PATCH 3/4] all: update references to symbols moved from io/ioutil to io --- misc/android/go_android_exec.go | 3 +-- misc/cgo/errors/badsym_test.go | 7 +++--- misc/cgo/errors/errors_test.go | 5 ++-- misc/cgo/errors/ptr_test.go | 9 +++---- misc/cgo/life/life_test.go | 5 ++-- misc/cgo/stdio/stdio_test.go | 5 ++-- misc/cgo/test/issue1435.go | 6 ++--- misc/cgo/test/pkg_test.go | 5 ++-- misc/cgo/testcarchive/carchive_test.go | 11 ++++----- misc/cgo/testcshared/cshared_test.go | 17 ++++++------- misc/cgo/testgodefs/testgodefs_test.go | 11 ++++----- misc/cgo/testplugin/plugin_test.go | 9 +++---- misc/cgo/testsanitizers/cc_test.go | 9 +++---- misc/cgo/testsanitizers/cshared_test.go | 4 +-- misc/cgo/testshared/shared_test.go | 13 +++++----- misc/cgo/testso/so_test.go | 5 ++-- misc/cgo/testsovar/so_test.go | 5 ++-- misc/ios/detect.go | 3 +-- misc/ios/go_ios_exec.go | 9 +++---- misc/reboot/experiment_toolid_test.go | 7 +++--- misc/reboot/reboot_test.go | 5 ++-- src/go/build/build.go | 1 + src/go/types/check_test.go | 3 +-- src/internal/execabs/execabs_test.go | 5 ++-- src/syscall/exec_windows_test.go | 3 +-- test/const7.go | 3 +-- test/fixedbugs/bug302.go | 3 +-- test/fixedbugs/bug369.go | 3 +-- test/fixedbugs/issue11771.go | 5 ++-- test/fixedbugs/issue13268.go | 3 +-- test/fixedbugs/issue16037_run.go | 5 ++-- test/fixedbugs/issue19658.go | 5 ++-- test/fixedbugs/issue21317.go | 3 +-- test/fixedbugs/issue21576.go | 5 ++-- test/fixedbugs/issue22660.go | 5 ++-- test/fixedbugs/issue22662b.go | 5 ++-- test/fixedbugs/issue26411.go | 5 ++-- test/fixedbugs/issue30908.dir/b.go | 4 +-- test/fixedbugs/issue33555.go | 5 ++-- test/fixedbugs/issue36437.go | 3 +-- test/fixedbugs/issue9355.go | 3 +-- test/linkmain_run.go | 3 +-- test/linkobj.go | 9 +++---- test/nosplit.go | 9 +++---- test/run.go | 33 ++++++++++++------------- test/sinit_run.go | 3 +-- test/winbatch.go | 3 +-- 47 files changed, 124 insertions(+), 166 deletions(-) diff --git a/misc/android/go_android_exec.go b/misc/android/go_android_exec.go index 35b160fc9f0b04..3af2bee5839b93 100644 --- a/misc/android/go_android_exec.go +++ b/misc/android/go_android_exec.go @@ -14,7 +14,6 @@ import ( "fmt" "go/build" "io" - "io/ioutil" "log" "os" "os/exec" @@ -294,7 +293,7 @@ func adbCopyGoroot() error { goroot := runtime.GOROOT() // Build go for android. goCmd := filepath.Join(goroot, "bin", "go") - tmpGo, err := ioutil.TempFile("", "go_android_exec-cmd-go-*") + tmpGo, err := os.CreateTemp("", "go_android_exec-cmd-go-*") if err != nil { return err } diff --git a/misc/cgo/errors/badsym_test.go b/misc/cgo/errors/badsym_test.go index b2701bf922e529..fc687567bf71b2 100644 --- a/misc/cgo/errors/badsym_test.go +++ b/misc/cgo/errors/badsym_test.go @@ -6,7 +6,6 @@ package errorstest import ( "bytes" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -55,7 +54,7 @@ func TestBadSymbol(t *testing.T) { makeFile := func(mdir, base, source string) string { ret := filepath.Join(mdir, base) - if err := ioutil.WriteFile(ret, []byte(source), 0644); err != nil { + if err := os.WriteFile(ret, []byte(source), 0644); err != nil { t.Fatal(err) } return ret @@ -100,7 +99,7 @@ func TestBadSymbol(t *testing.T) { // _cgo_import.go. rewrite := func(from, to string) { - obj, err := ioutil.ReadFile(from) + obj, err := os.ReadFile(from) if err != nil { t.Fatal(err) } @@ -115,7 +114,7 @@ func TestBadSymbol(t *testing.T) { obj = bytes.ReplaceAll(obj, []byte(magicInput), []byte(magicReplace)) - if err := ioutil.WriteFile(to, obj, 0644); err != nil { + if err := os.WriteFile(to, obj, 0644); err != nil { t.Fatal(err) } } diff --git a/misc/cgo/errors/errors_test.go b/misc/cgo/errors/errors_test.go index 1bdf843451d366..a077b594786213 100644 --- a/misc/cgo/errors/errors_test.go +++ b/misc/cgo/errors/errors_test.go @@ -7,7 +7,6 @@ package errorstest import ( "bytes" "fmt" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -25,7 +24,7 @@ func check(t *testing.T, file string) { t.Run(file, func(t *testing.T) { t.Parallel() - contents, err := ioutil.ReadFile(path(file)) + contents, err := os.ReadFile(path(file)) if err != nil { t.Fatal(err) } @@ -56,7 +55,7 @@ func check(t *testing.T, file string) { } func expect(t *testing.T, file string, errors []*regexp.Regexp) { - dir, err := ioutil.TempDir("", filepath.Base(t.Name())) + dir, err := os.MkdirTemp("", filepath.Base(t.Name())) if err != nil { t.Fatal(err) } diff --git a/misc/cgo/errors/ptr_test.go b/misc/cgo/errors/ptr_test.go index 4a46b6023bb510..0f39dc8e547ed0 100644 --- a/misc/cgo/errors/ptr_test.go +++ b/misc/cgo/errors/ptr_test.go @@ -10,7 +10,6 @@ import ( "bytes" "flag" "fmt" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -463,7 +462,7 @@ func buildPtrTests(t *testing.T) (dir, exe string) { gopath = *tmp dir = "" } else { - d, err := ioutil.TempDir("", filepath.Base(t.Name())) + d, err := os.MkdirTemp("", filepath.Base(t.Name())) if err != nil { t.Fatal(err) } @@ -475,7 +474,7 @@ func buildPtrTests(t *testing.T) (dir, exe string) { if err := os.MkdirAll(src, 0777); err != nil { t.Fatal(err) } - if err := ioutil.WriteFile(filepath.Join(src, "go.mod"), []byte("module ptrtest"), 0666); err != nil { + if err := os.WriteFile(filepath.Join(src, "go.mod"), []byte("module ptrtest"), 0666); err != nil { t.Fatal(err) } @@ -535,10 +534,10 @@ func buildPtrTests(t *testing.T) (dir, exe string) { fmt.Fprintf(&cgo1, "}\n\n") fmt.Fprintf(&cgo1, "%s\n", ptrTestMain) - if err := ioutil.WriteFile(filepath.Join(src, "cgo1.go"), cgo1.Bytes(), 0666); err != nil { + if err := os.WriteFile(filepath.Join(src, "cgo1.go"), cgo1.Bytes(), 0666); err != nil { t.Fatal(err) } - if err := ioutil.WriteFile(filepath.Join(src, "cgo2.go"), cgo2.Bytes(), 0666); err != nil { + if err := os.WriteFile(filepath.Join(src, "cgo2.go"), cgo2.Bytes(), 0666); err != nil { t.Fatal(err) } diff --git a/misc/cgo/life/life_test.go b/misc/cgo/life/life_test.go index 3c95d87d8ade05..0becb262b43e9a 100644 --- a/misc/cgo/life/life_test.go +++ b/misc/cgo/life/life_test.go @@ -6,7 +6,6 @@ package life_test import ( "bytes" - "io/ioutil" "log" "os" "os/exec" @@ -21,7 +20,7 @@ func TestMain(m *testing.M) { } func testMain(m *testing.M) int { - GOPATH, err := ioutil.TempDir("", "cgolife") + GOPATH, err := os.MkdirTemp("", "cgolife") if err != nil { log.Panic(err) } @@ -38,7 +37,7 @@ func testMain(m *testing.M) int { log.Panic(err) } os.Setenv("PWD", modRoot) - if err := ioutil.WriteFile("go.mod", []byte("module cgolife\n"), 0666); err != nil { + if err := os.WriteFile("go.mod", []byte("module cgolife\n"), 0666); err != nil { log.Panic(err) } diff --git a/misc/cgo/stdio/stdio_test.go b/misc/cgo/stdio/stdio_test.go index ab5d328f676cd5..675418f98d026e 100644 --- a/misc/cgo/stdio/stdio_test.go +++ b/misc/cgo/stdio/stdio_test.go @@ -6,7 +6,6 @@ package stdio_test import ( "bytes" - "io/ioutil" "log" "os" "os/exec" @@ -21,7 +20,7 @@ func TestMain(m *testing.M) { } func testMain(m *testing.M) int { - GOPATH, err := ioutil.TempDir("", "cgostdio") + GOPATH, err := os.MkdirTemp("", "cgostdio") if err != nil { log.Panic(err) } @@ -38,7 +37,7 @@ func testMain(m *testing.M) int { log.Panic(err) } os.Setenv("PWD", modRoot) - if err := ioutil.WriteFile("go.mod", []byte("module cgostdio\n"), 0666); err != nil { + if err := os.WriteFile("go.mod", []byte("module cgostdio\n"), 0666); err != nil { log.Panic(err) } diff --git a/misc/cgo/test/issue1435.go b/misc/cgo/test/issue1435.go index a1c7cacde73844..cf34ce8db6ccb0 100644 --- a/misc/cgo/test/issue1435.go +++ b/misc/cgo/test/issue1435.go @@ -8,7 +8,7 @@ package cgotest import ( "fmt" - "io/ioutil" + "os" "strings" "syscall" "testing" @@ -64,7 +64,7 @@ import "C" func compareStatus(filter, expect string) error { expected := filter + expect pid := syscall.Getpid() - fs, err := ioutil.ReadDir(fmt.Sprintf("/proc/%d/task", pid)) + fs, err := os.ReadDir(fmt.Sprintf("/proc/%d/task", pid)) if err != nil { return fmt.Errorf("unable to find %d tasks: %v", pid, err) } @@ -72,7 +72,7 @@ func compareStatus(filter, expect string) error { foundAThread := false for _, f := range fs { tf := fmt.Sprintf("/proc/%s/status", f.Name()) - d, err := ioutil.ReadFile(tf) + d, err := os.ReadFile(tf) if err != nil { // There are a surprising number of ways this // can error out on linux. We've seen all of diff --git a/misc/cgo/test/pkg_test.go b/misc/cgo/test/pkg_test.go index 94abaa03e8d4b9..14013a4cd962b6 100644 --- a/misc/cgo/test/pkg_test.go +++ b/misc/cgo/test/pkg_test.go @@ -5,7 +5,6 @@ package cgotest import ( - "io/ioutil" "os" "os/exec" "path/filepath" @@ -37,7 +36,7 @@ func TestCrossPackageTests(t *testing.T) { } } - GOPATH, err := ioutil.TempDir("", "cgotest") + GOPATH, err := os.MkdirTemp("", "cgotest") if err != nil { t.Fatal(err) } @@ -47,7 +46,7 @@ func TestCrossPackageTests(t *testing.T) { if err := overlayDir(modRoot, "testdata"); err != nil { t.Fatal(err) } - if err := ioutil.WriteFile(filepath.Join(modRoot, "go.mod"), []byte("module cgotest\n"), 0666); err != nil { + if err := os.WriteFile(filepath.Join(modRoot, "go.mod"), []byte("module cgotest\n"), 0666); err != nil { t.Fatal(err) } diff --git a/misc/cgo/testcarchive/carchive_test.go b/misc/cgo/testcarchive/carchive_test.go index 6a5adf79ca05bb..ec717c4f8b2c53 100644 --- a/misc/cgo/testcarchive/carchive_test.go +++ b/misc/cgo/testcarchive/carchive_test.go @@ -10,7 +10,6 @@ import ( "debug/elf" "flag" "fmt" - "io/ioutil" "log" "os" "os/exec" @@ -53,7 +52,7 @@ func testMain(m *testing.M) int { // We need a writable GOPATH in which to run the tests. // Construct one in a temporary directory. var err error - GOPATH, err = ioutil.TempDir("", "carchive_test") + GOPATH, err = os.MkdirTemp("", "carchive_test") if err != nil { log.Panic(err) } @@ -74,7 +73,7 @@ func testMain(m *testing.M) int { log.Panic(err) } os.Setenv("PWD", modRoot) - if err := ioutil.WriteFile("go.mod", []byte("module testcarchive\n"), 0666); err != nil { + if err := os.WriteFile("go.mod", []byte("module testcarchive\n"), 0666); err != nil { log.Panic(err) } @@ -176,7 +175,7 @@ func genHeader(t *testing.T, header, dir string) { // The 'cgo' command generates a number of additional artifacts, // but we're only interested in the header. // Shunt the rest of the outputs to a temporary directory. - objDir, err := ioutil.TempDir(GOPATH, "_obj") + objDir, err := os.MkdirTemp(GOPATH, "_obj") if err != nil { t.Fatal(err) } @@ -252,7 +251,7 @@ var badLineRegexp = regexp.MustCompile(`(?m)^#line [0-9]+ "/.*$`) // the user and make the files change based on details of the location // of GOPATH. func checkLineComments(t *testing.T, hdrname string) { - hdr, err := ioutil.ReadFile(hdrname) + hdr, err := os.ReadFile(hdrname) if err != nil { if !os.IsNotExist(err) { t.Error(err) @@ -618,7 +617,7 @@ func TestExtar(t *testing.T) { t.Fatal(err) } s := strings.Replace(testar, "PWD", dir, 1) - if err := ioutil.WriteFile("testar", []byte(s), 0777); err != nil { + if err := os.WriteFile("testar", []byte(s), 0777); err != nil { t.Fatal(err) } diff --git a/misc/cgo/testcshared/cshared_test.go b/misc/cgo/testcshared/cshared_test.go index 3a4886cf30a88b..90d8c365e6d2ca 100644 --- a/misc/cgo/testcshared/cshared_test.go +++ b/misc/cgo/testcshared/cshared_test.go @@ -11,7 +11,6 @@ import ( "encoding/binary" "flag" "fmt" - "io/ioutil" "log" "os" "os/exec" @@ -125,7 +124,7 @@ func testMain(m *testing.M) int { // Copy testdata into GOPATH/src/testcshared, along with a go.mod file // declaring the same path. - GOPATH, err := ioutil.TempDir("", "cshared_test") + GOPATH, err := os.MkdirTemp("", "cshared_test") if err != nil { log.Panic(err) } @@ -140,7 +139,7 @@ func testMain(m *testing.M) int { log.Panic(err) } os.Setenv("PWD", modRoot) - if err := ioutil.WriteFile("go.mod", []byte("module testcshared\n"), 0666); err != nil { + if err := os.WriteFile("go.mod", []byte("module testcshared\n"), 0666); err != nil { log.Panic(err) } @@ -260,7 +259,7 @@ func createHeaders() error { // The 'cgo' command generates a number of additional artifacts, // but we're only interested in the header. // Shunt the rest of the outputs to a temporary directory. - objDir, err := ioutil.TempDir("", "testcshared_obj") + objDir, err := os.MkdirTemp("", "testcshared_obj") if err != nil { return err } @@ -381,7 +380,7 @@ func main() { srcfile := filepath.Join(tmpdir, "test.go") objfile := filepath.Join(tmpdir, "test.dll") - if err := ioutil.WriteFile(srcfile, []byte(prog), 0666); err != nil { + if err := os.WriteFile(srcfile, []byte(prog), 0666); err != nil { t.Fatal(err) } argv := []string{"build", "-buildmode=c-shared"} @@ -643,7 +642,7 @@ func TestPIE(t *testing.T) { // Test that installing a second time recreates the header file. func TestCachedInstall(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "cshared") + tmpdir, err := os.MkdirTemp("", "cshared") if err != nil { t.Fatal(err) } @@ -719,14 +718,14 @@ func TestCachedInstall(t *testing.T) { // copyFile copies src to dst. func copyFile(t *testing.T, dst, src string) { t.Helper() - data, err := ioutil.ReadFile(src) + data, err := os.ReadFile(src) if err != nil { t.Fatal(err) } if err := os.MkdirAll(filepath.Dir(dst), 0777); err != nil { t.Fatal(err) } - if err := ioutil.WriteFile(dst, data, 0666); err != nil { + if err := os.WriteFile(dst, data, 0666); err != nil { t.Fatal(err) } } @@ -743,7 +742,7 @@ func TestGo2C2Go(t *testing.T) { t.Parallel() - tmpdir, err := ioutil.TempDir("", "cshared-TestGo2C2Go") + tmpdir, err := os.MkdirTemp("", "cshared-TestGo2C2Go") if err != nil { t.Fatal(err) } diff --git a/misc/cgo/testgodefs/testgodefs_test.go b/misc/cgo/testgodefs/testgodefs_test.go index 4c2312c1c89633..aae34043605d34 100644 --- a/misc/cgo/testgodefs/testgodefs_test.go +++ b/misc/cgo/testgodefs/testgodefs_test.go @@ -6,7 +6,6 @@ package testgodefs import ( "bytes" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -34,7 +33,7 @@ func TestGoDefs(t *testing.T) { t.Fatal(err) } - gopath, err := ioutil.TempDir("", "testgodefs-gopath") + gopath, err := os.MkdirTemp("", "testgodefs-gopath") if err != nil { t.Fatal(err) } @@ -58,20 +57,20 @@ func TestGoDefs(t *testing.T) { t.Fatalf("%s: %v\n%s", strings.Join(cmd.Args, " "), err, cmd.Stderr) } - if err := ioutil.WriteFile(filepath.Join(dir, fp+"_defs.go"), out, 0644); err != nil { + if err := os.WriteFile(filepath.Join(dir, fp+"_defs.go"), out, 0644); err != nil { t.Fatal(err) } } - main, err := ioutil.ReadFile(filepath.Join("testdata", "main.go")) + main, err := os.ReadFile(filepath.Join("testdata", "main.go")) if err != nil { t.Fatal(err) } - if err := ioutil.WriteFile(filepath.Join(dir, "main.go"), main, 0644); err != nil { + if err := os.WriteFile(filepath.Join(dir, "main.go"), main, 0644); err != nil { t.Fatal(err) } - if err := ioutil.WriteFile(filepath.Join(dir, "go.mod"), []byte("module testgodefs\ngo 1.14\n"), 0644); err != nil { + if err := os.WriteFile(filepath.Join(dir, "go.mod"), []byte("module testgodefs\ngo 1.14\n"), 0644); err != nil { t.Fatal(err) } diff --git a/misc/cgo/testplugin/plugin_test.go b/misc/cgo/testplugin/plugin_test.go index 8869528015d86d..b894e8d30d0ca2 100644 --- a/misc/cgo/testplugin/plugin_test.go +++ b/misc/cgo/testplugin/plugin_test.go @@ -9,7 +9,6 @@ import ( "context" "flag" "fmt" - "io/ioutil" "log" "os" "os/exec" @@ -35,7 +34,7 @@ func testMain(m *testing.M) int { // Copy testdata into GOPATH/src/testplugin, along with a go.mod file // declaring the same path. - GOPATH, err := ioutil.TempDir("", "plugin_test") + GOPATH, err := os.MkdirTemp("", "plugin_test") if err != nil { log.Panic(err) } @@ -50,7 +49,7 @@ func testMain(m *testing.M) int { if err := overlayDir(dstRoot, srcRoot); err != nil { log.Panic(err) } - if err := ioutil.WriteFile(filepath.Join(dstRoot, "go.mod"), []byte("module testplugin\n"), 0666); err != nil { + if err := os.WriteFile(filepath.Join(dstRoot, "go.mod"), []byte("module testplugin\n"), 0666); err != nil { log.Panic(err) } } @@ -72,11 +71,11 @@ func testMain(m *testing.M) int { goCmd(nil, "build", "-buildmode=plugin", "./plugin1") goCmd(nil, "build", "-buildmode=plugin", "./plugin2") - so, err := ioutil.ReadFile("plugin2.so") + so, err := os.ReadFile("plugin2.so") if err != nil { log.Panic(err) } - if err := ioutil.WriteFile("plugin2-dup.so", so, 0444); err != nil { + if err := os.WriteFile("plugin2-dup.so", so, 0444); err != nil { log.Panic(err) } diff --git a/misc/cgo/testsanitizers/cc_test.go b/misc/cgo/testsanitizers/cc_test.go index dab13364b862b4..384b6250e1ef16 100644 --- a/misc/cgo/testsanitizers/cc_test.go +++ b/misc/cgo/testsanitizers/cc_test.go @@ -11,7 +11,6 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -36,7 +35,7 @@ func requireOvercommit(t *testing.T) { overcommit.Once.Do(func() { var out []byte - out, overcommit.err = ioutil.ReadFile("/proc/sys/vm/overcommit_memory") + out, overcommit.err = os.ReadFile("/proc/sys/vm/overcommit_memory") if overcommit.err != nil { return } @@ -313,14 +312,14 @@ int main() { `) func (c *config) checkCSanitizer() (skip bool, err error) { - dir, err := ioutil.TempDir("", c.sanitizer) + dir, err := os.MkdirTemp("", c.sanitizer) if err != nil { return false, fmt.Errorf("failed to create temp directory: %v", err) } defer os.RemoveAll(dir) src := filepath.Join(dir, "return0.c") - if err := ioutil.WriteFile(src, cMain, 0600); err != nil { + if err := os.WriteFile(src, cMain, 0600); err != nil { return false, fmt.Errorf("failed to write C source file: %v", err) } @@ -418,7 +417,7 @@ func (d *tempDir) Join(name string) string { func newTempDir(t *testing.T) *tempDir { t.Helper() - dir, err := ioutil.TempDir("", filepath.Dir(t.Name())) + dir, err := os.MkdirTemp("", filepath.Dir(t.Name())) if err != nil { t.Fatalf("Failed to create temp dir: %v", err) } diff --git a/misc/cgo/testsanitizers/cshared_test.go b/misc/cgo/testsanitizers/cshared_test.go index b98360c4ae34d3..8fd03715a11bd8 100644 --- a/misc/cgo/testsanitizers/cshared_test.go +++ b/misc/cgo/testsanitizers/cshared_test.go @@ -6,7 +6,7 @@ package sanitizers_test import ( "fmt" - "io/ioutil" + "os" "strings" "testing" ) @@ -64,7 +64,7 @@ func TestShared(t *testing.T) { mustRun(t, config.goCmd("build", "-buildmode=c-shared", "-o", lib, srcPath(tc.src))) cSrc := dir.Join("main.c") - if err := ioutil.WriteFile(cSrc, cMain, 0600); err != nil { + if err := os.WriteFile(cSrc, cMain, 0600); err != nil { t.Fatalf("failed to write C source file: %v", err) } diff --git a/misc/cgo/testshared/shared_test.go b/misc/cgo/testshared/shared_test.go index f52391c6f6c6ab..e77f84891543f5 100644 --- a/misc/cgo/testshared/shared_test.go +++ b/misc/cgo/testshared/shared_test.go @@ -13,7 +13,6 @@ import ( "fmt" "go/build" "io" - "io/ioutil" "log" "os" "os/exec" @@ -90,7 +89,7 @@ func goCmd(t *testing.T, args ...string) string { // TestMain calls testMain so that the latter can use defer (TestMain exits with os.Exit). func testMain(m *testing.M) (int, error) { - workDir, err := ioutil.TempDir("", "shared_test") + workDir, err := os.MkdirTemp("", "shared_test") if err != nil { return 0, err } @@ -177,7 +176,7 @@ func cloneTestdataModule(gopath string) (string, error) { if err := overlayDir(modRoot, "testdata"); err != nil { return "", err } - if err := ioutil.WriteFile(filepath.Join(modRoot, "go.mod"), []byte("module testshared\n"), 0644); err != nil { + if err := os.WriteFile(filepath.Join(modRoot, "go.mod"), []byte("module testshared\n"), 0644); err != nil { return "", err } return modRoot, nil @@ -318,7 +317,7 @@ func TestShlibnameFiles(t *testing.T) { } for _, pkg := range pkgs { shlibnamefile := filepath.Join(gorootInstallDir, pkg+".shlibname") - contentsb, err := ioutil.ReadFile(shlibnamefile) + contentsb, err := os.ReadFile(shlibnamefile) if err != nil { t.Errorf("error reading shlibnamefile for %s: %v", pkg, err) continue @@ -791,7 +790,7 @@ func resetFileStamps() { // It also sets the time of the file, so that we can see if it is rewritten. func touch(t *testing.T, path string) (cleanup func()) { t.Helper() - data, err := ioutil.ReadFile(path) + data, err := os.ReadFile(path) if err != nil { t.Fatal(err) } @@ -837,14 +836,14 @@ func touch(t *testing.T, path string) (cleanup func()) { // user-writable. perm := fi.Mode().Perm() | 0200 - if err := ioutil.WriteFile(path, data, perm); err != nil { + if err := os.WriteFile(path, data, perm); err != nil { t.Fatal(err) } if err := os.Chtimes(path, nearlyNew, nearlyNew); err != nil { t.Fatal(err) } return func() { - if err := ioutil.WriteFile(path, old, perm); err != nil { + if err := os.WriteFile(path, old, perm); err != nil { t.Fatal(err) } } diff --git a/misc/cgo/testso/so_test.go b/misc/cgo/testso/so_test.go index 57f0fd34f78aca..1c97ae9bcb2562 100644 --- a/misc/cgo/testso/so_test.go +++ b/misc/cgo/testso/so_test.go @@ -7,7 +7,6 @@ package so_test import ( - "io/ioutil" "log" "os" "os/exec" @@ -37,7 +36,7 @@ func requireTestSOSupported(t *testing.T) { func TestSO(t *testing.T) { requireTestSOSupported(t) - GOPATH, err := ioutil.TempDir("", "cgosotest") + GOPATH, err := os.MkdirTemp("", "cgosotest") if err != nil { log.Fatal(err) } @@ -47,7 +46,7 @@ func TestSO(t *testing.T) { if err := overlayDir(modRoot, "testdata"); err != nil { log.Panic(err) } - if err := ioutil.WriteFile(filepath.Join(modRoot, "go.mod"), []byte("module cgosotest\n"), 0666); err != nil { + if err := os.WriteFile(filepath.Join(modRoot, "go.mod"), []byte("module cgosotest\n"), 0666); err != nil { log.Panic(err) } diff --git a/misc/cgo/testsovar/so_test.go b/misc/cgo/testsovar/so_test.go index 57f0fd34f78aca..1c97ae9bcb2562 100644 --- a/misc/cgo/testsovar/so_test.go +++ b/misc/cgo/testsovar/so_test.go @@ -7,7 +7,6 @@ package so_test import ( - "io/ioutil" "log" "os" "os/exec" @@ -37,7 +36,7 @@ func requireTestSOSupported(t *testing.T) { func TestSO(t *testing.T) { requireTestSOSupported(t) - GOPATH, err := ioutil.TempDir("", "cgosotest") + GOPATH, err := os.MkdirTemp("", "cgosotest") if err != nil { log.Fatal(err) } @@ -47,7 +46,7 @@ func TestSO(t *testing.T) { if err := overlayDir(modRoot, "testdata"); err != nil { log.Panic(err) } - if err := ioutil.WriteFile(filepath.Join(modRoot, "go.mod"), []byte("module cgosotest\n"), 0666); err != nil { + if err := os.WriteFile(filepath.Join(modRoot, "go.mod"), []byte("module cgosotest\n"), 0666); err != nil { log.Panic(err) } diff --git a/misc/ios/detect.go b/misc/ios/detect.go index d32bcc3202a443..cde57238923be6 100644 --- a/misc/ios/detect.go +++ b/misc/ios/detect.go @@ -16,7 +16,6 @@ import ( "bytes" "crypto/x509" "fmt" - "io/ioutil" "os" "os/exec" "strings" @@ -38,7 +37,7 @@ func main() { fmt.Println("# will be overwritten when running Go programs.") for _, mp := range mps { fmt.Println() - f, err := ioutil.TempFile("", "go_ios_detect_") + f, err := os.CreateTemp("", "go_ios_detect_") check(err) fname := f.Name() defer os.Remove(fname) diff --git a/misc/ios/go_ios_exec.go b/misc/ios/go_ios_exec.go index 0acf1b259c0451..9e63717d9214d6 100644 --- a/misc/ios/go_ios_exec.go +++ b/misc/ios/go_ios_exec.go @@ -26,7 +26,6 @@ import ( "fmt" "go/build" "io" - "io/ioutil" "log" "net" "os" @@ -79,7 +78,7 @@ func main() { func runMain() (int, error) { var err error - tmpdir, err = ioutil.TempDir("", "go_ios_exec_") + tmpdir, err = os.MkdirTemp("", "go_ios_exec_") if err != nil { return 1, err } @@ -205,13 +204,13 @@ func assembleApp(appdir, bin string) error { } entitlementsPath := filepath.Join(tmpdir, "Entitlements.plist") - if err := ioutil.WriteFile(entitlementsPath, []byte(entitlementsPlist()), 0744); err != nil { + if err := os.WriteFile(entitlementsPath, []byte(entitlementsPlist()), 0744); err != nil { return err } - if err := ioutil.WriteFile(filepath.Join(appdir, "Info.plist"), []byte(infoPlist(pkgpath)), 0744); err != nil { + if err := os.WriteFile(filepath.Join(appdir, "Info.plist"), []byte(infoPlist(pkgpath)), 0744); err != nil { return err } - if err := ioutil.WriteFile(filepath.Join(appdir, "ResourceRules.plist"), []byte(resourceRules), 0744); err != nil { + if err := os.WriteFile(filepath.Join(appdir, "ResourceRules.plist"), []byte(resourceRules), 0744); err != nil { return err } return nil diff --git a/misc/reboot/experiment_toolid_test.go b/misc/reboot/experiment_toolid_test.go index eabf06b19ee3af..4f40284d80f107 100644 --- a/misc/reboot/experiment_toolid_test.go +++ b/misc/reboot/experiment_toolid_test.go @@ -13,7 +13,6 @@ package reboot_test import ( "bytes" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -23,7 +22,7 @@ import ( func TestExperimentToolID(t *testing.T) { // Set up GOROOT - goroot, err := ioutil.TempDir("", "experiment-goroot") + goroot, err := os.MkdirTemp("", "experiment-goroot") if err != nil { t.Fatal(err) } @@ -34,13 +33,13 @@ func TestExperimentToolID(t *testing.T) { t.Fatal(err) } - if err := ioutil.WriteFile(filepath.Join(goroot, "VERSION"), []byte("go1.999"), 0666); err != nil { + if err := os.WriteFile(filepath.Join(goroot, "VERSION"), []byte("go1.999"), 0666); err != nil { t.Fatal(err) } env := append(os.Environ(), "GOROOT=", "GOROOT_BOOTSTRAP="+runtime.GOROOT()) // Use a clean cache. - gocache, err := ioutil.TempDir("", "experiment-gocache") + gocache, err := os.MkdirTemp("", "experiment-gocache") if err != nil { t.Fatal(err) } diff --git a/misc/reboot/reboot_test.go b/misc/reboot/reboot_test.go index 717c0fb709638c..6bafc608b5e234 100644 --- a/misc/reboot/reboot_test.go +++ b/misc/reboot/reboot_test.go @@ -7,7 +7,6 @@ package reboot_test import ( - "io/ioutil" "os" "os/exec" "path/filepath" @@ -16,7 +15,7 @@ import ( ) func TestRepeatBootstrap(t *testing.T) { - goroot, err := ioutil.TempDir("", "reboot-goroot") + goroot, err := os.MkdirTemp("", "reboot-goroot") if err != nil { t.Fatal(err) } @@ -27,7 +26,7 @@ func TestRepeatBootstrap(t *testing.T) { t.Fatal(err) } - if err := ioutil.WriteFile(filepath.Join(goroot, "VERSION"), []byte(runtime.Version()), 0666); err != nil { + if err := os.WriteFile(filepath.Join(goroot, "VERSION"), []byte(runtime.Version()), 0666); err != nil { t.Fatal(err) } diff --git a/src/go/build/build.go b/src/go/build/build.go index 0732f6aa1991d9..501ce2e8dd2703 100644 --- a/src/go/build/build.go +++ b/src/go/build/build.go @@ -188,6 +188,7 @@ func (ctxt *Context) readDir(path string) ([]fs.FileInfo, error) { if f := ctxt.ReadDir; f != nil { return f(path) } + // TODO: use os.ReadDir return ioutil.ReadDir(path) } diff --git a/src/go/types/check_test.go b/src/go/types/check_test.go index 9812b3808b9190..327fb4c5f19cbe 100644 --- a/src/go/types/check_test.go +++ b/src/go/types/check_test.go @@ -34,7 +34,6 @@ import ( "go/scanner" "go/token" "internal/testenv" - "io/ioutil" "os" "path/filepath" "regexp" @@ -332,7 +331,7 @@ func testDir(t *testing.T, dir string) { // if fi is a directory, its files make up a single package var filenames []string if fi.IsDir() { - fis, err := ioutil.ReadDir(path) + fis, err := os.ReadDir(path) if err != nil { t.Error(err) continue diff --git a/src/internal/execabs/execabs_test.go b/src/internal/execabs/execabs_test.go index b71458587c5e84..7609b2106a6254 100644 --- a/src/internal/execabs/execabs_test.go +++ b/src/internal/execabs/execabs_test.go @@ -8,7 +8,6 @@ import ( "context" "fmt" "internal/testenv" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -42,7 +41,7 @@ func TestCommand(t *testing.T) { if runtime.GOOS == "windows" { executable += ".exe" } - if err := ioutil.WriteFile(filepath.Join(tmpDir, executable), []byte{1, 2, 3}, 0111); err != nil { + if err := os.WriteFile(filepath.Join(tmpDir, executable), []byte{1, 2, 3}, 0111); err != nil { t.Fatalf("ioutil.WriteFile failed: %s", err) } cwd, err := os.Getwd() @@ -77,7 +76,7 @@ func TestLookPath(t *testing.T) { if runtime.GOOS == "windows" { executable += ".exe" } - if err := ioutil.WriteFile(filepath.Join(tmpDir, executable), []byte{1, 2, 3}, 0111); err != nil { + if err := os.WriteFile(filepath.Join(tmpDir, executable), []byte{1, 2, 3}, 0111); err != nil { t.Fatalf("ioutil.WriteFile failed: %s", err) } cwd, err := os.Getwd() diff --git a/src/syscall/exec_windows_test.go b/src/syscall/exec_windows_test.go index fb2c767c3515b6..a5b1fb42534168 100644 --- a/src/syscall/exec_windows_test.go +++ b/src/syscall/exec_windows_test.go @@ -6,7 +6,6 @@ package syscall_test import ( "fmt" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -106,7 +105,7 @@ func TestChangingProcessParent(t *testing.T) { if err != nil { t.Errorf("child failed: %v: %v", err, string(childOutput)) } - childOutput, err = ioutil.ReadFile(childDumpPath) + childOutput, err = os.ReadFile(childDumpPath) if err != nil { t.Fatalf("reading child output failed: %v", err) } diff --git a/test/const7.go b/test/const7.go index 9ffd678fc5d882..e75cebf23dbbed 100644 --- a/test/const7.go +++ b/test/const7.go @@ -11,7 +11,6 @@ package main import ( "bytes" "fmt" - "io/ioutil" "log" "os" "os/exec" @@ -63,7 +62,7 @@ func main() { return } - dir, err := ioutil.TempDir("", "const7_") + dir, err := os.MkdirTemp("", "const7_") if err != nil { log.Fatalf("creating temp dir: %v\n", err) } diff --git a/test/fixedbugs/bug302.go b/test/fixedbugs/bug302.go index a2ab661277a38f..344697fd7131dd 100644 --- a/test/fixedbugs/bug302.go +++ b/test/fixedbugs/bug302.go @@ -9,7 +9,6 @@ package main import ( "fmt" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -20,7 +19,7 @@ var tmpDir string func main() { fb, err := filepath.Abs("fixedbugs") if err == nil { - tmpDir, err = ioutil.TempDir("", "bug302") + tmpDir, err = os.MkdirTemp("", "bug302") } if err != nil { fmt.Println(err) diff --git a/test/fixedbugs/bug369.go b/test/fixedbugs/bug369.go index 83f638d04632af..5fe71b8006eff7 100644 --- a/test/fixedbugs/bug369.go +++ b/test/fixedbugs/bug369.go @@ -11,7 +11,6 @@ package main import ( "fmt" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -21,7 +20,7 @@ func main() { err := os.Chdir(filepath.Join(".", "fixedbugs", "bug369.dir")) check(err) - tmpDir, err := ioutil.TempDir("", "bug369") + tmpDir, err := os.MkdirTemp("", "bug369") check(err) defer os.RemoveAll(tmpDir) diff --git a/test/fixedbugs/issue11771.go b/test/fixedbugs/issue11771.go index c95dd6ba396584..74c601142d814d 100644 --- a/test/fixedbugs/issue11771.go +++ b/test/fixedbugs/issue11771.go @@ -12,7 +12,6 @@ package main import ( "bytes" "fmt" - "io/ioutil" "log" "os" "os/exec" @@ -25,7 +24,7 @@ func main() { return } - dir, err := ioutil.TempDir("", "go-issue11771") + dir, err := os.MkdirTemp("", "go-issue11771") if err != nil { log.Fatalf("creating temp dir: %v\n", err) } @@ -48,7 +47,7 @@ func x() { } `) - if err := ioutil.WriteFile(filepath.Join(dir, "x.go"), buf.Bytes(), 0666); err != nil { + if err := os.WriteFile(filepath.Join(dir, "x.go"), buf.Bytes(), 0666); err != nil { log.Fatal(err) } diff --git a/test/fixedbugs/issue13268.go b/test/fixedbugs/issue13268.go index 53a82d5074ab97..452bfc83b5aee7 100644 --- a/test/fixedbugs/issue13268.go +++ b/test/fixedbugs/issue13268.go @@ -14,7 +14,6 @@ package main import ( - "io/ioutil" "log" "os" "os/exec" @@ -23,7 +22,7 @@ import ( func main() { // create source - f, err := ioutil.TempFile("", "issue13268-") + f, err := os.CreateTemp("", "issue13268-") if err != nil { log.Fatalf("could not create source file: %v", err) } diff --git a/test/fixedbugs/issue16037_run.go b/test/fixedbugs/issue16037_run.go index 68104a9000795d..0bd0d526e295a5 100644 --- a/test/fixedbugs/issue16037_run.go +++ b/test/fixedbugs/issue16037_run.go @@ -11,7 +11,6 @@ import ( "bytes" "fmt" "html/template" - "io/ioutil" "log" "os" "os/exec" @@ -53,13 +52,13 @@ func main() { log.Fatal(err) } - dir, err := ioutil.TempDir("", "issue16037-") + dir, err := os.MkdirTemp("", "issue16037-") if err != nil { log.Fatal(err) } defer os.RemoveAll(dir) path := filepath.Join(dir, "ridiculous_number_of_fields.go") - if err := ioutil.WriteFile(path, buf.Bytes(), 0664); err != nil { + if err := os.WriteFile(path, buf.Bytes(), 0664); err != nil { log.Fatal(err) } diff --git a/test/fixedbugs/issue19658.go b/test/fixedbugs/issue19658.go index bab409c6c03cc8..b6b5c09461879a 100644 --- a/test/fixedbugs/issue19658.go +++ b/test/fixedbugs/issue19658.go @@ -11,7 +11,6 @@ package main import ( "bytes" "fmt" - "io/ioutil" "log" "os" "os/exec" @@ -35,7 +34,7 @@ func main() { ` func main() { - tempDir, err := ioutil.TempDir("", "") + tempDir, err := os.MkdirTemp("", "") if err != nil { log.Fatal(err) } @@ -70,7 +69,7 @@ func main() { b := bytes.Buffer{} fmt.Fprintf(&b, fn, tc.Type, tc.Input) - err = ioutil.WriteFile(tmpFile, b.Bytes(), 0644) + err = os.WriteFile(tmpFile, b.Bytes(), 0644) if err != nil { log.Fatal(err) } diff --git a/test/fixedbugs/issue21317.go b/test/fixedbugs/issue21317.go index 32b660c1639169..2c634a7074730f 100644 --- a/test/fixedbugs/issue21317.go +++ b/test/fixedbugs/issue21317.go @@ -13,7 +13,6 @@ package main import ( "fmt" - "io/ioutil" "log" "os" "os/exec" @@ -21,7 +20,7 @@ import ( ) func main() { - f, err := ioutil.TempFile("", "issue21317.go") + f, err := os.CreateTemp("", "issue21317.go") if err != nil { log.Fatal(err) } diff --git a/test/fixedbugs/issue21576.go b/test/fixedbugs/issue21576.go index 3f9b1ba008af4c..f7b3d46711d744 100644 --- a/test/fixedbugs/issue21576.go +++ b/test/fixedbugs/issue21576.go @@ -14,7 +14,6 @@ package main import ( "bytes" "context" - "io/ioutil" "log" "os" "os/exec" @@ -34,14 +33,14 @@ func main() { ` func main() { - dir, err := ioutil.TempDir("", "21576") + dir, err := os.MkdirTemp("", "21576") if err != nil { log.Fatal(err) } defer os.RemoveAll(dir) file := filepath.Join(dir, "main.go") - if err := ioutil.WriteFile(file, []byte(prog), 0655); err != nil { + if err := os.WriteFile(file, []byte(prog), 0655); err != nil { log.Fatalf("Write error %v", err) } diff --git a/test/fixedbugs/issue22660.go b/test/fixedbugs/issue22660.go index 9ce9c4d732e6d4..78773cb0a3d369 100644 --- a/test/fixedbugs/issue22660.go +++ b/test/fixedbugs/issue22660.go @@ -10,7 +10,6 @@ package main import ( "bytes" "fmt" - "io/ioutil" "log" "os" "os/exec" @@ -19,7 +18,7 @@ import ( ) func main() { - f, err := ioutil.TempFile("", "issue22660.go") + f, err := os.CreateTemp("", "issue22660.go") if err != nil { log.Fatal(err) } @@ -31,7 +30,7 @@ func main() { var src bytes.Buffer fmt.Fprintf(&src, "//line %s:1\n", filepath.Join(path, "foo.go")) - if err := ioutil.WriteFile(f.Name(), src.Bytes(), 0660); err != nil { + if err := os.WriteFile(f.Name(), src.Bytes(), 0660); err != nil { log.Fatal(err) } diff --git a/test/fixedbugs/issue22662b.go b/test/fixedbugs/issue22662b.go index 8da17679be08e9..05cd2b9d5e025f 100644 --- a/test/fixedbugs/issue22662b.go +++ b/test/fixedbugs/issue22662b.go @@ -10,7 +10,6 @@ package main import ( - "io/ioutil" "log" "os" "os/exec" @@ -36,7 +35,7 @@ var tests = []struct { } func main() { - f, err := ioutil.TempFile("", "issue22662b.go") + f, err := os.CreateTemp("", "issue22662b.go") if err != nil { log.Fatal(err) } @@ -44,7 +43,7 @@ func main() { defer os.Remove(f.Name()) for _, test := range tests { - if err := ioutil.WriteFile(f.Name(), []byte(test.src), 0660); err != nil { + if err := os.WriteFile(f.Name(), []byte(test.src), 0660); err != nil { log.Fatal(err) } diff --git a/test/fixedbugs/issue26411.go b/test/fixedbugs/issue26411.go index 5f40bf25229a1a..36850ac4df83e2 100644 --- a/test/fixedbugs/issue26411.go +++ b/test/fixedbugs/issue26411.go @@ -14,7 +14,6 @@ package main import ( "bytes" "fmt" - "io/ioutil" "log" "os" "os/exec" @@ -23,7 +22,7 @@ import ( ) func main() { - tmpdir, err := ioutil.TempDir("", "issue26411") + tmpdir, err := os.MkdirTemp("", "issue26411") if err != nil { log.Fatalf("Failed to create temporary directory: %v", err) } @@ -71,7 +70,7 @@ bar : for i, test := range tests { filename := filepath.Join(tmpdir, fmt.Sprintf("%d.go", i)) - if err := ioutil.WriteFile(filename, []byte(test.code), 0644); err != nil { + if err := os.WriteFile(filename, []byte(test.code), 0644); err != nil { log.Printf("#%d: failed to create file %s", i, filename) continue } diff --git a/test/fixedbugs/issue30908.dir/b.go b/test/fixedbugs/issue30908.dir/b.go index 2f543985b4fc39..e6f1450df83caa 100644 --- a/test/fixedbugs/issue30908.dir/b.go +++ b/test/fixedbugs/issue30908.dir/b.go @@ -5,7 +5,7 @@ package b import ( - "io/ioutil" + "os" "./a" ) @@ -27,7 +27,7 @@ func ReadValues(data []byte) (vals map[string]interface{}, err error) { // of the output param. func CallReadValues(filename string) (map[string]interface{}, error) { defer func() { G++ }() - data, err := ioutil.ReadFile(filename) + data, err := os.ReadFile(filename) if err != nil { return map[string]interface{}{}, err } diff --git a/test/fixedbugs/issue33555.go b/test/fixedbugs/issue33555.go index c1fcd2a79b387a..560dbdff8a9955 100644 --- a/test/fixedbugs/issue33555.go +++ b/test/fixedbugs/issue33555.go @@ -11,7 +11,6 @@ package main import ( "bytes" "fmt" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -56,14 +55,14 @@ func test() error { } fmt.Fprintf(&buf, fnlast, count) - dir, err := ioutil.TempDir("", "issue33555") + dir, err := os.MkdirTemp("", "issue33555") if err != nil { return err } defer os.RemoveAll(dir) fn := filepath.Join(dir, "x.go") - if err := ioutil.WriteFile(fn, buf.Bytes(), 0644); err != nil { + if err := os.WriteFile(fn, buf.Bytes(), 0644); err != nil { return err } diff --git a/test/fixedbugs/issue36437.go b/test/fixedbugs/issue36437.go index c7a11d27a89349..01099b7a60318a 100644 --- a/test/fixedbugs/issue36437.go +++ b/test/fixedbugs/issue36437.go @@ -18,14 +18,13 @@ package main import ( "fmt" - "io/ioutil" "os" "os/exec" "regexp" ) func main() { - tmpDir, err := ioutil.TempDir("", "issue36437") + tmpDir, err := os.MkdirTemp("", "issue36437") if err != nil { panic(err) } diff --git a/test/fixedbugs/issue9355.go b/test/fixedbugs/issue9355.go index 319a2a90df9ba2..bfd032f99d7631 100644 --- a/test/fixedbugs/issue9355.go +++ b/test/fixedbugs/issue9355.go @@ -9,7 +9,6 @@ package main import ( "fmt" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -20,7 +19,7 @@ func main() { err := os.Chdir(filepath.Join("fixedbugs", "issue9355.dir")) check(err) - f, err := ioutil.TempFile("", "issue9355-*.o") + f, err := os.CreateTemp("", "issue9355-*.o") if err != nil { fmt.Println(err) os.Exit(1) diff --git a/test/linkmain_run.go b/test/linkmain_run.go index 077f7ee91753c5..91156b69e160a5 100644 --- a/test/linkmain_run.go +++ b/test/linkmain_run.go @@ -11,7 +11,6 @@ package main import ( "fmt" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -52,7 +51,7 @@ func runFail(cmdline ...string) { func main() { var err error - tmpDir, err = ioutil.TempDir("", "") + tmpDir, err = os.MkdirTemp("", "") if err != nil { fmt.Println(err) os.Exit(1) diff --git a/test/linkobj.go b/test/linkobj.go index 4c9bd24568b112..cdb09181db6131 100644 --- a/test/linkobj.go +++ b/test/linkobj.go @@ -11,7 +11,6 @@ package main import ( "fmt" - "io/ioutil" "log" "os" "os/exec" @@ -21,7 +20,7 @@ import ( var pwd, tmpdir string func main() { - dir, err := ioutil.TempDir("", "go-test-linkobj-") + dir, err := os.MkdirTemp("", "go-test-linkobj-") if err != nil { log.Fatal(err) } @@ -122,18 +121,18 @@ func runFail(args ...string) string { } func cp(src, dst string) { - data, err := ioutil.ReadFile(src) + data, err := os.ReadFile(src) if err != nil { fatalf("%v", err) } - err = ioutil.WriteFile(dst, data, 0666) + err = os.WriteFile(dst, data, 0666) if err != nil { fatalf("%v", err) } } func writeFile(name, data string) { - err := ioutil.WriteFile(name, []byte(data), 0666) + err := os.WriteFile(name, []byte(data), 0666) if err != nil { fatalf("%v", err) } diff --git a/test/nosplit.go b/test/nosplit.go index 7c7e1bfd99e01a..5b2503041b12b1 100644 --- a/test/nosplit.go +++ b/test/nosplit.go @@ -10,7 +10,6 @@ package main import ( "bytes" "fmt" - "io/ioutil" "log" "os" "os/exec" @@ -201,7 +200,7 @@ func main() { goarch = runtime.GOARCH } - dir, err := ioutil.TempDir("", "go-test-nosplit") + dir, err := os.MkdirTemp("", "go-test-nosplit") if err != nil { bug() fmt.Printf("creating temp dir: %v\n", err) @@ -210,7 +209,7 @@ func main() { defer os.RemoveAll(dir) os.Setenv("GOPATH", filepath.Join(dir, "_gopath")) - if err := ioutil.WriteFile(filepath.Join(dir, "go.mod"), []byte("module go-test-nosplit\n"), 0666); err != nil { + if err := os.WriteFile(filepath.Join(dir, "go.mod"), []byte("module go-test-nosplit\n"), 0666); err != nil { log.Panic(err) } @@ -351,10 +350,10 @@ TestCases: fmt.Printf("-- asm.s --\n%s", buf.String()) } - if err := ioutil.WriteFile(filepath.Join(dir, "asm.s"), buf.Bytes(), 0666); err != nil { + if err := os.WriteFile(filepath.Join(dir, "asm.s"), buf.Bytes(), 0666); err != nil { log.Fatal(err) } - if err := ioutil.WriteFile(filepath.Join(dir, "main.go"), gobuf.Bytes(), 0666); err != nil { + if err := os.WriteFile(filepath.Join(dir, "main.go"), gobuf.Bytes(), 0666); err != nil { log.Fatal(err) } diff --git a/test/run.go b/test/run.go index 7d5a558f2d2753..038908f0dd8b85 100644 --- a/test/run.go +++ b/test/run.go @@ -15,7 +15,6 @@ import ( "hash/fnv" "io" "io/fs" - "io/ioutil" "log" "os" "os/exec" @@ -313,8 +312,8 @@ func (t *test) goDirName() string { return filepath.Join(t.dir, strings.Replace(t.gofile, ".go", ".dir", -1)) } -func goDirFiles(longdir string) (filter []os.FileInfo, err error) { - files, dirErr := ioutil.ReadDir(longdir) +func goDirFiles(longdir string) (filter []os.DirEntry, err error) { + files, dirErr := os.ReadDir(longdir) if dirErr != nil { return nil, dirErr } @@ -329,7 +328,7 @@ func goDirFiles(longdir string) (filter []os.FileInfo, err error) { var packageRE = regexp.MustCompile(`(?m)^package ([\p{Lu}\p{Ll}\w]+)`) func getPackageNameFromSource(fn string) (string, error) { - data, err := ioutil.ReadFile(fn) + data, err := os.ReadFile(fn) if err != nil { return "", err } @@ -477,7 +476,7 @@ func (t *test) run() { close(t.donec) }() - srcBytes, err := ioutil.ReadFile(t.goFileName()) + srcBytes, err := os.ReadFile(t.goFileName()) if err != nil { t.err = err return @@ -600,7 +599,7 @@ func (t *test) run() { defer os.RemoveAll(t.tempDir) } - err = ioutil.WriteFile(filepath.Join(t.tempDir, t.gofile), srcBytes, 0644) + err = os.WriteFile(filepath.Join(t.tempDir, t.gofile), srcBytes, 0644) if err != nil { log.Fatal(err) } @@ -957,7 +956,7 @@ func (t *test) run() { } modFile := fmt.Sprintf("module %s\ngo 1.14\n", modName) - if err := ioutil.WriteFile(filepath.Join(gopathSrcDir, "go.mod"), []byte(modFile), 0666); err != nil { + if err := os.WriteFile(filepath.Join(gopathSrcDir, "go.mod"), []byte(modFile), 0666); err != nil { t.err = err return } @@ -986,7 +985,7 @@ func (t *test) run() { // Build an executable from all the .go and .s files in a subdirectory. // Run it and verify its output in the buildrundir case. longdir := filepath.Join(cwd, t.goDirName()) - files, dirErr := ioutil.ReadDir(longdir) + files, dirErr := os.ReadDir(longdir) if dirErr != nil { t.err = dirErr break @@ -1004,7 +1003,7 @@ func (t *test) run() { } if len(asms) > 0 { emptyHdrFile := filepath.Join(t.tempDir, "go_asm.h") - if err := ioutil.WriteFile(emptyHdrFile, nil, 0666); err != nil { + if err := os.WriteFile(emptyHdrFile, nil, 0666); err != nil { t.err = fmt.Errorf("write empty go_asm.h: %s", err) return } @@ -1148,7 +1147,7 @@ func (t *test) run() { return } tfile := filepath.Join(t.tempDir, "tmp__.go") - if err := ioutil.WriteFile(tfile, out, 0666); err != nil { + if err := os.WriteFile(tfile, out, 0666); err != nil { t.err = fmt.Errorf("write tempfile:%s", err) return } @@ -1179,7 +1178,7 @@ func (t *test) run() { return } tfile := filepath.Join(t.tempDir, "tmp__.go") - err = ioutil.WriteFile(tfile, out, 0666) + err = os.WriteFile(tfile, out, 0666) if err != nil { t.err = fmt.Errorf("write tempfile:%s", err) return @@ -1227,7 +1226,7 @@ func (t *test) String() string { func (t *test) makeTempDir() { var err error - t.tempDir, err = ioutil.TempDir("", "") + t.tempDir, err = os.MkdirTemp("", "") if err != nil { log.Fatal(err) } @@ -1244,7 +1243,7 @@ func (t *test) checkExpectedOutput(gotBytes []byte) { filename := filepath.Join(t.dir, t.gofile) filename = filename[:len(filename)-len(".go")] filename += ".out" - b, err := ioutil.ReadFile(filename) + b, err := os.ReadFile(filename) // File is allowed to be missing (err != nil) in which case output should be empty. got = strings.Replace(got, "\r\n", "\n", -1) if got != string(b) { @@ -1366,7 +1365,7 @@ func (t *test) errorCheck(outStr string, wantAuto bool, fullshort ...string) (er func (t *test) updateErrors(out, file string) { base := path.Base(file) // Read in source file. - src, err := ioutil.ReadFile(file) + src, err := os.ReadFile(file) if err != nil { fmt.Fprintln(os.Stderr, err) return @@ -1423,7 +1422,7 @@ func (t *test) updateErrors(out, file string) { } } // Write new file. - err = ioutil.WriteFile(file, []byte(strings.Join(lines, "\n")), 0640) + err = os.WriteFile(file, []byte(strings.Join(lines, "\n")), 0640) if err != nil { fmt.Fprintln(os.Stderr, err) return @@ -1482,7 +1481,7 @@ var ( func (t *test) wantedErrors(file, short string) (errs []wantedError) { cache := make(map[string]*regexp.Regexp) - src, _ := ioutil.ReadFile(file) + src, _ := os.ReadFile(file) for i, line := range strings.Split(string(src), "\n") { lineNum := i + 1 if strings.Contains(line, "////") { @@ -1625,7 +1624,7 @@ func (t *test) wantedAsmOpcodes(fn string) asmChecks { ops := make(asmChecks) comment := "" - src, _ := ioutil.ReadFile(fn) + src, _ := os.ReadFile(fn) for i, line := range strings.Split(string(src), "\n") { matches := rxAsmComment.FindStringSubmatch(line) code, cmt := matches[1], matches[2] diff --git a/test/sinit_run.go b/test/sinit_run.go index dcaf3383312602..127c5abfcf164b 100644 --- a/test/sinit_run.go +++ b/test/sinit_run.go @@ -12,13 +12,12 @@ package main import ( "bytes" "fmt" - "io/ioutil" "os" "os/exec" ) func main() { - f, err := ioutil.TempFile("", "sinit-*.o") + f, err := os.CreateTemp("", "sinit-*.o") if err != nil { fmt.Println(err) os.Exit(1) diff --git a/test/winbatch.go b/test/winbatch.go index 54c2fff13463bd..86a68ca1eaa695 100644 --- a/test/winbatch.go +++ b/test/winbatch.go @@ -12,7 +12,6 @@ package main import ( "bytes" "fmt" - "io/ioutil" "log" "os" "path/filepath" @@ -50,7 +49,7 @@ func main() { } func enforceBatchStrictCRLF(path string) { - b, err := ioutil.ReadFile(path) + b, err := os.ReadFile(path) if err != nil { log.Fatalln(err) } From dda42b09fff36dc08ec1cdec50cc19e3da5058e5 Mon Sep 17 00:00:00 2001 From: KimMachineGun Date: Sat, 3 Apr 2021 17:08:09 +0900 Subject: [PATCH 4/4] test: revert changes in test directory --- test/const7.go | 3 ++- test/fixedbugs/bug302.go | 3 ++- test/fixedbugs/bug369.go | 3 ++- test/fixedbugs/issue11771.go | 5 +++-- test/fixedbugs/issue13268.go | 3 ++- test/fixedbugs/issue16037_run.go | 5 +++-- test/fixedbugs/issue19658.go | 5 +++-- test/fixedbugs/issue21317.go | 3 ++- test/fixedbugs/issue21576.go | 5 +++-- test/fixedbugs/issue22660.go | 5 +++-- test/fixedbugs/issue22662b.go | 5 +++-- test/fixedbugs/issue26411.go | 5 +++-- test/fixedbugs/issue30908.dir/b.go | 4 ++-- test/fixedbugs/issue33555.go | 5 +++-- test/fixedbugs/issue36437.go | 3 ++- test/fixedbugs/issue9355.go | 3 ++- test/linkmain_run.go | 3 ++- test/linkobj.go | 9 ++++---- test/nosplit.go | 9 ++++---- test/run.go | 33 +++++++++++++++--------------- test/sinit_run.go | 3 ++- test/winbatch.go | 3 ++- 22 files changed, 73 insertions(+), 52 deletions(-) diff --git a/test/const7.go b/test/const7.go index e75cebf23dbbed..9ffd678fc5d882 100644 --- a/test/const7.go +++ b/test/const7.go @@ -11,6 +11,7 @@ package main import ( "bytes" "fmt" + "io/ioutil" "log" "os" "os/exec" @@ -62,7 +63,7 @@ func main() { return } - dir, err := os.MkdirTemp("", "const7_") + dir, err := ioutil.TempDir("", "const7_") if err != nil { log.Fatalf("creating temp dir: %v\n", err) } diff --git a/test/fixedbugs/bug302.go b/test/fixedbugs/bug302.go index 344697fd7131dd..a2ab661277a38f 100644 --- a/test/fixedbugs/bug302.go +++ b/test/fixedbugs/bug302.go @@ -9,6 +9,7 @@ package main import ( "fmt" + "io/ioutil" "os" "os/exec" "path/filepath" @@ -19,7 +20,7 @@ var tmpDir string func main() { fb, err := filepath.Abs("fixedbugs") if err == nil { - tmpDir, err = os.MkdirTemp("", "bug302") + tmpDir, err = ioutil.TempDir("", "bug302") } if err != nil { fmt.Println(err) diff --git a/test/fixedbugs/bug369.go b/test/fixedbugs/bug369.go index 5fe71b8006eff7..83f638d04632af 100644 --- a/test/fixedbugs/bug369.go +++ b/test/fixedbugs/bug369.go @@ -11,6 +11,7 @@ package main import ( "fmt" + "io/ioutil" "os" "os/exec" "path/filepath" @@ -20,7 +21,7 @@ func main() { err := os.Chdir(filepath.Join(".", "fixedbugs", "bug369.dir")) check(err) - tmpDir, err := os.MkdirTemp("", "bug369") + tmpDir, err := ioutil.TempDir("", "bug369") check(err) defer os.RemoveAll(tmpDir) diff --git a/test/fixedbugs/issue11771.go b/test/fixedbugs/issue11771.go index 74c601142d814d..c95dd6ba396584 100644 --- a/test/fixedbugs/issue11771.go +++ b/test/fixedbugs/issue11771.go @@ -12,6 +12,7 @@ package main import ( "bytes" "fmt" + "io/ioutil" "log" "os" "os/exec" @@ -24,7 +25,7 @@ func main() { return } - dir, err := os.MkdirTemp("", "go-issue11771") + dir, err := ioutil.TempDir("", "go-issue11771") if err != nil { log.Fatalf("creating temp dir: %v\n", err) } @@ -47,7 +48,7 @@ func x() { } `) - if err := os.WriteFile(filepath.Join(dir, "x.go"), buf.Bytes(), 0666); err != nil { + if err := ioutil.WriteFile(filepath.Join(dir, "x.go"), buf.Bytes(), 0666); err != nil { log.Fatal(err) } diff --git a/test/fixedbugs/issue13268.go b/test/fixedbugs/issue13268.go index 452bfc83b5aee7..53a82d5074ab97 100644 --- a/test/fixedbugs/issue13268.go +++ b/test/fixedbugs/issue13268.go @@ -14,6 +14,7 @@ package main import ( + "io/ioutil" "log" "os" "os/exec" @@ -22,7 +23,7 @@ import ( func main() { // create source - f, err := os.CreateTemp("", "issue13268-") + f, err := ioutil.TempFile("", "issue13268-") if err != nil { log.Fatalf("could not create source file: %v", err) } diff --git a/test/fixedbugs/issue16037_run.go b/test/fixedbugs/issue16037_run.go index 0bd0d526e295a5..68104a9000795d 100644 --- a/test/fixedbugs/issue16037_run.go +++ b/test/fixedbugs/issue16037_run.go @@ -11,6 +11,7 @@ import ( "bytes" "fmt" "html/template" + "io/ioutil" "log" "os" "os/exec" @@ -52,13 +53,13 @@ func main() { log.Fatal(err) } - dir, err := os.MkdirTemp("", "issue16037-") + dir, err := ioutil.TempDir("", "issue16037-") if err != nil { log.Fatal(err) } defer os.RemoveAll(dir) path := filepath.Join(dir, "ridiculous_number_of_fields.go") - if err := os.WriteFile(path, buf.Bytes(), 0664); err != nil { + if err := ioutil.WriteFile(path, buf.Bytes(), 0664); err != nil { log.Fatal(err) } diff --git a/test/fixedbugs/issue19658.go b/test/fixedbugs/issue19658.go index b6b5c09461879a..bab409c6c03cc8 100644 --- a/test/fixedbugs/issue19658.go +++ b/test/fixedbugs/issue19658.go @@ -11,6 +11,7 @@ package main import ( "bytes" "fmt" + "io/ioutil" "log" "os" "os/exec" @@ -34,7 +35,7 @@ func main() { ` func main() { - tempDir, err := os.MkdirTemp("", "") + tempDir, err := ioutil.TempDir("", "") if err != nil { log.Fatal(err) } @@ -69,7 +70,7 @@ func main() { b := bytes.Buffer{} fmt.Fprintf(&b, fn, tc.Type, tc.Input) - err = os.WriteFile(tmpFile, b.Bytes(), 0644) + err = ioutil.WriteFile(tmpFile, b.Bytes(), 0644) if err != nil { log.Fatal(err) } diff --git a/test/fixedbugs/issue21317.go b/test/fixedbugs/issue21317.go index 2c634a7074730f..32b660c1639169 100644 --- a/test/fixedbugs/issue21317.go +++ b/test/fixedbugs/issue21317.go @@ -13,6 +13,7 @@ package main import ( "fmt" + "io/ioutil" "log" "os" "os/exec" @@ -20,7 +21,7 @@ import ( ) func main() { - f, err := os.CreateTemp("", "issue21317.go") + f, err := ioutil.TempFile("", "issue21317.go") if err != nil { log.Fatal(err) } diff --git a/test/fixedbugs/issue21576.go b/test/fixedbugs/issue21576.go index f7b3d46711d744..3f9b1ba008af4c 100644 --- a/test/fixedbugs/issue21576.go +++ b/test/fixedbugs/issue21576.go @@ -14,6 +14,7 @@ package main import ( "bytes" "context" + "io/ioutil" "log" "os" "os/exec" @@ -33,14 +34,14 @@ func main() { ` func main() { - dir, err := os.MkdirTemp("", "21576") + dir, err := ioutil.TempDir("", "21576") if err != nil { log.Fatal(err) } defer os.RemoveAll(dir) file := filepath.Join(dir, "main.go") - if err := os.WriteFile(file, []byte(prog), 0655); err != nil { + if err := ioutil.WriteFile(file, []byte(prog), 0655); err != nil { log.Fatalf("Write error %v", err) } diff --git a/test/fixedbugs/issue22660.go b/test/fixedbugs/issue22660.go index 78773cb0a3d369..9ce9c4d732e6d4 100644 --- a/test/fixedbugs/issue22660.go +++ b/test/fixedbugs/issue22660.go @@ -10,6 +10,7 @@ package main import ( "bytes" "fmt" + "io/ioutil" "log" "os" "os/exec" @@ -18,7 +19,7 @@ import ( ) func main() { - f, err := os.CreateTemp("", "issue22660.go") + f, err := ioutil.TempFile("", "issue22660.go") if err != nil { log.Fatal(err) } @@ -30,7 +31,7 @@ func main() { var src bytes.Buffer fmt.Fprintf(&src, "//line %s:1\n", filepath.Join(path, "foo.go")) - if err := os.WriteFile(f.Name(), src.Bytes(), 0660); err != nil { + if err := ioutil.WriteFile(f.Name(), src.Bytes(), 0660); err != nil { log.Fatal(err) } diff --git a/test/fixedbugs/issue22662b.go b/test/fixedbugs/issue22662b.go index 05cd2b9d5e025f..8da17679be08e9 100644 --- a/test/fixedbugs/issue22662b.go +++ b/test/fixedbugs/issue22662b.go @@ -10,6 +10,7 @@ package main import ( + "io/ioutil" "log" "os" "os/exec" @@ -35,7 +36,7 @@ var tests = []struct { } func main() { - f, err := os.CreateTemp("", "issue22662b.go") + f, err := ioutil.TempFile("", "issue22662b.go") if err != nil { log.Fatal(err) } @@ -43,7 +44,7 @@ func main() { defer os.Remove(f.Name()) for _, test := range tests { - if err := os.WriteFile(f.Name(), []byte(test.src), 0660); err != nil { + if err := ioutil.WriteFile(f.Name(), []byte(test.src), 0660); err != nil { log.Fatal(err) } diff --git a/test/fixedbugs/issue26411.go b/test/fixedbugs/issue26411.go index 36850ac4df83e2..5f40bf25229a1a 100644 --- a/test/fixedbugs/issue26411.go +++ b/test/fixedbugs/issue26411.go @@ -14,6 +14,7 @@ package main import ( "bytes" "fmt" + "io/ioutil" "log" "os" "os/exec" @@ -22,7 +23,7 @@ import ( ) func main() { - tmpdir, err := os.MkdirTemp("", "issue26411") + tmpdir, err := ioutil.TempDir("", "issue26411") if err != nil { log.Fatalf("Failed to create temporary directory: %v", err) } @@ -70,7 +71,7 @@ bar : for i, test := range tests { filename := filepath.Join(tmpdir, fmt.Sprintf("%d.go", i)) - if err := os.WriteFile(filename, []byte(test.code), 0644); err != nil { + if err := ioutil.WriteFile(filename, []byte(test.code), 0644); err != nil { log.Printf("#%d: failed to create file %s", i, filename) continue } diff --git a/test/fixedbugs/issue30908.dir/b.go b/test/fixedbugs/issue30908.dir/b.go index e6f1450df83caa..2f543985b4fc39 100644 --- a/test/fixedbugs/issue30908.dir/b.go +++ b/test/fixedbugs/issue30908.dir/b.go @@ -5,7 +5,7 @@ package b import ( - "os" + "io/ioutil" "./a" ) @@ -27,7 +27,7 @@ func ReadValues(data []byte) (vals map[string]interface{}, err error) { // of the output param. func CallReadValues(filename string) (map[string]interface{}, error) { defer func() { G++ }() - data, err := os.ReadFile(filename) + data, err := ioutil.ReadFile(filename) if err != nil { return map[string]interface{}{}, err } diff --git a/test/fixedbugs/issue33555.go b/test/fixedbugs/issue33555.go index 560dbdff8a9955..c1fcd2a79b387a 100644 --- a/test/fixedbugs/issue33555.go +++ b/test/fixedbugs/issue33555.go @@ -11,6 +11,7 @@ package main import ( "bytes" "fmt" + "io/ioutil" "os" "os/exec" "path/filepath" @@ -55,14 +56,14 @@ func test() error { } fmt.Fprintf(&buf, fnlast, count) - dir, err := os.MkdirTemp("", "issue33555") + dir, err := ioutil.TempDir("", "issue33555") if err != nil { return err } defer os.RemoveAll(dir) fn := filepath.Join(dir, "x.go") - if err := os.WriteFile(fn, buf.Bytes(), 0644); err != nil { + if err := ioutil.WriteFile(fn, buf.Bytes(), 0644); err != nil { return err } diff --git a/test/fixedbugs/issue36437.go b/test/fixedbugs/issue36437.go index 01099b7a60318a..c7a11d27a89349 100644 --- a/test/fixedbugs/issue36437.go +++ b/test/fixedbugs/issue36437.go @@ -18,13 +18,14 @@ package main import ( "fmt" + "io/ioutil" "os" "os/exec" "regexp" ) func main() { - tmpDir, err := os.MkdirTemp("", "issue36437") + tmpDir, err := ioutil.TempDir("", "issue36437") if err != nil { panic(err) } diff --git a/test/fixedbugs/issue9355.go b/test/fixedbugs/issue9355.go index bfd032f99d7631..319a2a90df9ba2 100644 --- a/test/fixedbugs/issue9355.go +++ b/test/fixedbugs/issue9355.go @@ -9,6 +9,7 @@ package main import ( "fmt" + "io/ioutil" "os" "os/exec" "path/filepath" @@ -19,7 +20,7 @@ func main() { err := os.Chdir(filepath.Join("fixedbugs", "issue9355.dir")) check(err) - f, err := os.CreateTemp("", "issue9355-*.o") + f, err := ioutil.TempFile("", "issue9355-*.o") if err != nil { fmt.Println(err) os.Exit(1) diff --git a/test/linkmain_run.go b/test/linkmain_run.go index 91156b69e160a5..077f7ee91753c5 100644 --- a/test/linkmain_run.go +++ b/test/linkmain_run.go @@ -11,6 +11,7 @@ package main import ( "fmt" + "io/ioutil" "os" "os/exec" "path/filepath" @@ -51,7 +52,7 @@ func runFail(cmdline ...string) { func main() { var err error - tmpDir, err = os.MkdirTemp("", "") + tmpDir, err = ioutil.TempDir("", "") if err != nil { fmt.Println(err) os.Exit(1) diff --git a/test/linkobj.go b/test/linkobj.go index cdb09181db6131..4c9bd24568b112 100644 --- a/test/linkobj.go +++ b/test/linkobj.go @@ -11,6 +11,7 @@ package main import ( "fmt" + "io/ioutil" "log" "os" "os/exec" @@ -20,7 +21,7 @@ import ( var pwd, tmpdir string func main() { - dir, err := os.MkdirTemp("", "go-test-linkobj-") + dir, err := ioutil.TempDir("", "go-test-linkobj-") if err != nil { log.Fatal(err) } @@ -121,18 +122,18 @@ func runFail(args ...string) string { } func cp(src, dst string) { - data, err := os.ReadFile(src) + data, err := ioutil.ReadFile(src) if err != nil { fatalf("%v", err) } - err = os.WriteFile(dst, data, 0666) + err = ioutil.WriteFile(dst, data, 0666) if err != nil { fatalf("%v", err) } } func writeFile(name, data string) { - err := os.WriteFile(name, []byte(data), 0666) + err := ioutil.WriteFile(name, []byte(data), 0666) if err != nil { fatalf("%v", err) } diff --git a/test/nosplit.go b/test/nosplit.go index 5b2503041b12b1..7c7e1bfd99e01a 100644 --- a/test/nosplit.go +++ b/test/nosplit.go @@ -10,6 +10,7 @@ package main import ( "bytes" "fmt" + "io/ioutil" "log" "os" "os/exec" @@ -200,7 +201,7 @@ func main() { goarch = runtime.GOARCH } - dir, err := os.MkdirTemp("", "go-test-nosplit") + dir, err := ioutil.TempDir("", "go-test-nosplit") if err != nil { bug() fmt.Printf("creating temp dir: %v\n", err) @@ -209,7 +210,7 @@ func main() { defer os.RemoveAll(dir) os.Setenv("GOPATH", filepath.Join(dir, "_gopath")) - if err := os.WriteFile(filepath.Join(dir, "go.mod"), []byte("module go-test-nosplit\n"), 0666); err != nil { + if err := ioutil.WriteFile(filepath.Join(dir, "go.mod"), []byte("module go-test-nosplit\n"), 0666); err != nil { log.Panic(err) } @@ -350,10 +351,10 @@ TestCases: fmt.Printf("-- asm.s --\n%s", buf.String()) } - if err := os.WriteFile(filepath.Join(dir, "asm.s"), buf.Bytes(), 0666); err != nil { + if err := ioutil.WriteFile(filepath.Join(dir, "asm.s"), buf.Bytes(), 0666); err != nil { log.Fatal(err) } - if err := os.WriteFile(filepath.Join(dir, "main.go"), gobuf.Bytes(), 0666); err != nil { + if err := ioutil.WriteFile(filepath.Join(dir, "main.go"), gobuf.Bytes(), 0666); err != nil { log.Fatal(err) } diff --git a/test/run.go b/test/run.go index 038908f0dd8b85..7d5a558f2d2753 100644 --- a/test/run.go +++ b/test/run.go @@ -15,6 +15,7 @@ import ( "hash/fnv" "io" "io/fs" + "io/ioutil" "log" "os" "os/exec" @@ -312,8 +313,8 @@ func (t *test) goDirName() string { return filepath.Join(t.dir, strings.Replace(t.gofile, ".go", ".dir", -1)) } -func goDirFiles(longdir string) (filter []os.DirEntry, err error) { - files, dirErr := os.ReadDir(longdir) +func goDirFiles(longdir string) (filter []os.FileInfo, err error) { + files, dirErr := ioutil.ReadDir(longdir) if dirErr != nil { return nil, dirErr } @@ -328,7 +329,7 @@ func goDirFiles(longdir string) (filter []os.DirEntry, err error) { var packageRE = regexp.MustCompile(`(?m)^package ([\p{Lu}\p{Ll}\w]+)`) func getPackageNameFromSource(fn string) (string, error) { - data, err := os.ReadFile(fn) + data, err := ioutil.ReadFile(fn) if err != nil { return "", err } @@ -476,7 +477,7 @@ func (t *test) run() { close(t.donec) }() - srcBytes, err := os.ReadFile(t.goFileName()) + srcBytes, err := ioutil.ReadFile(t.goFileName()) if err != nil { t.err = err return @@ -599,7 +600,7 @@ func (t *test) run() { defer os.RemoveAll(t.tempDir) } - err = os.WriteFile(filepath.Join(t.tempDir, t.gofile), srcBytes, 0644) + err = ioutil.WriteFile(filepath.Join(t.tempDir, t.gofile), srcBytes, 0644) if err != nil { log.Fatal(err) } @@ -956,7 +957,7 @@ func (t *test) run() { } modFile := fmt.Sprintf("module %s\ngo 1.14\n", modName) - if err := os.WriteFile(filepath.Join(gopathSrcDir, "go.mod"), []byte(modFile), 0666); err != nil { + if err := ioutil.WriteFile(filepath.Join(gopathSrcDir, "go.mod"), []byte(modFile), 0666); err != nil { t.err = err return } @@ -985,7 +986,7 @@ func (t *test) run() { // Build an executable from all the .go and .s files in a subdirectory. // Run it and verify its output in the buildrundir case. longdir := filepath.Join(cwd, t.goDirName()) - files, dirErr := os.ReadDir(longdir) + files, dirErr := ioutil.ReadDir(longdir) if dirErr != nil { t.err = dirErr break @@ -1003,7 +1004,7 @@ func (t *test) run() { } if len(asms) > 0 { emptyHdrFile := filepath.Join(t.tempDir, "go_asm.h") - if err := os.WriteFile(emptyHdrFile, nil, 0666); err != nil { + if err := ioutil.WriteFile(emptyHdrFile, nil, 0666); err != nil { t.err = fmt.Errorf("write empty go_asm.h: %s", err) return } @@ -1147,7 +1148,7 @@ func (t *test) run() { return } tfile := filepath.Join(t.tempDir, "tmp__.go") - if err := os.WriteFile(tfile, out, 0666); err != nil { + if err := ioutil.WriteFile(tfile, out, 0666); err != nil { t.err = fmt.Errorf("write tempfile:%s", err) return } @@ -1178,7 +1179,7 @@ func (t *test) run() { return } tfile := filepath.Join(t.tempDir, "tmp__.go") - err = os.WriteFile(tfile, out, 0666) + err = ioutil.WriteFile(tfile, out, 0666) if err != nil { t.err = fmt.Errorf("write tempfile:%s", err) return @@ -1226,7 +1227,7 @@ func (t *test) String() string { func (t *test) makeTempDir() { var err error - t.tempDir, err = os.MkdirTemp("", "") + t.tempDir, err = ioutil.TempDir("", "") if err != nil { log.Fatal(err) } @@ -1243,7 +1244,7 @@ func (t *test) checkExpectedOutput(gotBytes []byte) { filename := filepath.Join(t.dir, t.gofile) filename = filename[:len(filename)-len(".go")] filename += ".out" - b, err := os.ReadFile(filename) + b, err := ioutil.ReadFile(filename) // File is allowed to be missing (err != nil) in which case output should be empty. got = strings.Replace(got, "\r\n", "\n", -1) if got != string(b) { @@ -1365,7 +1366,7 @@ func (t *test) errorCheck(outStr string, wantAuto bool, fullshort ...string) (er func (t *test) updateErrors(out, file string) { base := path.Base(file) // Read in source file. - src, err := os.ReadFile(file) + src, err := ioutil.ReadFile(file) if err != nil { fmt.Fprintln(os.Stderr, err) return @@ -1422,7 +1423,7 @@ func (t *test) updateErrors(out, file string) { } } // Write new file. - err = os.WriteFile(file, []byte(strings.Join(lines, "\n")), 0640) + err = ioutil.WriteFile(file, []byte(strings.Join(lines, "\n")), 0640) if err != nil { fmt.Fprintln(os.Stderr, err) return @@ -1481,7 +1482,7 @@ var ( func (t *test) wantedErrors(file, short string) (errs []wantedError) { cache := make(map[string]*regexp.Regexp) - src, _ := os.ReadFile(file) + src, _ := ioutil.ReadFile(file) for i, line := range strings.Split(string(src), "\n") { lineNum := i + 1 if strings.Contains(line, "////") { @@ -1624,7 +1625,7 @@ func (t *test) wantedAsmOpcodes(fn string) asmChecks { ops := make(asmChecks) comment := "" - src, _ := os.ReadFile(fn) + src, _ := ioutil.ReadFile(fn) for i, line := range strings.Split(string(src), "\n") { matches := rxAsmComment.FindStringSubmatch(line) code, cmt := matches[1], matches[2] diff --git a/test/sinit_run.go b/test/sinit_run.go index 127c5abfcf164b..dcaf3383312602 100644 --- a/test/sinit_run.go +++ b/test/sinit_run.go @@ -12,12 +12,13 @@ package main import ( "bytes" "fmt" + "io/ioutil" "os" "os/exec" ) func main() { - f, err := os.CreateTemp("", "sinit-*.o") + f, err := ioutil.TempFile("", "sinit-*.o") if err != nil { fmt.Println(err) os.Exit(1) diff --git a/test/winbatch.go b/test/winbatch.go index 86a68ca1eaa695..54c2fff13463bd 100644 --- a/test/winbatch.go +++ b/test/winbatch.go @@ -12,6 +12,7 @@ package main import ( "bytes" "fmt" + "io/ioutil" "log" "os" "path/filepath" @@ -49,7 +50,7 @@ func main() { } func enforceBatchStrictCRLF(path string) { - b, err := os.ReadFile(path) + b, err := ioutil.ReadFile(path) if err != nil { log.Fatalln(err) }