-
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.
cmd/cue: add test cases for package resolution
This adds some test cases listed in issue #1138 to make some of the package resolution semantics explicit in the tests. Signed-off-by: Roger Peppe <rogpeppe@gmail.com> Change-Id: I935e91658b84f419e040c7d9ee845944e8b542e9
- Loading branch information
Showing
5 changed files
with
204 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
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,48 @@ | ||
# 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 |
33 changes: 33 additions & 0 deletions
33
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,33 @@ | ||
# Test that a relative package path functions the same as an | ||
# absolute package path when there is 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.x"' | ||
|
||
-- 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 |
55 changes: 55 additions & 0 deletions
55
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,55 @@ | ||
# 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 |
27 changes: 27 additions & 0 deletions
27
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,27 @@ | ||
# 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 |
41 changes: 41 additions & 0 deletions
41
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,41 @@ | ||
# 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 |