Skip to content
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
6 changes: 3 additions & 3 deletions gomock/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (c *Call) DoAndReturn(f any) *Call {
return nil
}
vArgs := make([]reflect.Value, len(args))
for i := 0; i < len(args); i++ {
for i := range args {
if args[i] != nil {
vArgs[i] = reflect.ValueOf(args[i])
} else {
Expand Down Expand Up @@ -170,7 +170,7 @@ func (c *Call) Do(f any) *Call {
return nil
}
vArgs := make([]reflect.Value, len(args))
for i := 0; i < len(args); i++ {
for i := range args {
if args[i] != nil {
vArgs[i] = reflect.ValueOf(args[i])
} else {
Expand Down Expand Up @@ -437,7 +437,7 @@ func (c *Call) call() []func([]any) []any {
// mock with an embedded *Call.
func InOrder(args ...any) {
calls := make([]*Call, 0, len(args))
for i := 0; i < len(args); i++ {
for i := range args {
if call := getCall(args[i]); call != nil {
calls = append(calls, call)
continue
Expand Down
4 changes: 2 additions & 2 deletions gomock/callset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestCallSetAdd(t *testing.T) {
cs := newCallSet()

numCalls := 10
for i := 0; i < numCalls; i++ {
for range numCalls {
cs.Add(newCall(t, receiver, method, reflect.TypeOf(receiverType{}.Func)))
}

Expand Down Expand Up @@ -68,7 +68,7 @@ func TestCallSetRemove(t *testing.T) {
ourCalls := []*Call{}

numCalls := 10
for i := 0; i < numCalls; i++ {
for i := range numCalls {
// NOTE: abuse the `numCalls` value to convey initial ordering of mocked calls
generatedCall := &Call{receiver: receiver, method: method, numCalls: i}
cs.Add(generatedCall)
Expand Down
6 changes: 3 additions & 3 deletions gomock/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ func TestAnyTimes(t *testing.T) {
subject := new(Subject)

ctrl.RecordCall(subject, "FooMethod", "argument").AnyTimes()
for i := 0; i < 100; i++ {
for range 100 {
ctrl.Call(subject, "FooMethod", "argument")
}
reporter.assertPass("After 100 method calls.")
Expand All @@ -419,7 +419,7 @@ func TestMinTimes1(t *testing.T) {
_, ctrl = createFixtures(t)
subject = new(Subject)
ctrl.RecordCall(subject, "FooMethod", "argument").MinTimes(1)
for i := 0; i < 100; i++ {
for range 100 {
ctrl.Call(subject, "FooMethod", "argument")
}
ctrl.Finish()
Expand Down Expand Up @@ -492,7 +492,7 @@ func TestMinMaxTimes(t *testing.T) {
_, ctrl = createFixtures(t)
subject = new(Subject)
ctrl.RecordCall(subject, "FooMethod", "argument").MaxTimes(1).MinTimes(2)
for i := 0; i < 100; i++ {
for range 100 {
ctrl.Call(subject, "FooMethod", "argument")
}
ctrl.Finish()
Expand Down
2 changes: 1 addition & 1 deletion mockgen/internal/tests/build_constraint/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package empty_interface

//go:generate mockgen -package empty_interface -destination mock.go -source input.go "-build_constraint=(linux && 386) || (darwin && !cgo) || usertag"

type Empty interface{}
type Empty any
2 changes: 1 addition & 1 deletion mockgen/internal/tests/copyright_file/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package empty_interface

//go:generate mockgen -package empty_interface -destination mock.go -source input.go -copyright_file=mock_copyright_header

type Empty interface{} // migrating interface{} -> any does not resolve to an interface type dropping test generation added in b391ab3
type Empty any // migrating interface{} -> any does not resolve to an interface type dropping test generation added in b391ab3
2 changes: 1 addition & 1 deletion mockgen/internal/tests/empty_interface/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package empty_interface

//go:generate mockgen -package empty_interface -destination mock.go -source input.go

type Empty interface{} // migrating interface{} -> any does not resolve to an interface type.
type Empty any // migrating interface{} -> any does not resolve to an interface type.
Copy link

Choose a reason for hiding this comment

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

this comment (and one above) doesn't seme to hold anymore? But also I don't understand what this means?

2 changes: 1 addition & 1 deletion mockgen/internal/tests/package_comment/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package empty_interface

//go:generate mockgen -package empty_interface -destination mock.go -source input.go -write_package_comment=false

type Empty interface{}
type Empty any
4 changes: 2 additions & 2 deletions mockgen/mockgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -937,8 +937,8 @@ func parsePackageImport(srcDir string) (string, error) {
goPathList := strings.Split(goPaths, string(os.PathListSeparator))
for _, goPath := range goPathList {
sourceRoot := filepath.Join(goPath, "src") + string(os.PathSeparator)
if strings.HasPrefix(srcDir, sourceRoot) {
return filepath.ToSlash(strings.TrimPrefix(srcDir, sourceRoot)), nil
if after, ok := strings.CutPrefix(srcDir, sourceRoot); ok {
return filepath.ToSlash(after), nil
}
}
return "", errOutsideGoPath
Expand Down
5 changes: 2 additions & 3 deletions mockgen/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"go/token"
"go/types"
"log"
"maps"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -300,9 +301,7 @@ func (p *fileParser) parsePackage(path string) (*fileParser, error) {
newP.importedInterfaces.Set(path, ni.name.Name, ni)
}
imports, _ := importsOfFile(file)
for pkgName, pkgI := range imports {
newP.imports[pkgName] = pkgI
}
maps.Copy(newP.imports, imports)
}
return newP, nil
}
Expand Down
Loading