mirror of
https://github.com/apple/pkl.git
synced 2026-05-25 16:19:20 +02:00
Improve handling of evaling dependency notation URIs (#1595)
This commit is contained in:
+1
-1
@@ -1,5 +1,5 @@
|
||||
–– Pkl Error ––
|
||||
Cannot import dependency because there is no project found.
|
||||
Cannot resolve dependency because there is no project found.
|
||||
|
||||
If you meant to import a path that starts with `@`, prefix the path with `./` (e.g. `import "./@myPath").
|
||||
If you meant to import a dependency, ensure that this file is within a directory that contains a PklProject module.
|
||||
|
||||
@@ -507,7 +507,7 @@ class EvaluatorTest {
|
||||
val evaluator = evaluatorBuilder.setProjectDependencies(project.dependencies).build()
|
||||
assertThatCode { evaluator.use { it.evaluateOutputText(uri("foobar:baz")) } }
|
||||
.hasMessageContaining(
|
||||
"Cannot import dependency because project URI `foobar:foo/PklProject` does not have a hierarchical path."
|
||||
"Cannot resolve dependency because project URI `foobar:foo/PklProject` does not have a hierarchical path."
|
||||
)
|
||||
}
|
||||
|
||||
@@ -722,6 +722,34 @@ class EvaluatorTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `eval dependency notation as a module source`(@TempDir tempDir: Path) {
|
||||
PackageServer.populateCacheDir(tempDir)
|
||||
val project = Project.load(modulePath("org/pkl/core/project/project5/PklProject"))
|
||||
val evaluator =
|
||||
with(EvaluatorBuilder.preconfigured()) {
|
||||
moduleCacheDir = tempDir
|
||||
applyFromProject(project)
|
||||
build()
|
||||
}
|
||||
val outputText = evaluator.evaluateOutputText(uri("@fruit/catalog/apple.pkl"))
|
||||
assertThat(outputText)
|
||||
.isEqualTo(
|
||||
"""
|
||||
name = "Apple"
|
||||
|
||||
"""
|
||||
.trimIndent()
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `eval dependency notation -- no project configured`() {
|
||||
val evaluator = Evaluator.preconfigured()
|
||||
assertThatCode { evaluator.evaluateOutputText(uri("@fruit/catalog/apple.pkl")) }
|
||||
.hasMessageContaining("Cannot resolve dependency because there is no project found.")
|
||||
}
|
||||
|
||||
private fun checkModule(module: PModule) {
|
||||
assertThat(module.properties.size).isEqualTo(2)
|
||||
assertThat(module.getProperty("name")).isEqualTo("pigeon")
|
||||
|
||||
Reference in New Issue
Block a user