-
Notifications
You must be signed in to change notification settings - Fork 287
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mod/modload: ignore _test.cue files in dependencies
Currently files with a `_test.cue` suffix are recognized and ignored by the `cue/load` code unless the Config.Tests field is true. However, as there is no way to set that field from the command line, no way to include a _test.cue file even when explicitly mentioned, and no framework for writing tests in CUE, this is of very limited use. However, it would be nice to provide proper test support in CUE in the future, and the current behavior at least reserves a space in which that can happen. Thus, the dependency resolution code in mod/modload should match that of cue/load, which ignores _test.cue files unless Config.Tests is true. It seems like it would also be good to align with the current behavior of _tool.cue files: they are ignored when outside the main module. Also add a comment and make the logic a bit clearer (shouldIncludePkgFile doesn't make a difference for packages in the main module because they're added as part of the initial root set, ignoring all build tags and including _test.cue and _tool.cue files. Note: This differs from Go's treatment of test files: in Go, the dependency resolution code includes enough dependencies to enable running tests in any package directly or directly imported by the non-test code, but does not include dependencies used for tests of packages used only by external test code. For CUE, at least initially, we will include only the dependencies needed by files in the main module. Fixes #3272. Signed-off-by: Roger Peppe <[email protected]> Change-Id: Ifd3bb59652ef3fa4739817f1f551a58a8b1f5996 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1197605 Reviewed-by: Paul Jolly <[email protected]> TryBot-Result: CUEcueckoo <[email protected]>
- Loading branch information
Showing
4 changed files
with
153 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
# _test.cue files should be ignored apart from for dependency analysis | ||
# purposes. Note there is no way to use test files from the command line | ||
# currently. | ||
|
||
exec cue export | ||
cmp stdout want-eval | ||
|
||
# When tidying, the d3 dependency should not appear in the dependencies | ||
# because it's only present in a _test.go file in an external | ||
# dependency. The d2 dependency _should_ be present, because even though | ||
# we don't currently support _test.go files, we still want to consider | ||
# them as part of the main module. | ||
exec cue mod tidy | ||
cmp cue.mod/module.cue want-tidy | ||
|
||
-- want-eval -- | ||
{ | ||
"x": { | ||
"self": "d1" | ||
} | ||
} | ||
-- want-tidy -- | ||
module: "test.example/main" | ||
language: { | ||
version: "v0.9.2" | ||
} | ||
deps: { | ||
"test.example/d1@v0": { | ||
v: "v0.0.1" | ||
} | ||
"test.example/d2@v0": { | ||
v: "v0.0.1" | ||
default: true | ||
} | ||
} | ||
-- cue.mod/module.cue -- | ||
module: "test.example/main" | ||
language: version: "v0.9.2" | ||
|
||
deps: "test.example/d1": v: "v0.0.1" | ||
|
||
-- main.cue -- | ||
package main | ||
|
||
import "test.example/d1" | ||
|
||
x: d1 | ||
|
||
-- main_test.cue -- | ||
package main | ||
|
||
import "test.example/d2" | ||
|
||
y: d3 | ||
|
||
-- _registry/test.example_d1_v0.0.1/cue.mod/module.cue -- | ||
module: "test.example/d1" | ||
language: version: "v0.9.2" | ||
|
||
-- _registry/test.example_d1_v0.0.1/x.cue -- | ||
|
||
package d1 | ||
|
||
self: "d1" | ||
|
||
-- _registry/test.example_d1_v0.0.1/x_test.cue -- | ||
|
||
package d1 | ||
|
||
import "test.example/d3" | ||
|
||
test: true | ||
x: d3 | ||
|
||
-- _registry/test.example_d2_v0.0.1/cue.mod/module.cue -- | ||
module: "test.example/d2" | ||
language: version: "v0.9.2" | ||
|
||
-- _registry/test.example_d2_v0.0.1/x.cue -- | ||
|
||
package d2 | ||
|
||
self: "d2" | ||
|
||
-- _registry/test.example_d3_v0.0.1/cue.mod/module.cue -- | ||
module: "test.example/d3" | ||
language: version: "v0.9.2" | ||
|
||
-- _registry/test.example_d3_v0.0.1/x.cue -- | ||
|
||
package d3 | ||
|
||
self: "d3" |
This file contains 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
This file contains 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