Skip to content

Commit

Permalink
cue/load: add tests for issue 3213
Browse files Browse the repository at this point in the history
Issue #3213 exposed a shortcoming in the modules
logic when there is a Package field explicitly specified
in the cue/load.Config struct. This CL adds some tests
to expose existing behavior in this respect
before a subsequent CL will apply a fix.

For #3213.

Signed-off-by: Roger Peppe <[email protected]>
Change-Id: If101f7b6729acdc87a9ae62ebd932044fb276e51
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1196177
Reviewed-by: Daniel Martí <[email protected]>
Unity-Result: CUE porcuepine <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
  • Loading branch information
rogpeppe committed Jun 12, 2024
1 parent 63d1318 commit 4111b3e
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 0 deletions.
40 changes: 40 additions & 0 deletions cue/load/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,46 @@ path: ""
module: mod.test/wrong
root: ""
dir: ""
display:""`}, {
name: "ExplicitPackageWithUnqualifiedImportPath#1",
cfg: &Config{
Dir: filepath.Join(testdataDir, "multi"),
Package: "main",
},
args: []string{"."},
want: `err: found packages "main" (file.cue) and "test_package" (file_appengine.cue) in "multi"
path: ""
module: mod.test/test@v0
root: $CWD/testdata/testmod
dir: ""
display:""`}, {
name: "ExplicitPackageWithUnqualifiedImportPath#2",
// This test replicates the failure reported in https://cuelang.org/issue/3213
cfg: &Config{
Dir: filepath.Join(testdataDir, "multi2"),
Package: "other",
},
args: []string{"."},
want: `err: mod.test/test/multi2@v0:other: import failed: no dependency found for package "mod.test/test/sub":
$CWD/testdata/testmod/multi2/other.cue:3:8
path: mod.test/test/multi2@v0:other
module: mod.test/test@v0
root: $CWD/testdata/testmod
dir: $CWD/testdata/testmod/multi2
display:.
files:
$CWD/testdata/testmod/multi2/other.cue`}, {
name: "ExplicitPackageWithUnqualifiedImportPath#3",
cfg: &Config{
Dir: filepath.Join(testdataDir, "multi3"),
Package: "other",
},
args: []string{"."},
want: `err: found packages "multi3" (multi3.cue) and "other" (other.cue) in "multi3"
path: ""
module: mod.test/test@v0
root: $CWD/testdata/testmod
dir: ""
display:""`}}
tdtest.Run(t, testCases, func(t *tdtest.T, tc *loadTest) {
pkgs := Instances(tc.args, tc.cfg)
Expand Down
1 change: 1 addition & 0 deletions cue/load/testdata/testmod/multi2/anon.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

7 changes: 7 additions & 0 deletions cue/load/testdata/testmod/multi2/other.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package other

import "mod.test/test/sub"

// This is a non-default package for the directory.

x: sub
3 changes: 3 additions & 0 deletions cue/load/testdata/testmod/multi3/multi3.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package multi3

// This is the default package for the directory.
7 changes: 7 additions & 0 deletions cue/load/testdata/testmod/multi3/other.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package other

import "mod.test/test/sub"

// This is a non-default package for the directory.

x: sub

0 comments on commit 4111b3e

Please sign in to comment.