-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/cue: add more test cases for package resolution
This adds some test cases listed in https://cuelang.org/issue/1138 to make their package resolution semantics explicit in the tests. For #3155. Signed-off-by: Roger Peppe <rogpeppe@gmail.com> Change-Id: I935e91658b84f419e040c7d9ee845944e8b542e9 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1195196 Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com> TryBot-Result: CUEcueckoo <cueckoo@cuelang.org> Reviewed-by: Chief Cueckoo <chief.cueckoo@gmail.com>
- Loading branch information
Showing
6 changed files
with
224 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
cmd/cue/cmd/testdata/script/pkg_resolution_multiple_packages_build_attr.txtar
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,33 @@ | ||
# Test that a wildcard pattern respects build attributes when determining | ||
# what packages it resolves to. | ||
|
||
exec cue eval ./... | ||
cmp stdout stdout.golden | ||
|
||
! exec cue eval -t something ./... | ||
stderr '^found packages "x" \(x.cue\) and "y" \(y.cue\) in ".*x"$' | ||
|
||
-- stdout.golden -- | ||
x: 5 | ||
// --- | ||
x: 5 | ||
-- cue.mod/module.cue -- | ||
module: "mod.com" | ||
language: version: "v0.9.0" | ||
-- root.cue -- | ||
package root | ||
|
||
import "mod.com/x" | ||
|
||
x | ||
-- x/x.cue -- | ||
package x | ||
|
||
x: 5 | ||
-- x/y.cue -- | ||
|
||
@if(something) | ||
|
||
package y | ||
|
||
y: 5 |
44 changes: 44 additions & 0 deletions
44
cmd/cue/cmd/testdata/script/pkg_resolution_multiple_packages_no_matching_path_element.txtar
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,44 @@ | ||
# Test that a relative package path functions the same as an absolute package path | ||
# when there are no packages in the directory with names that match | ||
# the final element of the import path. | ||
|
||
! exec cue eval root.cue | ||
# TODO: the error for this isn't quite right: it says: | ||
# root.cue: package is root, want x | ||
# but the evaluation should not care about the package in the root directory | ||
# because we are not trying to evaluate that package. | ||
cmp stderr import_stderr.golden | ||
! exec cue eval mod.com/x | ||
cmp stderr absolute_stderr.golden | ||
! exec cue eval ./x | ||
# TODO: it would be nice if the error output was similar for this case as the others. | ||
stderr 'found packages "y" \(y.cue\) and "z" \(z.cue\) in ".*"' | ||
|
||
-- cue.mod/module.cue -- | ||
module: "mod.com" | ||
language: version: "v0.9.0" | ||
-- root.cue -- | ||
package root | ||
|
||
import "mod.com/x" | ||
|
||
x | ||
-- x/y.cue -- | ||
package y | ||
|
||
y: 5 | ||
-- x/z.cue -- | ||
package z | ||
|
||
z: 5 | ||
-- import_stderr.golden -- | ||
import failed: build constraints exclude all CUE files in mod.com/x: | ||
root.cue: package is root, want x | ||
x/y.cue: package is y, want x | ||
x/z.cue: package is z, want x: | ||
./root.cue:3:8 | ||
-- absolute_stderr.golden -- | ||
build constraints exclude all CUE files in mod.com/x: | ||
root.cue: package is root, want x | ||
x/y.cue: package is y, want x | ||
x/z.cue: package is z, want x |
31 changes: 31 additions & 0 deletions
31
cmd/cue/cmd/testdata/script/pkg_resolution_multiple_packages_one_matching_path_element.txtar
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,31 @@ | ||
# Test that a relative package path functions the same as an absolute package path | ||
# when there are multiple packages in the directory where one has a name | ||
# that does matches the final element of the import path. | ||
|
||
exec cue eval root.cue | ||
cmp stdout stdout.golden | ||
exec cue eval mod.com/x | ||
cmp stdout stdout.golden | ||
# TODO: the following command fails unexpectedly although it should be consistent with the above. | ||
! exec cue eval ./x | ||
stderr 'found packages "x" \(x.cue\) and "y" \(y.cue\) in ".*script-pkg_resolution_multiple_packages_one_matching_path_element.*"' | ||
|
||
-- stdout.golden -- | ||
x: 5 | ||
-- cue.mod/module.cue -- | ||
module: "mod.com" | ||
language: version: "v0.9.0" | ||
-- root.cue -- | ||
package root | ||
|
||
import "mod.com/x" | ||
|
||
x | ||
-- x/x.cue -- | ||
package x | ||
|
||
x: 5 | ||
-- x/y.cue -- | ||
package y | ||
|
||
y: 5 |
52 changes: 52 additions & 0 deletions
52
cmd/cue/cmd/testdata/script/pkg_resolution_path_element_invalid_ident.txtar
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,52 @@ | ||
# Test that a package qualifier is always required to import a package where | ||
# the final element of the import path is not a valid CUE identifier. | ||
|
||
# When there's a qualifier, the import is OK. | ||
exec cue eval ./test1/root.cue | ||
cmp stdout stdout.golden | ||
exec cue eval mod.com/1x:x | ||
cmp stdout stdout.golden | ||
exec cue eval ./1x:x | ||
cmp stdout stdout.golden | ||
|
||
# Without a qualifier, it's an error because the chosen package is ambiguous | ||
# (the package clause in CUE has to declare a valid CUE identifier). | ||
! exec cue eval ./test2/root.cue | ||
# Note: the errors here could use improvement. Specifically it says: | ||
# package is x, want 1x: | ||
# but it's not possible for a package to be 1x because it's not a valid CUE identifier. | ||
cmp stderr test2-import-stderr.golden | ||
! exec cue eval mod.com/1x | ||
cmp stderr test2-abs-stderr.golden | ||
|
||
# TODO: the following succeeds inappropriately | ||
exec cue eval ./1x | ||
|
||
-- cue.mod/module.cue -- | ||
module: "mod.com" | ||
language: version: "v0.9.0" | ||
-- test1/root.cue -- | ||
package test1 | ||
|
||
import "mod.com/1x:x" | ||
|
||
x | ||
-- test2/root.cue -- | ||
package test1 | ||
|
||
import "mod.com/1x" | ||
|
||
x | ||
-- 1x/x.cue -- | ||
package x | ||
|
||
x: 5 | ||
-- stdout.golden -- | ||
x: 5 | ||
-- test2-import-stderr.golden -- | ||
import failed: build constraints exclude all CUE files in mod.com/1x: | ||
1x/x.cue: package is x, want 1x: | ||
./test2/root.cue:3:8 | ||
-- test2-abs-stderr.golden -- | ||
build constraints exclude all CUE files in mod.com/1x: | ||
1x/x.cue: package is x, want 1x |
26 changes: 26 additions & 0 deletions
26
cmd/cue/cmd/testdata/script/pkg_resolution_single_package_matching_path_element.txtar
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,26 @@ | ||
# Test that a relative package path functions the same as an absolute package path | ||
# when there is a single package in the directory with a name | ||
# that matches the final element of the import path. | ||
|
||
exec cue eval root.cue | ||
cmp stdout output.golden | ||
exec cue eval mod.com/x | ||
cmp stdout output.golden | ||
exec cue eval ./x | ||
cmp stdout output.golden | ||
|
||
-- output.golden -- | ||
x: 5 | ||
-- cue.mod/module.cue -- | ||
module: "mod.com" | ||
language: version: "v0.9.0" | ||
-- root.cue -- | ||
package root | ||
|
||
import "mod.com/x" | ||
|
||
x | ||
-- x/y.cue -- | ||
package x | ||
|
||
x: 5 |
38 changes: 38 additions & 0 deletions
38
cmd/cue/cmd/testdata/script/pkg_resolution_single_package_not_matching_path_element.txtar
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,38 @@ | ||
# Test that a relative package path functions the same as an absolute package path | ||
# when there is a single package in the directory with a name | ||
# that does not match the final element of the import path. | ||
|
||
! exec cue eval root.cue | ||
# TODO: the error for this isn't quite right: it says: | ||
# root.cue: package is root, want x | ||
# but the evaluation should not care about the package in the root directory | ||
# because we are not trying to evaluate that package. | ||
cmp stderr import_stderr.golden | ||
! exec cue eval mod.com/x | ||
cmp stderr absolute_stderr.golden | ||
# TODO: the following command succeeds unexpectedly, | ||
# although it should be consistent with the above. | ||
exec cue eval ./x | ||
|
||
-- cue.mod/module.cue -- | ||
module: "mod.com" | ||
language: version: "v0.9.0" | ||
-- root.cue -- | ||
package root | ||
|
||
import "mod.com/x" | ||
|
||
x | ||
-- x/y.cue -- | ||
package y | ||
|
||
y: 5 | ||
-- import_stderr.golden -- | ||
import failed: build constraints exclude all CUE files in mod.com/x: | ||
root.cue: package is root, want x | ||
x/y.cue: package is y, want x: | ||
./root.cue:3:8 | ||
-- absolute_stderr.golden -- | ||
build constraints exclude all CUE files in mod.com/x: | ||
root.cue: package is root, want x | ||
x/y.cue: package is y, want x |