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

fix: restore support and testing of Go 1.22.0 #315

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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