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

Attempt fixes for go 1.19 #98

Merged
merged 3 commits into from
Aug 5, 2022
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
56 changes: 28 additions & 28 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,34 @@ jobs:
test:
strategy:
matrix:
go-version: [1.16.x]
go-version: [1.x]
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- name: Install Go
uses: actions/setup-go@v1
with:
go-version: ${{ matrix.go-version }}
- name: Install staticcheck
run: go install honnef.co/go/tools/cmd/staticcheck@latest
shell: bash
- name: Install golint
run: go install golang.org/x/lint/golint@latest
shell: bash
- name: Update PATH
run: echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
shell: bash
- name: Checkout code
uses: actions/checkout@v1
- name: Fmt
if: matrix.platform != 'windows-latest' # :(
run: "diff <(gofmt -d .) <(printf '')"
shell: bash
- name: Vet
run: go vet ./...
- name: Staticcheck
run: staticcheck ./...
- name: Lint
run: golint ./...
- name: Test
run: go test -race ./...
- name: Install Go
uses: actions/setup-go@v1
with:
go-version: ${{ matrix.go-version }}
- name: Install staticcheck
run: go install honnef.co/go/tools/cmd/staticcheck@latest
shell: bash
- name: Install golint
run: go install golang.org/x/lint/golint@latest
shell: bash
- name: Update PATH
run: echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
shell: bash
- name: Checkout code
uses: actions/checkout@v1
- name: Fmt
if: matrix.platform != 'windows-latest' # :(
run: "diff <(gofmt -d .) <(printf '')"
shell: bash
- name: Vet
run: go vet ./...
- name: Staticcheck
run: staticcheck ./...
- name: Lint
run: golint ./...
- name: Test
run: go test -race ./...
8 changes: 4 additions & 4 deletions ffcli/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"errors"
"flag"
"fmt"
"io/ioutil"
"io"
"log"
"reflect"
"strings"
Expand Down Expand Up @@ -326,10 +326,10 @@ func TestIssue57(t *testing.T) {

for _, testcase := range []struct {
args []string
parseErrAs error
parseErrAs any
parseErrIs error
parseErrStr string
runErrAs error
runErrAs any
runErrIs error
runErrStr string
}{
Expand Down Expand Up @@ -374,7 +374,7 @@ func TestIssue57(t *testing.T) {
} {
t.Run(strings.Join(append([]string{"foo"}, testcase.args...), " "), func(t *testing.T) {
fs := flag.NewFlagSet("·", flag.ContinueOnError)
fs.SetOutput(ioutil.Discard)
fs.SetOutput(io.Discard)

var (
baz = &ffcli.Command{Name: "baz", FlagSet: fs, Exec: func(_ context.Context, args []string) error { return nil }}
Expand Down
30 changes: 11 additions & 19 deletions fftest/tempfile.go
Original file line number Diff line number Diff line change
@@ -1,34 +1,26 @@
package fftest

import (
"io/ioutil"
"math/rand"
"os"
"path/filepath"
"strconv"
"testing"
)

// TempFile uses ioutil.TempFile to create a temporary file with the given
// content. Use the cleanup func to remove the file.
func TempFile(t *testing.T, content string) (filename string, cleanup func()) {
// TempFile returns the filename of a temporary file that has been created with
// the provided content. The file is created in t.TempDir(), which is
// automatically removed when the test finishes.
func TempFile(t *testing.T, content string) string {
t.Helper()

f, err := ioutil.TempFile("", "fftest_")
if err != nil {
t.Fatal(err)
}

if _, err := f.Write([]byte(content)); err != nil {
t.Fatal(err)
}
filename := filepath.Join(t.TempDir(), strconv.Itoa(rand.Int()))

if err := f.Close(); err != nil {
if err := os.WriteFile(filename, []byte(content), 0600); err != nil {
t.Fatal(err)
}

cleanup = func() {
if err := os.Remove(f.Name()); err != nil {
t.Errorf("os.Remove(%q): %v", f.Name(), err)
}
}
t.Logf("created %s", filename)

return f.Name(), cleanup
return filename
}
4 changes: 2 additions & 2 deletions fftoml/fftoml.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ type Option func(*ConfigFileParser)
//
// For example, given the following TOML
//
// [section.subsection]
// value = 10
// [section.subsection]
// value = 10
//
// Parse will match to a flag with the name `-section.subsection.value` by default.
// If the delimiter is "-", Parse will match to `-section-subsection-value` instead.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/peterbourgon/ff/v3

go 1.16
go 1.18

require (
github.com/pelletier/go-toml v1.9.5
Expand Down
7 changes: 2 additions & 5 deletions parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,7 @@ func TestParseIssue16(t *testing.T) {
},
} {
t.Run(testcase.name, func(t *testing.T) {
filename, cleanup := fftest.TempFile(t, testcase.data)
defer cleanup()
filename := fftest.TempFile(t, testcase.data)

fs, vars := fftest.Pair()
vars.ParseError = ff.Parse(fs, []string{},
Expand Down Expand Up @@ -245,9 +244,7 @@ func TestParseConfigFile(t *testing.T) {
t.Run(testcase.name, func(t *testing.T) {
filename := "dummy"
if !testcase.missing {
var cleanup func()
filename, cleanup = fftest.TempFile(t, "")
defer cleanup()
filename = fftest.TempFile(t, "")
}

options := []ff.Option{ff.WithConfigFile(filename), ff.WithConfigFileParser(ff.PlainParser)}
Expand Down