Skip to content

Commit

Permalink
Merge branch 'main' into deps
Browse files Browse the repository at this point in the history
  • Loading branch information
nicksnyder authored Dec 3, 2023
2 parents 7c05647 + 3570aa7 commit b919e21
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 20 deletions.
4 changes: 2 additions & 2 deletions v2/goi18n/common_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package main

import "io/ioutil"
import "os"

func mustTempDir(prefix string) string {
outdir, err := ioutil.TempDir("", prefix)
outdir, err := os.MkdirTemp("", prefix)
if err != nil {
panic(err)
}
Expand Down
5 changes: 2 additions & 3 deletions v2/goi18n/extract_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"go/ast"
"go/parser"
"go/token"
"io/ioutil"
"os"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -89,7 +88,7 @@ func (ec *extractCommand) execute() error {
return nil
}

buf, err := ioutil.ReadFile(path)
buf, err := os.ReadFile(path)
if err != nil {
return err
}
Expand All @@ -113,7 +112,7 @@ func (ec *extractCommand) execute() error {
if err != nil {
return err
}
return ioutil.WriteFile(path, content, 0666)
return os.WriteFile(path, content, 0666)
}

// extractMessages extracts messages from the bytes of a Go source file.
Expand Down
12 changes: 5 additions & 7 deletions v2/goi18n/extract_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ package main

import (
"bytes"
"io/ioutil"
"os"
"path/filepath"
"testing"
)

func TestExtract(t *testing.T) {

tests := []struct {
name string
fileName string
Expand Down Expand Up @@ -258,15 +256,15 @@ zero = "Zero translation"
defer os.RemoveAll(outdir)

inpath := filepath.Join(indir, test.fileName)
if err := ioutil.WriteFile(inpath, []byte(test.file), 0666); err != nil {
if err := os.WriteFile(inpath, []byte(test.file), 0666); err != nil {
t.Fatal(err)
}

if code := testableMain([]string{"extract", "-outdir", outdir, indir}); code != 0 {
t.Fatalf("expected exit code 0; got %d\n", code)
}

files, err := ioutil.ReadDir(outdir)
files, err := os.ReadDir(outdir)
if err != nil {
t.Fatal(err)
}
Expand All @@ -280,7 +278,7 @@ zero = "Zero translation"
}

outpath := filepath.Join(outdir, actualFile.Name())
actual, err := ioutil.ReadFile(outpath)
actual, err := os.ReadFile(outpath)
if err != nil {
t.Fatal(err)
}
Expand All @@ -292,15 +290,15 @@ zero = "Zero translation"
}

func TestExtractCommand(t *testing.T) {
outdir, err := ioutil.TempDir("", "TestExtractCommand")
outdir, err := os.MkdirTemp("", "TestExtractCommand")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(outdir)
if code := testableMain([]string{"extract", "-outdir", outdir, "../example/"}); code != 0 {
t.Fatalf("expected exit code 0; got %d", code)
}
actual, err := ioutil.ReadFile(filepath.Join(outdir, "active.en.toml"))
actual, err := os.ReadFile(filepath.Join(outdir, "active.en.toml"))
if err != nil {
t.Fatal(err)
}
Expand Down
5 changes: 2 additions & 3 deletions v2/goi18n/merge_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"os"

"github.com/BurntSushi/toml"
Expand Down Expand Up @@ -83,7 +82,7 @@ func (mc *mergeCommand) execute() error {
}
inFiles := make(map[string][]byte)
for _, path := range mc.messageFiles {
content, err := ioutil.ReadFile(path)
content, err := os.ReadFile(path)
if err != nil {
return err
}
Expand All @@ -94,7 +93,7 @@ func (mc *mergeCommand) execute() error {
return err
}
for path, content := range ops.writeFiles {
if err := ioutil.WriteFile(path, content, 0666); err != nil {
if err := os.WriteFile(path, content, 0666); err != nil {
return err
}
}
Expand Down
9 changes: 4 additions & 5 deletions v2/goi18n/merge_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"bytes"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -539,14 +538,14 @@ zero = "{{.Count}} unread emails"
for name, content := range testCase.inFiles {
path := filepath.Join(indir, name)
infiles = append(infiles, path)
if err := ioutil.WriteFile(path, content, 0666); err != nil {
if err := os.WriteFile(path, content, 0666); err != nil {
t.Fatal(err)
}
}

for _, name := range testCase.deleteFiles {
path := filepath.Join(outdir, name)
if err := ioutil.WriteFile(path, []byte(`this file should get deleted`), 0666); err != nil {
if err := os.WriteFile(path, []byte(`this file should get deleted`), 0666); err != nil {
t.Fatal(err)
}
}
Expand All @@ -556,7 +555,7 @@ zero = "{{.Count}} unread emails"
t.Fatalf("expected exit code 0; got %d\n", code)
}

files, err := ioutil.ReadDir(outdir)
files, err := os.ReadDir(outdir)
if err != nil {
t.Fatal(err)
}
Expand All @@ -570,7 +569,7 @@ zero = "{{.Count}} unread emails"
continue
}
path := filepath.Join(outdir, f.Name())
actual, err := ioutil.ReadFile(path)
actual, err := os.ReadFile(path)
if err != nil {
t.Error(err)
continue
Expand Down

0 comments on commit b919e21

Please sign in to comment.