Skip to content

Commit

Permalink
update readme to require modules, remove gopath tests
Browse files Browse the repository at this point in the history
- Fixes #161
  • Loading branch information
joefitzgerald committed Oct 26, 2020
1 parent 35e12c1 commit d0c725d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 38 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ If you are having problems with `counterfeiter` and are not using a supported ve

### Using `counterfeiter`

We recommend you use [`go modules`](https://blog.golang.org/using-go-modules) when working with counterfeiter.
⚠️ Please use [`go modules`](https://blog.golang.org/using-go-modules) when working with counterfeiter.

Typically, `counterfeiter` is used in `go generate` directives. It can be frustrating when you change your interface declaration and suddenly all of your generated code is suddenly out-of-date. The best practice here is to use the [`go generate` command](https://blog.golang.org/generate) to make it easier to keep your test doubles up to date.

Expand Down
2 changes: 1 addition & 1 deletion arguments/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ OPTIONS
-p
Package mode: When invoked in package mode, counterfeiter
will generate an interface and shim implementation from a
package in your GOPATH. Counterfeiter finds the public methods
package in your module. Counterfeiter finds the public methods
in the package <source-path> and adds those method signatures
to the generated interface <interface-name>.
Expand Down
7 changes: 1 addition & 6 deletions integration/roundtrip_module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,9 @@ import (
func TestIntegration(t *testing.T) {
suite := spec.New("integration", spec.Report(report.Terminal{}))
suite("round trip as module", testRoundTripAsModule)
suite("round trip with gopath", testRoundTrip)
suite.Run(t)
}

func testRoundTripAsModule(t *testing.T, when spec.G, it spec.S) {
runTests(false, t, when, it)
}

func testRoundTrip(t *testing.T, when spec.G, it spec.S) {
runTests(true, t, when, it)
runTests(t, when, it)
}
36 changes: 6 additions & 30 deletions integration/roundtrip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/maxbrunsfeld/counterfeiter/v6/generator"
)

func runTests(useGopath bool, t *testing.T, when spec.G, it spec.S) {
func runTests(t *testing.T, when spec.G, it spec.S) {
log.SetOutput(ioutil.Discard) // Comment this out to see verbose log output
log.SetFlags(log.Llongfile)
var (
Expand All @@ -32,38 +32,19 @@ func runTests(useGopath bool, t *testing.T, when spec.G, it spec.S) {
writeToTestData bool
)

name := "working with a GOPATH"
if !useGopath {
name = "working with a module"
}
name := "working with a module"

it.Before(func() {
RegisterTestingT(t)
originalGo111module = os.Getenv("GO111MODULE")
if useGopath {
os.Setenv("GO111MODULE", "off")
} else {
os.Setenv("GO111MODULE", "on")
}
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")
}

if useGopath {
baseDir = filepath.Join(testDir, "src", "github.com", "maxbrunsfeld", "counterfeiter", "v6", "fixtures")
} else {
baseDir = testDir
}

os.Unsetenv("GOPATH")
baseDir = testDir
err = os.MkdirAll(baseDir, 0777)
Expect(err).ToNot(HaveOccurred())
relativeDir = filepath.Join("..", "fixtures")
Expand Down Expand Up @@ -179,9 +160,7 @@ func runTests(useGopath bool, t *testing.T, when spec.G, it spec.S) {
if suffix != "" {
suffix = "/" + suffix
}
if !useGopath {
WriteOutput([]byte(fmt.Sprintf("module github.com/maxbrunsfeld/counterfeiter/v6/fixtures%s\n", suffix)), filepath.Join(baseDir, "go.mod"))
}
WriteOutput([]byte(fmt.Sprintf("module github.com/maxbrunsfeld/counterfeiter/v6/fixtures%s\n", suffix)), filepath.Join(baseDir, "go.mod"))
cache := &generator.FakeCache{}
f, err := generator.NewFake(generator.InterfaceOrFunction, interfaceName, fmt.Sprintf("github.com/maxbrunsfeld/counterfeiter/v6/fixtures%s", suffix), "Fake"+interfaceName, "fixturesfakes", "", baseDir, cache)
Expect(err).NotTo(HaveOccurred())
Expand Down Expand Up @@ -218,9 +197,6 @@ func runTests(useGopath bool, t *testing.T, when spec.G, it spec.S) {
t := func(interfaceName string, offset string, fakePackageName string) {
when("working with "+interfaceName, func() {
it.Before(func() {
if useGopath {
baseDir = filepath.Join(baseDir, "dup_packages")
}
relativeDir = filepath.Join(relativeDir, "dup_packages")
copyDirFunc()
})
Expand Down

0 comments on commit d0c725d

Please sign in to comment.