Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove ioutil (fixes #106) #108

Merged
merged 2 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions bootstrap/cmd/bootstrap-pigeon/bench_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package main

import (
"io/ioutil"
"os"
"testing"
)

func BenchmarkParsePigeonNoMemo(b *testing.B) {
d, err := ioutil.ReadFile("../../../grammar/pigeon.peg")
d, err := os.ReadFile("../../../grammar/pigeon.peg")
if err != nil {
b.Fatal(err)
}
Expand All @@ -20,7 +20,7 @@ func BenchmarkParsePigeonNoMemo(b *testing.B) {
}

func BenchmarkParsePigeonMemo(b *testing.B) {
d, err := ioutil.ReadFile("../../../grammar/pigeon.peg")
d, err := os.ReadFile("../../../grammar/pigeon.peg")
if err != nil {
b.Fatal(err)
}
Expand Down
26 changes: 12 additions & 14 deletions bootstrap/cmd/bootstrap-pigeon/bootstrap_pigeon.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions bootstrap/cmd/static_code_generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package main

import (
"fmt"
"io/ioutil"
"os"
"strings"
)
Expand All @@ -25,7 +24,7 @@ var %s = ` + "`"
)

func generateFile(source, dest, varname string) {
staticCode, err := ioutil.ReadFile(source)
staticCode, err := os.ReadFile(source)
if err != nil {
panic(err)
}
Expand All @@ -44,7 +43,7 @@ func generateFile(source, dest, varname string) {
}
dstLines = append(dstLines, strings.Split(footer, eol)...)

err = ioutil.WriteFile(dest, []byte(strings.Join(dstLines, eol)+eol), 0644)
err = os.WriteFile(dest, []byte(strings.Join(dstLines, eol)+eol), 0644)
if err != nil {
panic(err)
}
Expand Down
4 changes: 2 additions & 2 deletions builder/builder_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package builder

import (
"io/ioutil"
"io"
"strings"
"testing"

Expand Down Expand Up @@ -34,7 +34,7 @@ func TestBuildParser(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if err := BuildParser(ioutil.Discard, g); err != nil {
if err := BuildParser(io.Discard, g); err != nil {
t.Fatal(err)
}
}
2 changes: 1 addition & 1 deletion builder/generated_static_code.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions builder/static_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"math"
"os"
"sort"
Expand Down Expand Up @@ -202,7 +201,7 @@ func ParseFile(filename string, opts ...Option) (i interface{}, err error) { //{
// ParseReader parses the data from r using filename as information in the
// error messages.
func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, error) { //{{ if .Nolint }} nolint: deadcode {{else}} ==template== {{ end }}
b, err := ioutil.ReadAll(r)
b, err := io.ReadAll(r)
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions examples/calculator/calculator.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions examples/indentation/indentation.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions examples/json/cmd/json-parser/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"log"
"os"
"strings"
Expand All @@ -29,7 +29,7 @@ func main() {
nm = os.Args[1]
}

b, err := ioutil.ReadAll(in)
b, err := io.ReadAll(in)
if err != nil {
log.Fatal(err)
}
Expand Down
3 changes: 1 addition & 2 deletions examples/json/json.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions examples/json/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package json

import (
"encoding/json"
"io/ioutil"
"os"
"path/filepath"
"reflect"
"testing"
Expand Down Expand Up @@ -32,9 +32,9 @@ func TestCmpStdlib(t *testing.T) {
continue
}

b, err := ioutil.ReadFile(file)
b, err := os.ReadFile(file)
if err != nil {
t.Errorf("%s: ioutil.ReadAll: %v", file, err)
t.Errorf("%s: os.ReadFile: %v", file, err)
continue
}
var jgot interface{}
Expand Down Expand Up @@ -63,7 +63,7 @@ func TestCmpStdlib(t *testing.T) {
func testJSONFiles(t *testing.T) []string {
const rootDir = "testdata"

fis, err := ioutil.ReadDir(rootDir)
fis, err := os.ReadDir(rootDir)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -138,7 +138,7 @@ func TestForwardSlash(t *testing.T) {
}

func BenchmarkPigeonJSONNoMemo(b *testing.B) {
d, err := ioutil.ReadFile("testdata/github-octokit-repos.json")
d, err := os.ReadFile("testdata/github-octokit-repos.json")
if err != nil {
b.Fatal(err)
}
Expand All @@ -152,7 +152,7 @@ func BenchmarkPigeonJSONNoMemo(b *testing.B) {
}

func BenchmarkPigeonJSONMemo(b *testing.B) {
d, err := ioutil.ReadFile("testdata/github-octokit-repos.json")
d, err := os.ReadFile("testdata/github-octokit-repos.json")
if err != nil {
b.Fatal(err)
}
Expand All @@ -166,7 +166,7 @@ func BenchmarkPigeonJSONMemo(b *testing.B) {
}

func BenchmarkPigeonJSONOptimized(b *testing.B) {
d, err := ioutil.ReadFile("testdata/github-octokit-repos.json")
d, err := os.ReadFile("testdata/github-octokit-repos.json")
if err != nil {
b.Fatal(err)
}
Expand All @@ -180,7 +180,7 @@ func BenchmarkPigeonJSONOptimized(b *testing.B) {
}

func BenchmarkPigeonJSONOptimizedGrammar(b *testing.B) {
d, err := ioutil.ReadFile("testdata/github-octokit-repos.json")
d, err := os.ReadFile("testdata/github-octokit-repos.json")
if err != nil {
b.Fatal(err)
}
Expand All @@ -194,7 +194,7 @@ func BenchmarkPigeonJSONOptimizedGrammar(b *testing.B) {
}

func BenchmarkStdlibJSON(b *testing.B) {
d, err := ioutil.ReadFile("testdata/github-octokit-repos.json")
d, err := os.ReadFile("testdata/github-octokit-repos.json")
if err != nil {
b.Fatal(err)
}
Expand Down
3 changes: 1 addition & 2 deletions examples/json/optimized-grammar/json.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions examples/json/optimized/json.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 12 additions & 14 deletions pigeon.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions test/alternate_entrypoint/altentry.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions test/andnot/andnot.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.