General cleanup (#999)

This commit is contained in:
Nathan Baulch
2025-08-24 20:18:46 +10:00
committed by GitHub
parent 18a2148713
commit 36df8eef6e
15 changed files with 47 additions and 44 deletions
+9 -9
View File
@@ -33,7 +33,7 @@ The documentation is present in the [README][readme] and thorough the source
code. On release, it gets updated on [pkg.go.dev][pkg.go.dev]. To make a change
to the documentation, create a pull request with your proposed changes. For
simple changes like that, the easiest way to go is probably the "Fork this
project and edit the file" button on Github, displayed at the top right of the
project and edit the file" button on GitHub, displayed at the top right of the
file. Unless it's a trivial change (for example a typo), provide a little bit of
context in your pull request description or commit message.
@@ -111,7 +111,7 @@ code lowers the coverage.
Go-toml aims to stay efficient. We rely on a set of scenarios executed with Go's
builtin benchmark systems. Because of their noisy nature, containers provided by
Github Actions cannot be reliably used for benchmarking. As a result, you are
GitHub Actions cannot be reliably used for benchmarking. As a result, you are
responsible for checking that your changes do not incur a performance penalty.
You can run their following to execute benchmarks:
@@ -168,13 +168,13 @@ Checklist:
1. Decide on the next version number. Use semver. Review commits since last
version to assess.
2. Tag release. For example:
```
git checkout v2
git pull
git tag v2.2.0
git push --tags
```
3. CI automatically builds a draft Github release. Review it and edit as
```
git checkout v2
git pull
git tag v2.2.0
git push --tags
```
3. CI automatically builds a draft GitHub release. Review it and edit as
necessary. Look for "Other changes". That would indicate a pull request not
labeled properly. Tweak labels and pull request titles until changelog looks
good for users.
+2 -2
View File
@@ -3,7 +3,7 @@ package benchmark_test
import (
"compress/gzip"
"encoding/json"
"io/ioutil"
"io"
"os"
"path/filepath"
"testing"
@@ -74,7 +74,7 @@ func fixture(tb testing.TB, path string) []byte {
gz, err := gzip.NewReader(f)
assert.NoError(tb, err)
buf, err := ioutil.ReadAll(gz)
buf, err := io.ReadAll(gz)
assert.NoError(tb, err)
return buf
}
+4 -4
View File
@@ -2,7 +2,7 @@ package benchmark_test
import (
"bytes"
"io/ioutil"
"os"
"testing"
"time"
@@ -59,7 +59,7 @@ func BenchmarkUnmarshal(b *testing.B) {
})
b.Run("ReferenceFile", func(b *testing.B) {
bytes, err := ioutil.ReadFile("benchmark.toml")
bytes, err := os.ReadFile("benchmark.toml")
if err != nil {
b.Fatal(err)
}
@@ -165,7 +165,7 @@ func BenchmarkMarshal(b *testing.B) {
})
b.Run("ReferenceFile", func(b *testing.B) {
bytes, err := ioutil.ReadFile("benchmark.toml")
bytes, err := os.ReadFile("benchmark.toml")
if err != nil {
b.Fatal(err)
}
@@ -344,7 +344,7 @@ type benchmarkDoc struct {
}
func TestUnmarshalReferenceFile(t *testing.T) {
bytes, err := ioutil.ReadFile("benchmark.toml")
bytes, err := os.ReadFile("benchmark.toml")
assert.NoError(t, err)
d := benchmarkDoc{}
err = toml.Unmarshal(bytes, &d)
+2 -2
View File
@@ -1,7 +1,7 @@
package toml_test
import (
"io/ioutil"
"os"
"strings"
"testing"
@@ -10,7 +10,7 @@ import (
)
func FuzzUnmarshal(f *testing.F) {
file, err := ioutil.ReadFile("benchmark/benchmark.toml")
file, err := os.ReadFile("benchmark/benchmark.toml")
if err != nil {
panic(err)
}
+2 -3
View File
@@ -6,7 +6,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"os"
"github.com/pelletier/go-toml/v2"
@@ -72,7 +71,7 @@ func (p *Program) runAllFilesInPlace(files []string) error {
}
func (p *Program) runFileInPlace(path string) error {
in, err := ioutil.ReadFile(path)
in, err := os.ReadFile(path)
if err != nil {
return err
}
@@ -84,5 +83,5 @@ func (p *Program) runFileInPlace(path string) error {
return err
}
return ioutil.WriteFile(path, out.Bytes(), 0600)
return os.WriteFile(path, out.Bytes(), 0600)
}
+10 -11
View File
@@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"path"
"strings"
@@ -63,7 +62,7 @@ func TestProcessMainStdinDecodeErr(t *testing.T) {
}
func TestProcessMainFileExists(t *testing.T) {
tmpfile, err := ioutil.TempFile("", "example")
tmpfile, err := os.CreateTemp("", "example")
assert.NoError(t, err)
defer os.Remove(tmpfile.Name())
_, err = tmpfile.Write([]byte(`some data`))
@@ -95,16 +94,16 @@ func TestProcessMainFileDoesNotExist(t *testing.T) {
}
func TestProcessMainFilesInPlace(t *testing.T) {
dir, err := ioutil.TempDir("", "")
dir, err := os.MkdirTemp("", "")
assert.NoError(t, err)
defer os.RemoveAll(dir)
path1 := path.Join(dir, "file1")
path2 := path.Join(dir, "file2")
err = ioutil.WriteFile(path1, []byte("content 1"), 0600)
err = os.WriteFile(path1, []byte("content 1"), 0600)
assert.NoError(t, err)
err = ioutil.WriteFile(path2, []byte("content 2"), 0600)
err = os.WriteFile(path2, []byte("content 2"), 0600)
assert.NoError(t, err)
p := Program{
@@ -116,11 +115,11 @@ func TestProcessMainFilesInPlace(t *testing.T) {
assert.Equal(t, 0, exit)
v1, err := ioutil.ReadFile(path1)
v1, err := os.ReadFile(path1)
assert.NoError(t, err)
assert.Equal(t, "1", string(v1))
v2, err := ioutil.ReadFile(path2)
v2, err := os.ReadFile(path2)
assert.NoError(t, err)
assert.Equal(t, "2", string(v2))
}
@@ -137,13 +136,13 @@ func TestProcessMainFilesInPlaceErrRead(t *testing.T) {
}
func TestProcessMainFilesInPlaceFailFn(t *testing.T) {
dir, err := ioutil.TempDir("", "")
dir, err := os.MkdirTemp("", "")
assert.NoError(t, err)
defer os.RemoveAll(dir)
path1 := path.Join(dir, "file1")
err = ioutil.WriteFile(path1, []byte("content 1"), 0600)
err = os.WriteFile(path1, []byte("content 1"), 0600)
assert.NoError(t, err)
p := Program{
@@ -155,13 +154,13 @@ func TestProcessMainFilesInPlaceFailFn(t *testing.T) {
assert.Equal(t, -1, exit)
v1, err := ioutil.ReadFile(path1)
v1, err := os.ReadFile(path1)
assert.NoError(t, err)
assert.Equal(t, "content 1", string(v1))
}
func dummyFileFn(r io.Reader, w io.Writer) error {
b, err := ioutil.ReadAll(r)
b, err := io.ReadAll(r)
if err != nil {
return err
}
@@ -2283,7 +2283,7 @@ func (c *Custom) UnmarshalTOML(v interface{}) error {
return nil
}
func TestGithubIssue431(t *testing.T) {
func TestGitHubIssue431(t *testing.T) {
doc := `key = "value"`
var c Config
if err := toml.Unmarshal([]byte(doc), &c); err != nil {
@@ -2321,7 +2321,7 @@ type config437 struct {
} `toml:"HTTP"`
}
func TestGithubIssue437(t *testing.T) {
func TestGitHubIssue437(t *testing.T) {
t.Skipf("unmarshalTOML not implemented")
src := `
[HTTP]
+1 -1
View File
@@ -10,7 +10,7 @@ import (
"github.com/pelletier/go-toml/v2"
)
// Marshal is a helpfer function for calling toml.Marshal
// Marshal is a helper function for calling toml.Marshal
//
// Only needed to avoid package import loops.
func Marshal(v interface{}) ([]byte, error) {
+1 -1
View File
@@ -846,7 +846,7 @@ func parseTag(tag string) (string, tagOptions) {
}
raw := tag[idx+1:]
tag = string(tag[:idx])
tag = tag[:idx]
for raw != "" {
var o string
i := strings.Index(raw, ",")
+4 -2
View File
@@ -1326,7 +1326,8 @@ func TestIssue786(t *testing.T) {
config.Custom = []Custom{{Name: "omit", General: General{Randomize: false}}}
config.Custom = append(config.Custom, Custom{Name: "present", General: General{From: "-2d", Randomize: true}})
encoder := toml.NewEncoder(buf)
encoder.Encode(config)
err = encoder.Encode(config)
assert.NoError(t, err)
expected := `# from in graphite-web format, the local TZ is used
from = '-2d'
@@ -1372,7 +1373,8 @@ func TestMarshalIssue888(t *testing.T) {
}
encoder := toml.NewEncoder(buf).SetIndentTables(true)
encoder.Encode(config)
err := encoder.Encode(config)
assert.NoError(t, err)
expected := `# custom config
[[Custom]]
+1 -1
View File
@@ -52,7 +52,7 @@ func testgenValid(t *testing.T, input string, jsonRef string) {
assert.NoError(t, err)
var actual interface{}
err = json.Unmarshal([]byte(j), &actual)
err = json.Unmarshal(j, &actual)
assert.NoError(t, err)
testsuite.CmpJSON(t, "", ref, actual)
+6 -3
View File
@@ -2977,7 +2977,8 @@ func TestIssue931(t *testing.T) {
Name = 'd'
`)
toml.Unmarshal(b, &its)
err := toml.Unmarshal(b, &its)
assert.NoError(t, err)
assert.Equal(t, items{[]item{{"c"}, {"d"}}}, its)
}
@@ -2998,7 +2999,8 @@ func TestIssue931Interface(t *testing.T) {
Name = 'd'
`)
toml.Unmarshal(b, &its)
err := toml.Unmarshal(b, &its)
assert.NoError(t, err)
assert.Equal(t, items{[]interface{}{item{"Name": "c"}, item{"Name": "d"}}}, its)
}
@@ -3024,7 +3026,8 @@ func TestIssue931SliceInterface(t *testing.T) {
Name = 'd'
`)
toml.Unmarshal(b, &its)
err := toml.Unmarshal(b, &its)
assert.NoError(t, err)
assert.Equal(t, items{[]interface{}{item{"Name": "c"}, item{"Name": "d"}}}, its)
}
+1 -1
View File
@@ -89,7 +89,7 @@ func (n *Node) Next() *Node {
}
// Child returns a pointer to the first child node of this node. Other children
// can be accessed calling Next on the first child. Returns an nil if this Node
// can be accessed calling Next on the first child. Returns nil if this Node
// has no child.
func (n *Node) Child() *Node {
if n.child == 0 {
+1 -1
View File
@@ -1076,7 +1076,7 @@ byteLoop:
}
case c == 'T' || c == 't' || c == ':' || c == '.':
hasTime = true
case c == '+' || c == '-' || c == 'Z' || c == 'z':
case c == '+' || c == 'Z' || c == 'z':
hasTz = true
case c == ' ':
if !seenSpace && i+1 < len(b) && isDigit(b[i+1]) {