Skip to content

Commit

Permalink
fix: restore support and testing of Go 1.22.0
Browse files Browse the repository at this point in the history
- relax go directive to 1.22.0 to match the N-1 and N support statement
  and permit run/build with go1.22.0 and newer
- update the test fixtures go.mod similarly to make them representative
- use the toolchain directive to _recommend_ the latest 1.23.x (Go
  treats this as advisory)
- fix the CI build so that oldstable and stable are actually being
  tested by telling setup-go to ignore the toolchain directive
- use go build tags to add a stub for types.Alias on go1.22 and
  (somewhat ironically!) use a simple type Alias to the builtin on
  go1.23 and newer

Fixes #312

Signed-off-by: Dominic Evans <dominic.evans@uk.ibm.com>
  • Loading branch information
dnwe committed Jan 17, 2025
1 parent a8526ad commit dc6c31d
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 14 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ on:
inputs:
debug_enabled:
type: boolean
description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)'
description: "Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)"
required: false
default: false
env:
# GOOTOOLCHAIN=local tells Go to only use the installed Go version (from the
# build matrix) rather than immediately upgrading to whatever is specified by
# the `toolchain` directive in `go.mod`. This ensures that the build matrix
# versions (stable and oldstable) are actually being validated.
GOTOOLCHAIN: local
jobs:
build:
name: Build and Test
Expand Down
4 changes: 3 additions & 1 deletion fixtures/dup_packages/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module github.com/maxbrunsfeld/counterfeiter/v6/fixtures/dup_packages

go 1.22
go 1.22.0

toolchain go1.23.5
4 changes: 4 additions & 0 deletions fixtures/hyphenated_package_same_name/go.mod
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
module github.com/maxbrunsfeld/counterfeiter/v6/fixtures/hyphenated_package_same_name

go 1.22.0

toolchain go1.23.5
4 changes: 3 additions & 1 deletion fixtures/type_aliases/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module github.com/maxbrunsfeld/counterfeiter/v6/fixtures/type_aliases

go 1.22
go 1.22.0

toolchain go1.23.5
12 changes: 7 additions & 5 deletions generator/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ import (
"golang.org/x/tools/imports"
)

type namedType interface {
Obj() *types.TypeName
TypeArgs() *types.TypeList
}

func (f *Fake) loadPackages(c Cacher, workingDir string) error {
log.Println("loading packages...")
p, ok := c.Load(f.TargetPackage)
Expand Down Expand Up @@ -169,7 +174,7 @@ func (f *Fake) addImportsFor(typ types.Type) {
f.addImportsFor(t.Elem())
case *types.Chan:
f.addImportsFor(t.Elem())
case *types.Alias:
case *typesAlias: // note: using stub or alias from types_alias_go1.22.go or types_alias_go1.23.go as appropriate
f.addImportsForNamedType(t)
case *types.Named:
f.addImportsForNamedType(t)
Expand All @@ -190,10 +195,7 @@ func (f *Fake) addImportsFor(typ types.Type) {
}
}

func (f *Fake) addImportsForNamedType(t interface {
Obj() *types.TypeName
TypeArgs() *types.TypeList
}) {
func (f *Fake) addImportsForNamedType(t namedType) {
if t.Obj() != nil && t.Obj().Pkg() != nil {
typeArgs := t.TypeArgs()
for i := 0; i < typeArgs.Len(); i++ {
Expand Down
27 changes: 27 additions & 0 deletions generator/types_alias_go122.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//go:build !go1.23

package generator

import (
"go/types"
)

var _ namedType = &typesAlias{}

type typesAlias struct{}

func (a *typesAlias) Obj() *types.TypeName {
panic("counterfeiter itself must be run/built with go1.23 or newer in order to handle type aliasing")
}

func (a *typesAlias) String() string {
panic("counterfeiter itself must be run/built with go1.23 or newer in order to handle type aliasing")
}

func (a *typesAlias) TypeArgs() *types.TypeList {
panic("counterfeiter itself must be run/built with go1.23 or newer in order to handle type aliasing")
}

func (a *typesAlias) Underlying() types.Type {
panic("counterfeiter itself must be run/built with go1.23 or newer in order to handle type aliasing")
}
11 changes: 11 additions & 0 deletions generator/types_alias_go123.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//go:build go1.23

package generator

import (
"go/types"
)

var _ types.Type = &typesAlias{}

type typesAlias = types.Alias
9 changes: 5 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
module github.com/maxbrunsfeld/counterfeiter/v6

go 1.22.0

toolchain go1.23.5

require (
github.com/onsi/gomega v1.36.2
github.com/sclevine/spec v1.4.0
Expand All @@ -9,13 +13,10 @@ require (

require (
github.com/google/go-cmp v0.6.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
golang.org/x/mod v0.22.0 // indirect
golang.org/x/net v0.34.0 // indirect
golang.org/x/sync v0.10.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

go 1.23

toolchain go1.23.1
10 changes: 8 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI=
Expand All @@ -6,15 +7,20 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad h1:a6HEuzUHeKH6hwfN/ZoQgRgVIWFJljSWa/zetS2WTvg=
github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/onsi/ginkgo/v2 v2.22.1 h1:QW7tbJAUDyVDVOM5dFa7qaybo+CRfR7bemlQUN6Z8aM=
github.com/onsi/ginkgo/v2 v2.22.1/go.mod h1:S6aTpoRsSq2cZOd+pssHAlKW/Q/jZt6cPrPlnj4a1xM=
github.com/onsi/gomega v1.36.2 h1:koNYke6TVk6ZmnyHrCXba/T/MoLBXFjeC1PtvYgw0A8=
github.com/onsi/gomega v1.36.2/go.mod h1:DdwyADRjrc825LhMEkD76cHR5+pUnjhUN8GlHlRPHzY=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/sclevine/spec v1.4.0 h1:z/Q9idDcay5m5irkZ28M7PtQM4aOISzOpj4bUPkDee8=
github.com/sclevine/spec v1.4.0/go.mod h1:LvpgJaFyvQzRvc1kaDs0bulYwzC70PbiYjC4QnFHkOM=
golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4=
Expand Down

0 comments on commit dc6c31d

Please sign in to comment.