diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7dc1486..d52919c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 ./... diff --git a/ffcli/command_test.go b/ffcli/command_test.go index 45b1100..7656a85 100644 --- a/ffcli/command_test.go +++ b/ffcli/command_test.go @@ -6,7 +6,7 @@ import ( "errors" "flag" "fmt" - "io/ioutil" + "io" "log" "reflect" "strings" @@ -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 }{ @@ -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 }} diff --git a/fftest/tempfile.go b/fftest/tempfile.go index f7bfdf5..cfb5c0f 100644 --- a/fftest/tempfile.go +++ b/fftest/tempfile.go @@ -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 } diff --git a/fftoml/fftoml.go b/fftoml/fftoml.go index d57451d..03e628e 100644 --- a/fftoml/fftoml.go +++ b/fftoml/fftoml.go @@ -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. diff --git a/go.mod b/go.mod index 09de5a6..e0dfa50 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/parse_test.go b/parse_test.go index 8404699..9717f7b 100644 --- a/parse_test.go +++ b/parse_test.go @@ -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{}, @@ -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)}