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

Add exclude-regex or similar mechanism to ignore certain types #718

Closed
1 of 5 tasks
kbolino opened this issue Oct 8, 2023 · 1 comment · Fixed by #720
Closed
1 of 5 tasks

Add exclude-regex or similar mechanism to ignore certain types #718

kbolino opened this issue Oct 8, 2023 · 1 comment · Fixed by #720

Comments

@kbolino
Copy link
Contributor

kbolino commented Oct 8, 2023

Description

Currently, to define which types (not packages) to generate mocks for using the new configuration syntax, there seem to be three options: specify each type, set all: true, or set include-regex to a regular expression. However, negating a regular expression is not possible in general, and so there is no way to configure mockery to generate mocks for all types except certain ones.

In my particular case, I have a type like the following:

type Option func(*privateStructType)

I configure mockery to generate mocks in another package, and so it is impossible to have a mock for this type. However, without enumerating all of the other interface types instead, I see no way to disable mock generation for this type. What I'd like to see is something like an exclude-regex option (the inverse of include-regex), an ignore type-specific option, or some similar mechanism to prevent this type from being mocked.

A temporary solution might have been to specify a never-used build tag on that type only, but when trying that, I ran into #691 instead.

Mockery Version

% mockery --version
08 Oct 23 17:06 EDT INF couldn't read any config file version=v2.34.2
08 Oct 23 17:06 EDT INF Starting mockery dry-run=false version=v2.34.2
08 Oct 23 17:06 EDT INF Using config:  dry-run=false version=v2.34.2
v2.34.2

Golang Version

% go version
go version go1.21.2 darwin/arm64

Installation Method

  • Binary Distribution
  • Docker
  • brew
  • go install
  • Other: [specify]

Steps to Reproduce

Not a bug, but here's my mockery config for illustration (exact package name is redacted):

all: true
dir: "{{ .InterfaceDir }}/mocks"
filename: "{{ .InterfaceName }}.go"
mockname: "{{ .InterfaceName }}"
outpkg: mocks
with-expecter: true
packages:
  example.com/package:
    config:
      exclude: [mocks]
      recursive: true
@LandonTClipp
Copy link
Collaborator

I was waiting for someone to send in a request for this :D I have no concerns with it. When an interface matches both the include and exclude regex, we should exclude the interface. I think this will be very easy to do, PRs are welcome!

kbolino added a commit to kbolino/mockery that referenced this issue Oct 9, 2023
kbolino added a commit to kbolino/mockery that referenced this issue Oct 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants