Skip to content

Commit

Permalink
use replace-type config
Browse files Browse the repository at this point in the history
  • Loading branch information
DustinJSilk committed Feb 8, 2024
1 parent 4854efd commit 4b08243
Show file tree
Hide file tree
Showing 10 changed files with 405 additions and 8 deletions.
11 changes: 11 additions & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ packages:
config:
with-expecter: True
unroll-variadic: False
# Replace generic params with a new constraint and a new fixed value
ReplaceGeneric:
config:
replace-type:
- github.com/vektra/mockery/v2/pkg/fixtures.ReplaceGeneric[-TImport]=github.com/vektra/mockery/v2/pkg/fixtures/redefined_type_b.B
- github.com/vektra/mockery/v2/pkg/fixtures.ReplaceGeneric[TConstraint]=github.com/vektra/mockery/v2/pkg/fixtures/constraints.Integer
# Replace a generic param with the parent type
ReplaceGenericSelf:
config:
replace-type:
- github.com/vektra/mockery/v2/pkg/fixtures.ReplaceGenericSelf[-T]=github.com/vektra/mockery/v2/pkg/fixtures.ReplaceGenericSelf
github.com/vektra/mockery/v2/pkg/fixtures/recursive_generation:
config:
recursive: True
Expand Down
2 changes: 1 addition & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ tasks:
- "**/*.go"
cmds:
- go fmt ./...

mocks:
desc: generate new mocks from scratch
deps: [mocks.remove, mocks.generate]
Expand Down
12 changes: 12 additions & 0 deletions docs/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ func (_m *Handler) HandleMessage(m pubsub.Message) error {
}
```

Generic type constraints can also be replaced by targeting the changed parameter with the square bracket notation on the left hand side.

```shell
mockery --replace-type github.com/vektra/mockery/v2/baz/internal/foo.InternalBaz[T]=baz:github.com/vektra/mockery/v2/baz.Baz
```

If a type constraint needs to be removed and replaced with a type, target the constraint with square brackets and include a '-' in front to have it removed.

```shell
mockery --replace-type github.com/vektra/mockery/v2/baz/internal/foo.InternalBaz[-T]=baz:github.com/vektra/mockery/v2/baz.Baz
```

`packages` configuration
------------------------
:octicons-tag-24: v2.21.0
Expand Down
173 changes: 173 additions & 0 deletions mocks/github.com/vektra/mockery/v2/pkg/fixtures/ReplaceGeneric.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions mocks/github.com/vektra/mockery/v2/pkg/fixtures/Variadic.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions pkg/fixtures/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,17 @@ type GetInt interface{ Get() int }
type GetGeneric[T constraints.Integer] interface{ Get() T }

type EmbeddedGet[T constraints.Signed] interface{ GetGeneric[T] }

type ReplaceGeneric[
TImport any,
TConstraint constraints.Signed,
TKeep any,
] interface {
A(t1 TImport) TKeep
B() TImport
C() TConstraint
}

type ReplaceGenericSelf[T any] interface {
A() T
}

0 comments on commit 4b08243

Please sign in to comment.