Skip to content

replace deprecated io/ioutil package #11

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions arm/armasm/decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ package armasm

import (
"encoding/hex"
"io/ioutil"
"os"
"strconv"
"strings"
"testing"
)

func TestDecode(t *testing.T) {
data, err := ioutil.ReadFile("testdata/decode.txt")
data, err := os.ReadFile("testdata/decode.txt")
if err != nil {
t.Fatal(err)
}
Expand Down
5 changes: 2 additions & 3 deletions arm/armasm/ext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"math/rand"
"os"
Expand Down Expand Up @@ -190,7 +189,7 @@ const start = 0x8000 // start address of text
// starting at offset start. That file is intended to be the input to
// the external disassembler.
func writeInst(generate func(func([]byte))) (file string, f *os.File, size int, err error) {
f, err = ioutil.TempFile("", "armasm")
f, err = os.CreateTemp("", "armasm")
if err != nil {
return
}
Expand Down Expand Up @@ -568,7 +567,7 @@ func hexCases(t *testing.T, encoded string) func(func([]byte)) {
// It only uses the inputs; it ignores the answers recorded in that file.
func testdataCases(t *testing.T) func(func([]byte)) {
var codes [][]byte
data, err := ioutil.ReadFile("testdata/decode.txt")
data, err := os.ReadFile("testdata/decode.txt")
if err != nil {
t.Fatal(err)
}
Expand Down
3 changes: 1 addition & 2 deletions arm/armspec/specmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
"regexp"
Expand All @@ -33,7 +32,7 @@ type Inst struct {
}

func main() {
data, err := ioutil.ReadFile("spec.json")
data, err := os.ReadFile("spec.json")
if err != nil {
log.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions arm64/arm64asm/decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ package arm64asm

import (
"encoding/hex"
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"
)

func testDecode(t *testing.T, syntax string) {
input := filepath.Join("testdata", syntax+"cases.txt")
data, err := ioutil.ReadFile(input)
data, err := os.ReadFile(input)
if err != nil {
t.Fatal(err)
}
Expand Down
7 changes: 3 additions & 4 deletions arm64/arm64asm/ext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"math/rand"
"os"
Expand Down Expand Up @@ -214,7 +213,7 @@ const start = 0x8000
// starting at offset start. That file is intended to be the input to
// the external disassembler.
func writeInst(generate func(func([]byte))) (file string, f *os.File, size int, err error) {
f, err = ioutil.TempFile("", "arm64asm")
f, err = os.CreateTemp("", "arm64asm")
if err != nil {
return
}
Expand Down Expand Up @@ -501,7 +500,7 @@ func doFuzzy(inst *InstJson, Ninst int) {
// JSONCases generates ARM64 instructions according to inst.json.
func JSONCases(t *testing.T) func(func([]byte)) {
return func(try func([]byte)) {
data, err := ioutil.ReadFile("inst.json")
data, err := os.ReadFile("inst.json")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -565,7 +564,7 @@ func hexCases(t *testing.T, encoded string) func(func([]byte)) {
func testdataCases(t *testing.T, syntax string) func(func([]byte)) {
var codes [][]byte
input := filepath.Join("testdata", syntax+"cases.txt")
data, err := ioutil.ReadFile(input)
data, err := os.ReadFile(input)
if err != nil {
t.Fatal(err)
}
Expand Down
6 changes: 3 additions & 3 deletions arm64/arm64gen/sysreggen.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"encoding/xml"
"flag"
"fmt"
"io/ioutil"
"io"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -124,7 +124,7 @@ func main() {
check(err)
defer out.Close()

files, err := ioutil.ReadDir(*xmlfolder)
files, err := os.ReadDir(*xmlfolder)
check(err)

var systemregs []SystemReg
Expand All @@ -133,7 +133,7 @@ func main() {
for _, file := range files {
xmlFile, err := os.Open(filepath.Join(*xmlfolder, file.Name()))
check(err)
value, err := ioutil.ReadAll(xmlFile)
value, err := io.ReadAll(xmlFile)
check(err)

var regpage RegisterPage
Expand Down
4 changes: 2 additions & 2 deletions loong64/loong64asm/decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ package loong64asm

import (
"encoding/hex"
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"
)

func testDecode(t *testing.T, syntax string) {
input := filepath.Join("testdata", syntax+"cases.txt")
data, err := ioutil.ReadFile(input)
data, err := os.ReadFile(input)
if err != nil {
t.Fatal(err)
}
Expand Down
5 changes: 2 additions & 3 deletions loong64/loong64asm/ext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"math/rand"
"os"
Expand Down Expand Up @@ -187,7 +186,7 @@ const start = 0x8000
// starting at offset start. That file is intended to be the input to
// the external disassembler.
func writeInst(generate func(func([]byte))) (file string, f *os.File, size int, err error) {
f, err = ioutil.TempFile("", "loong64asm")
f, err = os.CreateTemp("", "loong64asm")
if err != nil {
return
}
Expand Down Expand Up @@ -371,7 +370,7 @@ func hexCases(t *testing.T, encoded string) func(func([]byte)) {
func testdataCases(t *testing.T, syntax string) func(func([]byte)) {
var codes [][]byte
input := filepath.Join("testdata", syntax+"cases.txt")
data, err := ioutil.ReadFile(input)
data, err := os.ReadFile(input)
if err != nil {
t.Fatal(err)
}
Expand Down
6 changes: 3 additions & 3 deletions ppc64/ppc64asm/decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ package ppc64asm
import (
"encoding/binary"
"encoding/hex"
"io/ioutil"
"os"
"path"
"strings"
"testing"
)

func TestDecode(t *testing.T) {
files, err := ioutil.ReadDir("testdata")
files, err := os.ReadDir("testdata")
if err != nil {
t.Fatal(err)
}
Expand All @@ -23,7 +23,7 @@ func TestDecode(t *testing.T) {
continue
}
filename := path.Join("testdata", f.Name())
data, err := ioutil.ReadFile(filename)
data, err := os.ReadFile(filename)
if err != nil {
t.Fatal(err)
}
Expand Down
5 changes: 2 additions & 3 deletions ppc64/ppc64asm/ext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"math/rand"
"os"
Expand Down Expand Up @@ -188,7 +187,7 @@ const start = 0x8000 // start address of text
// starting at offset start. That file is intended to be the input to
// the external disassembler.
func writeInst(generate func(func([]byte))) (file string, f *os.File, size int, err error) {
f, err = ioutil.TempFile("", "ppc64asm")
f, err = os.CreateTemp("", "ppc64asm")
if err != nil {
return
}
Expand Down Expand Up @@ -494,7 +493,7 @@ func hexCases(t *testing.T, encoded string) func(func([]byte)) {
// It only uses the inputs; it ignores the answers recorded in that file.
func testdataCases(t *testing.T) func(func([]byte)) {
var codes [][]byte
data, err := ioutil.ReadFile("testdata/decode.txt")
data, err := os.ReadFile("testdata/decode.txt")
if err != nil {
t.Fatal(err)
}
Expand Down
5 changes: 2 additions & 3 deletions riscv64/riscv64asm/ext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"math/rand"
"os"
Expand Down Expand Up @@ -189,7 +188,7 @@ const start = 0x8000
// starting at offset start. That file is intended to be the input to
// the external disassembler.
func writeInst(generate func(func([]byte))) (file string, f *os.File, size int, err error) {
f, err = ioutil.TempFile("", "riscv64asm")
f, err = os.CreateTemp("", "riscv64asm")
if err != nil {
return
}
Expand Down Expand Up @@ -299,7 +298,7 @@ func hexCases(t *testing.T, encoded string) func(func([]byte)) {
func testdataCases(t *testing.T, syntax string) func(func([]byte)) {
var codes [][]byte
input := filepath.Join("testdata", syntax+"cases.txt")
data, err := ioutil.ReadFile(input)
data, err := os.ReadFile(input)
if err != nil {
t.Fatal(err)
}
Expand Down
6 changes: 3 additions & 3 deletions s390x/s390xasm/decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ package s390xasm

import (
"encoding/hex"
"io/ioutil"
"os"
"path"
"strings"
"testing"
)

func TestDecode(t *testing.T) {
files, err := ioutil.ReadDir("testdata")
files, err := os.ReadDir("testdata")
if err != nil {
t.Fatal(err)
}
Expand All @@ -22,7 +22,7 @@ func TestDecode(t *testing.T) {
continue
}
filename := path.Join("testdata", f.Name())
data, err := ioutil.ReadFile(filename)
data, err := os.ReadFile(filename)
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions x86/x86asm/decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ package x86asm

import (
"encoding/hex"
"io/ioutil"
"os"
"strconv"
"strings"
"testing"
)

func TestDecode(t *testing.T) {
data, err := ioutil.ReadFile("testdata/decode.txt")
data, err := os.ReadFile("testdata/decode.txt")
if err != nil {
t.Fatal(err)
}
Expand Down
5 changes: 2 additions & 3 deletions x86/x86asm/ext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"math/rand"
"os"
Expand Down Expand Up @@ -193,7 +192,7 @@ const start = 0x8000 // start address of text
// starting at offset start. That file is intended to be the input to
// the external disassembler.
func writeInst(generate func(func([]byte))) (file string, f *os.File, size int, err error) {
f, err = ioutil.TempFile("", "x86map")
f, err = os.CreateTemp("", "x86map")
if err != nil {
return
}
Expand Down Expand Up @@ -524,7 +523,7 @@ func hexCases(t *testing.T, encoded string) func(func([]byte)) {
// It only uses the inputs; it ignores the answers recorded in that file.
func testdataCases(t *testing.T) func(func([]byte)) {
var codes [][]byte
data, err := ioutil.ReadFile("testdata/decode.txt")
data, err := os.ReadFile("testdata/decode.txt")
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions x86/x86avxgen/avxgen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package main

import (
"bytes"
"io/ioutil"
"os"
"path/filepath"
"regexp"
"strings"
Expand Down Expand Up @@ -57,7 +57,7 @@ func TestOutput(t *testing.T) {
var testCases []testCase
{
opcodeRE := regexp.MustCompile(`as: ([A-Z][A-Z0-9]*)`)
data, err := ioutil.ReadFile(filepath.Join("testdata", "golden.txt"))
data, err := os.ReadFile(filepath.Join("testdata", "golden.txt"))
if err != nil {
t.Fatalf("read golden file: %v", err)
}
Expand Down
7 changes: 3 additions & 4 deletions x86/xeddata/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -212,7 +211,7 @@ func (db *Database) WidthSize(width string, m OperandSizeMode) string {
}

func parseWidths(r io.Reader) (map[string]*width, error) {
data, err := ioutil.ReadAll(r)
data, err := io.ReadAll(r)
if err != nil {
return nil, fmt.Errorf("parse widths: %v", err)
}
Expand Down Expand Up @@ -282,7 +281,7 @@ func parseExtraWidths(r io.Reader) (map[string]string, error) {
}

func parseStates(r io.Reader) (map[string]string, error) {
data, err := ioutil.ReadAll(r)
data, err := io.ReadAll(r)
if err != nil {
return nil, fmt.Errorf("parse states: %v", err)
}
Expand All @@ -303,7 +302,7 @@ func parseStates(r io.Reader) (map[string]string, error) {
}

func parseXtypes(r io.Reader) (map[string]*xtype, error) {
data, err := ioutil.ReadAll(r)
data, err := io.ReadAll(r)
if err != nil {
return nil, fmt.Errorf("parse xtypes: %v", err)
}
Expand Down
Loading