mirror of
https://github.com/apple/pkl.git
synced 2026-01-11 22:30:54 +01:00
Typecheck Mapping/Listing members lazily (#628)
This changes how the language performs typechecks for mappings and listings. Currently, Pkl will shallow-force any Mapping and Listing to check it the type parameter (e.g. Listing<Person> means each element is checked to be an instance of Person). This changes the language to check each member's type when the member is accessed. This also adjust test runner to handle thrown errors from within tests. With the change to make mapping/listing typechecks lazy, we can now correctly handle thrown errors from within a single test case. This adjusts the test runner to consider any thrown errors as a failure for that specific test case.
This commit is contained in:
@@ -71,10 +71,12 @@ class TestsTest : AbstractTest() {
|
||||
val output = runTask("evalTest", expectFailure = true).output.stripFilesAndLines()
|
||||
|
||||
assertThat(output)
|
||||
.contains(
|
||||
.containsIgnoringNewLines(
|
||||
"""
|
||||
> Task :evalTest FAILED
|
||||
module test (file:///file, line x)
|
||||
test ❌
|
||||
should pass ✅
|
||||
error ❌
|
||||
Error:
|
||||
–– Pkl Error ––
|
||||
exception
|
||||
@@ -82,11 +84,7 @@ class TestsTest : AbstractTest() {
|
||||
9 | throw("exception")
|
||||
^^^^^^^^^^^^^^^^^^
|
||||
at test#facts["error"][#1] (file:///file, line x)
|
||||
|
||||
3 | facts {
|
||||
^^^^^^^
|
||||
at test#facts (file:///file, line x)
|
||||
"""
|
||||
"""
|
||||
.trimIndent()
|
||||
)
|
||||
}
|
||||
@@ -122,7 +120,6 @@ class TestsTest : AbstractTest() {
|
||||
name = "Pigeon"
|
||||
age = 41
|
||||
}
|
||||
user 1 ❌
|
||||
(file:///file, line x)
|
||||
Expected: (file:///file, line x)
|
||||
new {
|
||||
@@ -189,7 +186,7 @@ class TestsTest : AbstractTest() {
|
||||
.isEqualTo(
|
||||
"""
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<testsuite name="test" tests="6" failures="4">
|
||||
<testsuite name="test" tests="5" failures="4">
|
||||
<testcase classname="test" name="sum numbers"></testcase>
|
||||
<testcase classname="test" name="divide numbers"></testcase>
|
||||
<testcase classname="test" name="fail">
|
||||
@@ -209,8 +206,6 @@ class TestsTest : AbstractTest() {
|
||||
name = "Pigeon"
|
||||
age = 41
|
||||
}</failure>
|
||||
</testcase>
|
||||
<testcase classname="test" name="user 1">
|
||||
<failure message="Example Failure">(file:///file, line x)
|
||||
Expected: (file:///file, line x)
|
||||
new {
|
||||
@@ -226,7 +221,7 @@ class TestsTest : AbstractTest() {
|
||||
<system-err><![CDATA[8 = 8
|
||||
]]></system-err>
|
||||
</testsuite>
|
||||
|
||||
|
||||
"""
|
||||
.trimIndent()
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user