Skip to content

Commit

Permalink
remove almost all references to ioutil
Browse files Browse the repository at this point in the history
Signed-off-by: Joe Fitzgerald <[email protected]>
  • Loading branch information
joefitzgerald committed Nov 17, 2023
1 parent 2bdcf66 commit 81ff4b8
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 29 deletions.
6 changes: 3 additions & 3 deletions arguments/parser_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// +build !windows
//go:build !windows

package arguments_test

import (
"errors"
"fmt"
"io/ioutil"
"io"
"log"
"os"
"path"
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions arguments/parser_windows_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// +build windows
//go:build windows

package arguments_test

import (
"io/ioutil"
"io"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions benchmark_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"io/ioutil"
"io"
"log"
"path/filepath"
"testing"
Expand All @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions command/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package command
import (
"fmt"
"go/build"
"io/ioutil"
"os"
"path/filepath"
"sort"
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions generator/file_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package generator

import (
"io"
"io/ioutil"
"os"
"path/filepath"
)
Expand All @@ -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
}
Expand Down
5 changes: 2 additions & 3 deletions generator/file_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package generator_test
import (
"fmt"
"io"
"io/ioutil"
"reflect"
"strings"
"testing"
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions generator/generator_internals_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package generator

import (
"io/ioutil"
"io"
"log"
"runtime"
"testing"
Expand All @@ -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{}))
}
Expand Down
1 change: 1 addition & 0 deletions integration/roundtrip_module_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build go1.11
// +build go1.11

package integration_test
Expand Down
14 changes: 7 additions & 7 deletions integration/roundtrip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package integration_test
import (
"fmt"
"go/build"
"io/ioutil"
"io"
"log"
"os"
"path/filepath"
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)))
})
Expand Down
7 changes: 4 additions & 3 deletions integration/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"errors"
"fmt"
"go/format"
"io/ioutil"
"io"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 81ff4b8

Please sign in to comment.