diff --git a/arguments/parser_test.go b/arguments/parser_test.go index b231096..dbf2d86 100644 --- a/arguments/parser_test.go +++ b/arguments/parser_test.go @@ -1,11 +1,11 @@ -// +build !windows +//go:build !windows package arguments_test import ( "errors" "fmt" - "io/ioutil" + "io" "log" "os" "path" @@ -41,7 +41,7 @@ func testParsingArguments(t *testing.T, when spec.G, it spec.S) { it.Before(func() { RegisterTestingT(t) - log.SetOutput(ioutil.Discard) + log.SetOutput(io.Discard) workingDir = "/home/test-user/workspace" evaler = func(input string) (string, error) { diff --git a/arguments/parser_windows_test.go b/arguments/parser_windows_test.go index 87574b8..1d4ff37 100644 --- a/arguments/parser_windows_test.go +++ b/arguments/parser_windows_test.go @@ -1,9 +1,9 @@ -// +build windows +//go:build windows package arguments_test import ( - "io/ioutil" + "io" "log" "os" "path/filepath" @@ -38,7 +38,7 @@ func testParsingArguments(t *testing.T, when spec.G, it spec.S) { it.Before(func() { RegisterTestingT(t) - log.SetOutput(ioutil.Discard) + log.SetOutput(io.Discard) workingDir = "C:\\Users\\test-user\\workspace" evaler = func(input string) (string, error) { diff --git a/benchmark_test.go b/benchmark_test.go index c46aa6f..ea966fe 100644 --- a/benchmark_test.go +++ b/benchmark_test.go @@ -1,7 +1,7 @@ package main import ( - "io/ioutil" + "io" "log" "path/filepath" "testing" @@ -16,7 +16,7 @@ func BenchmarkDoGenerate(b *testing.B) { if err != nil { b.Fatal(err) } - log.SetOutput(ioutil.Discard) + log.SetOutput(io.Discard) args := &arguments.ParsedArguments{ GenerateInterfaceAndShimFromPackageDirectory: false, diff --git a/command/runner.go b/command/runner.go index a4e6b7a..161fc4b 100644 --- a/command/runner.go +++ b/command/runner.go @@ -3,7 +3,6 @@ package command import ( "fmt" "go/build" - "io/ioutil" "os" "path/filepath" "sort" @@ -74,7 +73,7 @@ func generateModeInvocations(cwd string) ([]Invocation, error) { } func invocationsInFile(dir string, file string) ([]Invocation, error) { - str, err := ioutil.ReadFile(filepath.Join(dir, file)) + str, err := os.ReadFile(filepath.Join(dir, file)) if err != nil { return nil, err } diff --git a/generator/file_reader.go b/generator/file_reader.go index 1a4f7eb..8e0e77d 100644 --- a/generator/file_reader.go +++ b/generator/file_reader.go @@ -2,7 +2,6 @@ package generator import ( "io" - "io/ioutil" "os" "path/filepath" ) @@ -28,7 +27,7 @@ func (open Opener) readString(path string) (string, error) { } defer f.Close() - b, err := ioutil.ReadAll(f) + b, err := io.ReadAll(f) if err != nil { return "", err } diff --git a/generator/file_reader_test.go b/generator/file_reader_test.go index d8153f5..f0edbed 100644 --- a/generator/file_reader_test.go +++ b/generator/file_reader_test.go @@ -3,7 +3,6 @@ package generator_test import ( "fmt" "io" - "io/ioutil" "reflect" "strings" "testing" @@ -153,13 +152,13 @@ func openReturningErr(err string) generator.Opener { } func openReturningReader(content string) generator.Opener { return func(_ string) (io.ReadCloser, error) { - return ioutil.NopCloser(strings.NewReader(content)), nil + return io.NopCloser(strings.NewReader(content)), nil } } func openReturningFailingReader(err string) generator.Opener { return func(_ string) (io.ReadCloser, error) { r := &erroringReader{ - reader: ioutil.NopCloser(strings.NewReader("some random file content")), + reader: io.NopCloser(strings.NewReader("some random file content")), err: fmt.Errorf(err), } return r, nil diff --git a/generator/generator_internals_test.go b/generator/generator_internals_test.go index f524608..0fb1959 100644 --- a/generator/generator_internals_test.go +++ b/generator/generator_internals_test.go @@ -1,7 +1,7 @@ package generator import ( - "io/ioutil" + "io" "log" "runtime" "testing" @@ -13,7 +13,7 @@ import ( ) func TestGenerator(t *testing.T) { - log.SetOutput(ioutil.Discard) // Comment this out to see verbose log output + log.SetOutput(io.Discard) // Comment this out to see verbose log output log.SetFlags(log.Llongfile) spec.Run(t, "Generator", testGenerator, spec.Report(report.Terminal{})) } diff --git a/integration/roundtrip_module_test.go b/integration/roundtrip_module_test.go index ffbd44d..499b25b 100644 --- a/integration/roundtrip_module_test.go +++ b/integration/roundtrip_module_test.go @@ -1,3 +1,4 @@ +//go:build go1.11 // +build go1.11 package integration_test diff --git a/integration/roundtrip_test.go b/integration/roundtrip_test.go index e62dbb2..55840d0 100644 --- a/integration/roundtrip_test.go +++ b/integration/roundtrip_test.go @@ -3,7 +3,7 @@ package integration_test import ( "fmt" "go/build" - "io/ioutil" + "io" "log" "os" "path/filepath" @@ -17,7 +17,7 @@ import ( ) func runTests(t *testing.T, when spec.G, it spec.S) { - log.SetOutput(ioutil.Discard) // Comment this out to see verbose log output + log.SetOutput(io.Discard) // Comment this out to see verbose log output log.SetFlags(log.Llongfile) var ( baseDir string @@ -41,7 +41,7 @@ func runTests(t *testing.T, when spec.G, it spec.S) { originalGopath = os.Getenv("GOPATH") originalBuildGopath = build.Default.GOPATH var err error - testDir, err = ioutil.TempDir("", "counterfeiter-integration") + testDir, err = os.MkdirTemp("", "counterfeiter-integration") Expect(err).NotTo(HaveOccurred()) os.Unsetenv("GOPATH") baseDir = testDir @@ -63,14 +63,14 @@ func runTests(t *testing.T, when spec.G, it spec.S) { err = os.MkdirAll(dir, 0777) Expect(err).ToNot(HaveOccurred()) - b, err := ioutil.ReadFile(filepath.Join(relativeDir, name)) + b, err := os.ReadFile(filepath.Join(relativeDir, name)) Expect(err).ToNot(HaveOccurred()) - err = ioutil.WriteFile(filepath.Join(baseDir, name), b, 0755) + err = os.WriteFile(filepath.Join(baseDir, name), b, 0755) Expect(err).ToNot(HaveOccurred()) } initModuleFunc = func() { copyFileFunc("blank.go") - err := ioutil.WriteFile(filepath.Join(baseDir, "go.mod"), []byte("module github.com/maxbrunsfeld/counterfeiter/v6/fixtures"), 0755) + err := os.WriteFile(filepath.Join(baseDir, "go.mod"), []byte("module github.com/maxbrunsfeld/counterfeiter/v6/fixtures"), 0755) Expect(err).ToNot(HaveOccurred()) } // Set this to true to write the output of tests to the testdata/output @@ -115,7 +115,7 @@ func runTests(t *testing.T, when spec.G, it spec.S) { } WriteOutput(b, filepath.Join(baseDir, "fixturesfakes", "fake_write_closer."+variant+".go")) RunBuild(baseDir) - b2, err := ioutil.ReadFile(filepath.Join("testdata", "expected_fake_writecloser."+variant+".txt")) + b2, err := os.ReadFile(filepath.Join("testdata", "expected_fake_writecloser."+variant+".txt")) Expect(err).NotTo(HaveOccurred()) Expect(string(b2)).To(Equal(string(b))) }) diff --git a/integration/util_test.go b/integration/util_test.go index 9f6f039..6490f30 100644 --- a/integration/util_test.go +++ b/integration/util_test.go @@ -3,17 +3,18 @@ package integration_test import ( "bytes" "fmt" - "io/ioutil" "os" "os/exec" "path/filepath" + "io/fs" + . "github.com/onsi/gomega" ) func WriteOutput(b []byte, file string) { - os.MkdirAll(filepath.Dir(file), 0700) - ioutil.WriteFile(file, b, 0600) + _ = os.MkdirAll(filepath.Dir(file), 0700) + _ = os.WriteFile(file, b, fs.FileMode(0600)) } func RunBuild(baseDir string) { diff --git a/main.go b/main.go index 0efb3f8..b9b84ce 100644 --- a/main.go +++ b/main.go @@ -4,7 +4,7 @@ import ( "errors" "fmt" "go/format" - "io/ioutil" + "io" "log" "os" "path/filepath" @@ -44,7 +44,7 @@ func run() error { log.SetFlags(log.Lshortfile) if !isDebug() { - log.SetOutput(ioutil.Discard) + log.SetOutput(io.Discard) } cwd, err := os.Getwd()