-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
cmd/go: 'go mod -sync' adds test dependencies of dependencies, while 'go build' does not #26626
Comments
Possibly related: #26571 "cmd/go: clarify doc that go commands like 'go build' are not always sufficient to update go.mod and 'go mod -sync' is sometimes required to handle variability due to GOOS/GOARCH/build tags" (Above issue #26571 is related in the sense that 'go mod -sync' is currently expected to do more than 'go build'). Separately, I think I have also seen reference to test dependencies getting picked up in go.mod and people saying it is expected? I think that makes sense in that you could imagine wanting to have control over your test dependencies in go.mod, but I don't personally know the intent. |
Note that these are not the test dependencies of my module, but test dependencies of its dependencies. I don't see why I would need them in my go.mod. |
If you run |
More generally: you should usually run your dependencies' tests before cutting a release. If the combination of versions that your program ends up with exposes a bug in the interaction of two or more dependencies, you want to find out about it. (The number of possible version combinations in general is exponential in the number of modules, so you cannot expect your dependencies to test against all possible combinations of their dependencies up-front.) |
Ok, then it probably works as intended. |
I think a common suggested workflow is doing 'go test ...' (or maybe 'go test all' -- not sure what the final syntax will be) to test your module (including your direct dependencies and your indirect dependencies) as a way of validating that the selected packages versions are compatible. Related snippet from https://research.swtch.com/vgo-cmd:
edit: couple minor typos |
In that case I'll close out this issue, but please reopen if you find that |
Hi @bcmills, while this is fresh, is 'go test all' considered preferable to 'go test ...'? |
No idea. I think (?) that they're equivalent, but they're implemented separately at the moment. I suspect that resolving this TODO will make them completely equivalent, but when I tried I ended up breaking tests. (Not sure if it's a bug in my change or a fundamental difference that I'm missing.) go/src/cmd/go/internal/modload/load.go Line 106 in bd98a81
|
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version devel +bd98a81 Thu Jul 26 17:13:12 2018 +0000 darwin/amd64
What did you do?
What did you expect to see?
I expected "go mod -sync" to add no more dependencies after "go build".
What did you see instead?
"go mod -sync" added dependencies of _test.go files (goconvey, gopherjs) of my dependency, which are unnecessary to build my module.
The text was updated successfully, but these errors were encountered: