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 importing of vendored packages #136

Merged
merged 1 commit into from
Jul 19, 2019
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
12 changes: 11 additions & 1 deletion generator/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package generator

import (
"fmt"
"go/build"
"go/types"
"log"
"path/filepath"
"reflect"
"strings"

Expand All @@ -19,11 +21,19 @@ func (f *Fake) loadPackages(c Cacher, workingDir string) error {
log.Printf("loaded %v packages from cache\n", len(f.Packages))
return nil
}
importPath := f.TargetPackage
if !filepath.IsAbs(importPath) {
bp, err := build.Import(f.TargetPackage, workingDir, build.FindOnly)
if err != nil {
return err
}
importPath = bp.ImportPath
}
p, err := packages.Load(&packages.Config{
Mode: packages.NeedName | packages.NeedFiles | packages.NeedImports | packages.NeedDeps | packages.NeedTypes,
Dir: workingDir,
Tests: true,
}, f.TargetPackage)
}, importPath)
if err != nil {
return err
}
Expand Down
6 changes: 6 additions & 0 deletions integration/roundtrip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package integration_test

import (
"fmt"
"go/build"
"io/ioutil"
"log"
"os"
Expand All @@ -22,6 +23,7 @@ func runTests(useGopath bool, t *testing.T, when spec.G, it spec.S) {
baseDir string
relativeDir string
originalGopath string
originalBuildGopath string
originalGo111module string
testDir string
copyDirFunc func()
Expand All @@ -44,11 +46,14 @@ func runTests(useGopath bool, t *testing.T, when spec.G, it spec.S) {
os.Setenv("GO111MODULE", "on")
}
originalGopath = os.Getenv("GOPATH")
originalBuildGopath = build.Default.GOPATH
var err error
testDir, err = ioutil.TempDir("", "counterfeiter-integration")
Expect(err).NotTo(HaveOccurred())
if useGopath {
os.Setenv("GOPATH", testDir)
// build.Default only reads the GOPATH env variable once on init
build.Default.GOPATH = testDir
} else {
os.Unsetenv("GOPATH")
}
Expand Down Expand Up @@ -103,6 +108,7 @@ func runTests(useGopath bool, t *testing.T, when spec.G, it spec.S) {
} else {
os.Unsetenv("GOPATH")
}
build.Default.GOPATH = originalBuildGopath
if baseDir == "" {
return
}
Expand Down