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

unconvert: replace deprecated io/ioutil with os #65

Merged
merged 1 commit into from
Nov 27, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions unconvert.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"go/parser"
"go/token"
"go/types"
"io/ioutil"
"log"
"os"
"os/exec"
Expand Down Expand Up @@ -87,7 +86,7 @@ func apply(file string, edits editSet) {
log.Fatal(err)
}

err = ioutil.WriteFile(file, buf.Bytes(), 0)
err = os.WriteFile(file, buf.Bytes(), 0)
if err != nil {
log.Fatal(err)
}
Expand Down Expand Up @@ -143,7 +142,7 @@ func print(conversions []token.Position) {
fmt.Printf("%s:%d:%d: unnecessary conversion\n", pos.Filename, pos.Line, pos.Column)
if *flagV {
if pos.Filename != file {
buf, err := ioutil.ReadFile(pos.Filename)
buf, err := os.ReadFile(pos.Filename)
if err != nil {
log.Fatal(err)
}
Expand Down
25 changes: 6 additions & 19 deletions unconvert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package main_test

import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand All @@ -17,8 +16,7 @@ import (
)

func TestBinary(t *testing.T) {
exePath, cleanup := build(t)
defer cleanup()
exePath := build(t)

tests := []struct {
name string
Expand Down Expand Up @@ -139,7 +137,7 @@ func ParseOutput(t *testing.T, dir, output string) ([]Annotation, error) {

func ParseDir(dir string) ([]Annotation, error) {
var all []Annotation
files, err := ioutil.ReadDir(dir)
files, err := os.ReadDir(dir)
if err != nil {
return nil, err
}
Expand All @@ -159,7 +157,7 @@ func ParseDir(dir string) ([]Annotation, error) {
}

func ParseFile(file string) ([]Annotation, error) {
data, err := ioutil.ReadFile(file)
data, err := os.ReadFile(file)
if err != nil {
return nil, err
}
Expand All @@ -183,24 +181,13 @@ func ParseFile(file string) ([]Annotation, error) {
return all, nil
}

func build(t *testing.T) (exePath string, cleanup func()) {
dir, err := ioutil.TempDir("", "unconvert_test")
if err != nil {
t.Fatalf("failed to create tempdir: %v\n", err)
}
exePath = filepath.Join(dir, "test_unconvert.exe")

cleanup = func() {
err := os.RemoveAll(dir)
if err != nil {
t.Fatal(err)
}
}
func build(t *testing.T) (exePath string) {
exePath = filepath.Join(t.TempDir(), "test_unconvert.exe")

output, err := exec.Command("go", "build", "-o", exePath, ".").CombinedOutput()
if err != nil {
t.Fatalf("failed to build service program: %v\n%v", err, string(output))
}

return exePath, cleanup
return exePath
}
Loading