From 4111b3eb3c794472d3d9403410c25948423b9b9e Mon Sep 17 00:00:00 2001 From: Roger Peppe Date: Wed, 12 Jun 2024 09:29:29 +0100 Subject: [PATCH] cue/load: add tests for issue 3213 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Change-Id: If101f7b6729acdc87a9ae62ebd932044fb276e51 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1196177 Reviewed-by: Daniel Martí Unity-Result: CUE porcuepine TryBot-Result: CUEcueckoo --- cue/load/loader_test.go | 40 +++++++++++++++++++++ cue/load/testdata/testmod/multi2/anon.cue | 1 + cue/load/testdata/testmod/multi2/other.cue | 7 ++++ cue/load/testdata/testmod/multi3/multi3.cue | 3 ++ cue/load/testdata/testmod/multi3/other.cue | 7 ++++ 5 files changed, 58 insertions(+) create mode 100644 cue/load/testdata/testmod/multi2/anon.cue create mode 100644 cue/load/testdata/testmod/multi2/other.cue create mode 100644 cue/load/testdata/testmod/multi3/multi3.cue create mode 100644 cue/load/testdata/testmod/multi3/other.cue diff --git a/cue/load/loader_test.go b/cue/load/loader_test.go index cc1a085f1c6..82db78bd6bb 100644 --- a/cue/load/loader_test.go +++ b/cue/load/loader_test.go @@ -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) diff --git a/cue/load/testdata/testmod/multi2/anon.cue b/cue/load/testdata/testmod/multi2/anon.cue new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/cue/load/testdata/testmod/multi2/anon.cue @@ -0,0 +1 @@ + diff --git a/cue/load/testdata/testmod/multi2/other.cue b/cue/load/testdata/testmod/multi2/other.cue new file mode 100644 index 00000000000..14c3a5c62fb --- /dev/null +++ b/cue/load/testdata/testmod/multi2/other.cue @@ -0,0 +1,7 @@ +package other + +import "mod.test/test/sub" + +// This is a non-default package for the directory. + +x: sub diff --git a/cue/load/testdata/testmod/multi3/multi3.cue b/cue/load/testdata/testmod/multi3/multi3.cue new file mode 100644 index 00000000000..2fce7fabeba --- /dev/null +++ b/cue/load/testdata/testmod/multi3/multi3.cue @@ -0,0 +1,3 @@ +package multi3 + +// This is the default package for the directory. diff --git a/cue/load/testdata/testmod/multi3/other.cue b/cue/load/testdata/testmod/multi3/other.cue new file mode 100644 index 00000000000..14c3a5c62fb --- /dev/null +++ b/cue/load/testdata/testmod/multi3/other.cue @@ -0,0 +1,7 @@ +package other + +import "mod.test/test/sub" + +// This is a non-default package for the directory. + +x: sub