Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.
Merged
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
13 changes: 12 additions & 1 deletion mockgen/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import (
"strings"
)

// pkgPath is the importable path for package model
const pkgPath = "github.com/golang/mock/mockgen/model"

// Package is a Go package. It may be a subset.
type Package struct {
Name string
Expand Down Expand Up @@ -131,7 +134,15 @@ func init() {
gob.Register(&MapType{})
gob.Register(&NamedType{})
gob.Register(&PointerType{})
gob.Register(PredeclaredType(""))

// Call gob.RegisterName to make sure it has the consistent name registered
// for both gob decoder and encoder.
//
// For a non-pointer type, gob.Register will try to get package full path by
// calling rt.PkgPath() for a name to register. If your project has vendor
// directory, it is possible that PkgPath will get a path like this:
// ../../../vendor/github.com/golang/mock/mockgen/model
gob.RegisterName(pkgPath+".PredeclaredType", PredeclaredType(""))
}

// ArrayType is an array or slice type.
Expand Down
5 changes: 4 additions & 1 deletion mockgen/reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ func Reflect(importPath string, symbols []string) (*model.Package, error) {

progPath := *execOnly
if *execOnly == "" {
pwd, _ := os.Getwd()
// We use TempDir instead of TempFile so we can control the filename.
tmpDir, err := ioutil.TempDir("", "gomock_reflect_")
// Try to place the TempDir under pwd, so that if there is some package in
// vendor directory, 'go build' can also load/mock it.
tmpDir, err := ioutil.TempDir(pwd, "gomock_reflect_")
if err != nil {
return nil, err
}
Expand Down
1 change: 1 addition & 0 deletions mockgen/tests/vendor_pkg/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test for [Issue#4](https://github.com/golang/mock/issues/4).
3 changes: 3 additions & 0 deletions mockgen/tests/vendor_pkg/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package vendor_pkg

//go:generate mockgen a Ifc
10 changes: 10 additions & 0 deletions mockgen/tests/vendor_pkg/vendor/a/a.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package a

type Ifc interface {
A(string) string
B(int) int
C(chan int) chan int
D(interface{})
E(map[string]interface{})
F([]float64)
}