Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
cmd/go: add 'require test' section to go.mod #26913
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
In a sense,
The module download is split into two parts: downloading the go.mod and downloading the actual code. If you have dependencies only needed for tests, then they will show up in your go.mod, and go get will download their go.mods, but it will not download their code. The test-only dependencies get downloaded only when you need it, such as the first time you run
This applies not just to test-only dependencies but also os-specific dependencies. For example if you use logrus but don't use Solaris, then the golang.org/x/sys go.mod needs to be downloaded, but not the code in that repo.
When you do split things out explicitly, then you'd have different version selection results for the different "scopes". You could potentially be using one version for a build and then get a different version for a test. That would be quite unfortunate. Having one unified go.mod avoids that potential problem.
So you're getting the fine-grained separation you want already, for free*, without having to maintain any explicit scopes, and without any possibility of inconsistency.
* The asterisk is that right now because we're still fetching git repos, even to get the go.mod, what I said isn't true. But once we have a better story for a proxy, it will become true, all with no effort. Because we do have a plan to get there, though, we're not planning to add any of these kinds of scopes as a temporary workaround. They'd just cause needless pain in the long run.
referenced this issue
Aug 10, 2018
This was referenced
Aug 12, 2018
I think it would be more clear if there were a way to know from the go tool or the go.mod which requirements are only for testing, and that doing this would not violate the problem of inconsistent scopes. It is in any event helpful to be clear about really why a requirement is there, as requirements without test fall under a different set of considerations for a module maintainer than requirements for tests. (The consumer of the former is more the end user and the later more developers). Similarly for build tags...
Note, this is not to say that I think splitting the requirements is good, as @rsc noted that causes problems. But explaining why requirements are there without mentioning scopes like testing or build tags is not ideal.
Also there is a question on go-nuts where there is some concern about vendoring overhead, but the justification from @rsc
referenced this issue
Oct 21, 2018
Having visibility into this is really important. Some of my test dependencies transitive packages are for things that I think I really really don't want in my runtime, and I would prefer my downstreams not see the pile of cruft that my use of GoConvey brings in, or at least see it with the explicit understanding that I'm not using this in the standard build.
For now this is actually driving me away from using certain 3rd party testing packages, because I consider their rather large dependency graph as pollution in my go.mod file.