Skip to content

Generate code with specified build tag#240

Open
nicholascapo wants to merge 1 commit intomatryer:mainfrom
axioscode:add_build_tags_flag
Open

Generate code with specified build tag#240
nicholascapo wants to merge 1 commit intomatryer:mainfrom
axioscode:add_build_tags_flag

Conversation

@nicholascapo
Copy link
Copy Markdown

At $day_job we use mocks for integration testing, which means that the mock needs to be exported but we don't want them to be used in production code.

For our manually written code we add a build constraint (build tag):

//go:build !release

package example

During development we can run a normal go test ./..., but for production we build with go build --tags=release, which excludes this code.

We would like to do the same thing for our moq generated mocks:

package example 

//go:generate moq --tags !release --out moq.go . Example
type Example interface {

Signed-off-by: Nicholas Capo <nicholas@capo.tech>
Comment thread README.md
suppress mock implementation check, avoid import cycle if mocks generated outside of the tested package
-stub
return zero values when no mock implementation is provided, do not panic
-tags string
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: From what I understand, we only support specifying a single build tag. If that is correct, should we rename the command line flag?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually you could pass as many as you want (it's just a string).
I chose this name to match what the go build command has (although that is setting the tag rather than checking it).

This is valid:

moq -tags '(linux && 386) || (darwin && !cgo)' ...

and should result in:

//go:build (linux && 386) || (darwin && !cgo)

package example

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 this pull request may close these issues.

2 participants