Generate code with specified build tag#240
Open
nicholascapo wants to merge 1 commit intomatryer:mainfrom
Open
Conversation
Signed-off-by: Nicholas Capo <nicholas@capo.tech>
sudo-suhas
reviewed
Feb 9, 2026
| 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 |
Collaborator
There was a problem hiding this comment.
suggestion: From what I understand, we only support specifying a single build tag. If that is correct, should we rename the command line flag?
Author
There was a problem hiding this comment.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
At
$day_jobwe 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):
During development we can run a normal
go test ./..., but for production we build withgo build --tags=release, which excludes this code.We would like to do the same thing for our
moqgenerated mocks: