diff --git a/mockgen/parse.go b/mockgen/parse.go index 794e749d..3060c481 100644 --- a/mockgen/parse.go +++ b/mockgen/parse.go @@ -444,13 +444,13 @@ func importsOfFile(file *ast.File) map[string]string { pkg, err := build.Import(importPath, "", 0) if err != nil { // Fallback to import path suffix. Note that this is uncertain. - log.Printf("failed to import package by path %s: %s - fallback to import path suffix", importPath, err.Error()) _, last := path.Split(importPath) // If the last path component has dots, the first dot-delimited // field is used as the name. pkgName = strings.SplitN(last, ".", 2)[0] + } else { + pkgName = pkg.Name } - pkgName = pkg.Name } if _, ok := m[pkgName]; ok { diff --git a/mockgen/tests/vendor_dep/doc.go b/mockgen/tests/vendor_dep/doc.go index 595f679b..e751826d 100644 --- a/mockgen/tests/vendor_dep/doc.go +++ b/mockgen/tests/vendor_dep/doc.go @@ -1,3 +1,4 @@ package vendor_dep //go:generate mockgen -package vendor_dep -destination mock.go github.com/golang/mock/mockgen/tests/vendor_dep VendorsDep +//go:generate mockgen -destination source_mock_package/mock.go -source=vendor_dep.go diff --git a/mockgen/tests/vendor_dep/source_mock_package/mock.go b/mockgen/tests/vendor_dep/source_mock_package/mock.go new file mode 100644 index 00000000..b4732592 --- /dev/null +++ b/mockgen/tests/vendor_dep/source_mock_package/mock.go @@ -0,0 +1,46 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: vendor_dep.go + +// Package mock_vendor_dep is a generated GoMock package. +package mock_vendor_dep + +import ( + a "a" + gomock "github.com/golang/mock/gomock" + reflect "reflect" +) + +// MockVendorsDep is a mock of VendorsDep interface +type MockVendorsDep struct { + ctrl *gomock.Controller + recorder *MockVendorsDepMockRecorder +} + +// MockVendorsDepMockRecorder is the mock recorder for MockVendorsDep +type MockVendorsDepMockRecorder struct { + mock *MockVendorsDep +} + +// NewMockVendorsDep creates a new mock instance +func NewMockVendorsDep(ctrl *gomock.Controller) *MockVendorsDep { + mock := &MockVendorsDep{ctrl: ctrl} + mock.recorder = &MockVendorsDepMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockVendorsDep) EXPECT() *MockVendorsDepMockRecorder { + return m.recorder +} + +// Foo mocks base method +func (m *MockVendorsDep) Foo() a.Ifc { + ret := m.ctrl.Call(m, "Foo") + ret0, _ := ret[0].(a.Ifc) + return ret0 +} + +// Foo indicates an expected call of Foo +func (mr *MockVendorsDepMockRecorder) Foo() *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Foo", reflect.TypeOf((*MockVendorsDep)(nil).Foo)) +}