Skip to content

Commit

Permalink
Remove deprecated matcher options, remove legacy mock generation
Browse files Browse the repository at this point in the history
This makes the golang.org/x/tools/go/packages based generation the default generation method and also the only one.

Because this could, in theory, be a behavioral breaking change, bumping major version.
  • Loading branch information
petergtz committed May 11, 2023
1 parent c3b20cc commit 082910c
Show file tree
Hide file tree
Showing 54 changed files with 303 additions and 2,894 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ Installing Pegomock
Pegomock consists of a binary `pegomock` and a package. Install both via:

```shell
go install github.com/petergtz/pegomock/v3/pegomock@latest
go get github.com/petergtz/pegomock/v3@latest
go install github.com/petergtz/pegomock/v4/pegomock@latest
go get github.com/petergtz/pegomock/v4@latest
```

This will download the package and install an executable `pegomock` in the directory named by the `$GOBIN` environment variable, which defaults to `$GOPATH/bin` or `$HOME/go/bin` if the `$GOPATH` environment variable is not set.
Expand All @@ -37,7 +37,7 @@ The preferred way is:

```go
import (
"github.com/petergtz/pegomock/v3"
"github.com/petergtz/pegomock/v4"
"testing"
)

Expand Down Expand Up @@ -86,7 +86,7 @@ package some_test

import (
. "github.com/onsi/ginkgo"
. "github.com/petergtz/pegomock/v3/ginkgo_compatible"
. "github.com/petergtz/pegomock/v4/ginkgo_compatible"
)

var _ = Describe("Some function", func() {
Expand Down Expand Up @@ -406,7 +406,7 @@ Installation
Install it via:

```shell
go install github.com/petergtz/pegomock/v3/pegomock@latest
go install github.com/petergtz/pegomock/v4/pegomock@latest
```

Tracking the pegomock tool in your project
Expand All @@ -425,15 +425,15 @@ Go modules allow to pin not only a package but also a tool (that is, an executab
package tools

import (
_ "github.com/petergtz/pegomock/v3/pegomock"
_ "github.com/petergtz/pegomock/v4/pegomock"
)
```
2. Set `$GOBIN` to a `bin` directory relative to your repo (this defines where tool dependencies will be installed).
2. Install the tool with `go install`:
```console
$ cd /path/to/myproject
$ export GOBIN=$PWD/bin
$ go install github.com/petergtz/pegomock/v3/pegomock
$ go install github.com/petergtz/pegomock/v4/pegomock
```
3. Use that `$GOBIN` when invoking `pegomock` for that project:
```console
Expand Down
2 changes: 1 addition & 1 deletion dsl.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"time"

"github.com/onsi/gomega/format"
"github.com/petergtz/pegomock/v3/internal/verify"
"github.com/petergtz/pegomock/v4/internal/verify"
)

var GlobalFailHandler FailHandler
Expand Down
11 changes: 5 additions & 6 deletions dsl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ import (
"testing"
"time"

. "github.com/petergtz/pegomock/v3"

"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
"github.com/petergtz/pegomock/v3"
"github.com/petergtz/pegomock/v3/test_interface"
"github.com/petergtz/pegomock/v4"
. "github.com/petergtz/pegomock/v4"
"github.com/petergtz/pegomock/v4/test_interface"
"github.com/samber/lo"
)

Expand Down Expand Up @@ -195,7 +194,7 @@ var _ = Describe("MockDisplay", func() {
})
})

Describe("https://github.com/petergtz/pegomock/v3/issues/24", func() {
Describe("https://github.com/petergtz/pegomock/v4/issues/24", func() {
Context("Stubbing with nil value", func() {
It("does not panic when return type is interface{}", func() {
When(display.InterfaceReturnValue()).ThenReturn(nil)
Expand Down Expand Up @@ -343,7 +342,7 @@ var _ = Describe("MockDisplay", func() {

Context("Never calling Flash", func() {
It("succeeds during verification when using Never() and argument matchers", func() {
// https://github.com/petergtz/pegomock/v3/issues/34
// https://github.com/petergtz/pegomock/v4/issues/34
Expect(func() { display.VerifyWasCalled(Never()).Flash(Any[string](), Any[int]()) }).NotTo(Panic())
})
})
Expand Down
32 changes: 0 additions & 32 deletions generate_test_mocks/gomock_reflect/generate_test.go

This file was deleted.

32 changes: 0 additions & 32 deletions generate_test_mocks/gomock_source/generate_test.go

This file was deleted.

10 changes: 5 additions & 5 deletions generate_test_mocks/xtools_go_loader/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"testing"

. "github.com/onsi/ginkgo/v2"
"github.com/petergtz/pegomock/v3/pegomock/filehandling"
"github.com/petergtz/pegomock/v4/pegomock/filehandling"
)

func TestMockGeneration(t *testing.T) {
Expand All @@ -28,12 +28,12 @@ func TestMockGeneration(t *testing.T) {

var _ = It("Generate mocks", func() {
filehandling.GenerateMockFile(
[]string{"github.com/petergtz/pegomock/v3/test_interface", "Display"},
[]string{"github.com/petergtz/pegomock/v4/test_interface", "Display"},
"../../mock_display_test.go", "MockDisplay", "pegomock_test",
"", false, os.Stdout, true, true, "")
"", false, os.Stdout)

filehandling.GenerateMockFile(
[]string{"github.com/petergtz/pegomock/v3/test_interface", "GenericDisplay"},
[]string{"github.com/petergtz/pegomock/v4/test_interface", "GenericDisplay"},
"../../mock_generic_display_test.go", "MockGenericDisplay", "pegomock_test",
"", false, os.Stdout, true, false, "")
"", false, os.Stdout)
})
2 changes: 0 additions & 2 deletions ginkgo_compatible/in_order_context.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
package mock

import "github.com/petergtz/pegomock/v3"

type InOrderContext = pegomock.InOrderContext
2 changes: 1 addition & 1 deletion ginkgo_compatible/matchers.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package mock

import (
"github.com/petergtz/pegomock/v3"
"github.com/petergtz/pegomock/v4"
)

var (
Expand Down
2 changes: 0 additions & 2 deletions ginkgo_compatible/matchers_generic.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package mock

import "github.com/petergtz/pegomock/v3"

func Eq[T any](value T) T { return pegomock.Eq(value) }
func NotEq[T any](value T) T { return pegomock.NotEq(value) }
func Any[T any]() T { return pegomock.Any[T]() }
Expand Down
4 changes: 0 additions & 4 deletions ginkgo_compatible/option.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
package mock

import (
"github.com/petergtz/pegomock/v3"
)

var OptionWithT = pegomock.WithT
4 changes: 0 additions & 4 deletions ginkgo_compatible/whenever.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
package mock

import (
"github.com/petergtz/pegomock/v3"
)

var Whenever = pegomock.When
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/petergtz/pegomock/v3
module github.com/petergtz/pegomock/v4

go 1.18

Expand Down
52 changes: 2 additions & 50 deletions internal/generate_matchers/matcher_generation.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

// Generate matchers:
//
// go generate github.com/petergtz/pegomock/v3/internal/generate_matchers
// go generate github.com/petergtz/pegomock/v4/internal/generate_matchers

//go:generate go run matcher_generation.go
//go:generate go fmt ../../matcher_factories.go
Expand Down Expand Up @@ -37,18 +37,6 @@ import (

for _, kind := range primitiveKinds {
contents += fmt.Sprintf(`
// Deprecated: Use Eq[T any](value T) instead.
func Eq%[1]s(value %[2]s) %[2]s {
RegisterMatcher(&EqMatcher{Value: value})
return %[4]s
}
// Deprecated: Use NotEq[T any](value T) instead.
func NotEq%[1]s(value %[2]s) %[2]s {
RegisterMatcher(&NotEqMatcher{Value: value})
return %[4]s
}
// Deprecated: Use Any[T any]() instead.
func Any%[1]s() %[2]s {
RegisterMatcher(NewAnyMatcher(reflect.TypeOf(%[3]s)))
Expand All @@ -61,18 +49,6 @@ func %[1]sThat(matcher ArgumentMatcher) %[2]s {
return %[4]s
}
// Deprecated: Use Eq[T any](value T) instead.
func Eq%[1]sSlice(value []%[2]s) []%[2]s {
RegisterMatcher(&EqMatcher{Value: value})
return nil
}
// Deprecated: Use NotEq[T any](value T) instead.
func NotEq%[1]sSlice(value []%[2]s) []%[2]s {
RegisterMatcher(&NotEqMatcher{Value: value})
return nil
}
// Deprecated: Use Any[T any]() instead.
func Any%[1]sSlice() []%[2]s {
RegisterMatcher(NewAnyMatcher(reflect.SliceOf(reflect.TypeOf(%[3]s))))
Expand All @@ -89,18 +65,6 @@ func %[1]sSliceThat(matcher ArgumentMatcher) []%[2]s {

// hard-coding this for now as interface{} overall works slightly different than other types.
return contents + `
// Deprecated: Use Eq[T any](value T) instead.
func EqInterface(value interface{}) interface{} {
RegisterMatcher(&EqMatcher{Value: value})
return nil
}
// Deprecated: Use NotEq[T any](value T) instead.
func NotEqInterface(value interface{}) interface{} {
RegisterMatcher(&NotEqMatcher{Value: value})
return nil
}
// Deprecated: Use Any[T any]() instead.
func AnyInterface() interface{} {
RegisterMatcher(NewAnyMatcher(reflect.TypeOf((*interface{})(nil)).Elem()))
Expand All @@ -113,18 +77,6 @@ func InterfaceThat(matcher ArgumentMatcher) interface{} {
return nil
}
// Deprecated: Use Eq[T any](value T) instead.
func EqInterfaceSlice(value []interface{}) []interface{} {
RegisterMatcher(&EqMatcher{Value: value})
return nil
}
// Deprecated: Use NotEq[T any](value T) instead.
func NotEqInterfaceSlice(value []interface{}) []interface{} {
RegisterMatcher(&NotEqMatcher{Value: value})
return nil
}
// Deprecated: Use Any[T any]() instead.
func AnyInterfaceSlice() []interface{} {
RegisterMatcher(NewAnyMatcher(reflect.SliceOf(reflect.TypeOf((*interface{})(nil)).Elem())))
Expand All @@ -143,7 +95,7 @@ func GenerateGinkgoMatchersFile() string {
contents := `package mock
import (
"github.com/petergtz/pegomock/v3"
"github.com/petergtz/pegomock/v4"
)
var (`
Expand Down
2 changes: 1 addition & 1 deletion matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"sync"

"github.com/petergtz/pegomock/v3/internal/verify"
"github.com/petergtz/pegomock/v4/internal/verify"
)

type EqMatcher struct {
Expand Down
Loading

0 comments on commit 082910c

Please sign in to comment.