-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: ignore 'go.mod' files in 'testdata' subdirectories when computing module boundaries #27852
Comments
This bit I don't quite understand, specifically "should be included in the same module as the test". Could you clarify? That said, with tests that do require a "full setup" (i.e. a go.mod etc) is it not just as easy to create a temporary directory and programmatically create a go.mod within it? Seems a bit easier/cleaner than offering an exemption to the rule? Or just use |
If I add a
That is a straightforward workaround, but it splits the test input across two places (the |
Change https://golang.org/cl/137815 mentions this issue: |
Note from @rsc: if we do this, we should also reject module paths that include a |
Some users may set GO111MODULE=on, and we will eventually want to be able to build x/tools itself in module mode. Updates golang/go#27858 Updates golang/go#27852 Change-Id: Iaf488b2a89e6526471530245cb580f1f0391a770 Reviewed-on: https://go-review.googlesource.com/137815 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org>
I don't know that we should introduce a special case here. We have a very simple rule at the moment. Maybe we should figure out how to work within that rule. |
The stack of changes starting at https://golang.org/cl/163209 works within that rule, but it's tedious (because we have to explicitly copy the modules in each test) and doesn't interoperate well with IDEs (because the import paths used by the files in Plus, the tests end up a lot less efficient because we have to copy the entire contents of the directory: |
I spoke too soon: it's easy enough to fall back to copying if |
If creating a |
I just realized that #30240 may require a variation on this proposal: if we want module-enabled builds from within the module cache to work with On the other hand, if we are ok with entries in the module cache only working for builds outside the module (which may be the case anyway due to file-based Both of those changes would require a migration strategy in order not to break existing |
@dmitshur That documentation isn't telling the whole story. |
I think I agree with @rsc's earlier comment. It would be better to keep the rules simple and not add a special case. Adding a special case means more logic in This may make tests for tools a little more complicated, but there are tools like golang.org/x/tools/go/packages/packagestest that should make it easier. |
Change https://golang.org/cl/196297 mentions this issue: |
…rectories When walking filesystem paths to locate packages, we normally prune out subdirectories with names beginning with ".", "_", or equal to "testdata". However, we should not prune out such a directory if it is at or above the module root, since its name is not part of the package path. Fixes #28481 Updates #27852 Change-Id: Ice82b1f908afaab50f5592f6c38ca6a0fe911edf Reviewed-on: https://go-review.googlesource.com/c/go/+/196297 Run-TryBot: Bryan C. Mills <bcmills@google.com> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Jay Conrod <jayconrod@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
I don't think we should do this. |
Some existing tests of Go tools make use of
testdata
directories containing a self-containedGOPATH
.¹For those tests to work as expected in module mode, the
testdata
directories may need to containgo.mod
files, but in order for the tests to pass when run from within other modules, thosego.mod
files should be included in the same module as the test — they should not actually define separate modules.(There's just one caveat that I know of: at the moment, adding a
go.mod
file is the easiest way to prune out files whose paths are invalid in the module zip format (see #26672).)CC: @rsc @myitcv @thepudds
¹ e.g.,
x/tools/cmd/fiximports/testdata
The text was updated successfully, but these errors were encountered: