Skip to content

Conversation

@tomasaschan
Copy link
Collaborator

Since 1.12 is what we specify in go.mod, and therefore implicitly is what we promise to work with, we should ensure that we don't introduce changes which break this promise (e.g. as 1bf832c).

This assumes that bumping the Go version in go.mod is actually considered breaking, which I'm not 100% sure of (and so far my Google-fu has not been enough to help me...), but we might as well enforce this until we explicitly decide otherwise.

thaJeztah and others added 3 commits September 1, 2025 21:10
Commit 1bf832c introduced the use of
`errors.Is`, which was added in [go1.13], but the `go.mod` was not
updated to reflect this, causing compile failures on go1.12:

    docker run -it --rm -v ./:/pflag -w /pflag golang:1.12 sh -c 'go test -v ./...'
    # github.com/spf13/pflag [github.com/spf13/pflag.test]
    ./flag.go:1190:7: undefined: errors.Is
    ./flag.go:1219:7: undefined: errors.Is
    ./bool_func_test.go:86:28: cannot use stdFSet (type *flag.FlagSet) as type BoolFuncFlagSet in argument to runCase:
        *flag.FlagSet does not implement BoolFuncFlagSet (missing BoolFunc method)
    ...

As the error that is tested will not be wrapped, we can omit the `errors.Is`,
and instead continue doing a straight comparison.

[go1.13]: https://pkg.go.dev/[email protected]#Is

Signed-off-by: Sebastiaan van Stijn <[email protected]>
Commit 69bc3bd added support for Func()
and BoolFunc() to match stdlib. However, the Func method was added in
[go1.16.0], and BoolFunc in [go1.21.0], so running the tests on older
versions of Go would fail;

    docker run -it --rm -v ./:/pflag -w /pflag golang:1.21 sh -c 'go test -v ./...'
    # github.com/spf13/pflag [github.com/spf13/pflag.test]
    ./bool_func_test.go:86:28: cannot use stdFSet (type *flag.FlagSet) as type BoolFuncFlagSet in argument to runCase:
        *flag.FlagSet does not implement BoolFuncFlagSet (missing BoolFunc method)
    ./bool_func_test.go:113:21: undefined: io.Discard
    ./bool_func_test.go:116:28: cannot use stdFSet (type *flag.FlagSet) as type BoolFuncFlagSet in argument to runCase:
        *flag.FlagSet does not implement BoolFuncFlagSet (missing BoolFunc method)
    ./bool_func_test.go:139:7: undefined: errors.Is
    ./func_test.go:92:28: cannot use stdFSet (type *flag.FlagSet) as type FuncFlagSet in argument to runCase:
        *flag.FlagSet does not implement FuncFlagSet (missing Func method)
    ./func_test.go:119:21: undefined: io.Discard
    ./func_test.go:122:28: cannot use stdFSet (type *flag.FlagSet) as type FuncFlagSet in argument to runCase:
        *flag.FlagSet does not implement FuncFlagSet (missing Func method)
    ./func_test.go:145:7: undefined: errors.Is
    ./func_test.go:145:7: too many errors
    FAIL	github.com/spf13/pflag [build failed]

This patch moves the tests to a separate file that is not built for older
versions of Go.

[go1.16.0]: https://pkg.go.dev/[email protected]#Func
[go1.21.0]: https://pkg.go.dev/[email protected]#BoolFunc

Signed-off-by: Sebastiaan van Stijn <[email protected]>
Since 1.12 is what we specify in go.mod, and therefore implicitly is what
we promise to work with, we should ensure that we don't introduce changes
which break this promise (e.g. as 1bf832c).
fail-fast: false
matrix:
go: ["1.21", "1.22", "1.23"]
go: ["1.12", "1.21", "1.22", "1.23"]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could probably change this to;

  • go1.12 (oldest version advertised in go.mod)
  • go1.21 (version that we gated some tests on)
  • oldstable
  • stable

The oldstable and stable will always point to the currently supported Go versions, which can help reduce maintenance having to keep those last 2 versions up to date.

FWIW, I just started a branch to bring GolangCI a bit up to speed; looks like currently its config doesn't work with latest versions, and it only checks for nolintlint (has all other linters disabled).

I'll open a PR with that after the other ones are in.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That'd be great, thank you!

And the suggestion to test on oldstable and stable makes a lot of sense too. This PR was mostly a check to see that there isn't anything else not supported on Go 1.12 that has slipped under the radar, so I'm happy to close it for now and look forward to your follow-ups.

@tomasaschan tomasaschan closed this Sep 1, 2025
@tomasaschan tomasaschan deleted the test-on-go-1.12 branch September 1, 2025 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants