diff --git a/pkl-cli/src/test/kotlin/org/pkl/cli/CliTestRunnerTest.kt b/pkl-cli/src/test/kotlin/org/pkl/cli/CliTestRunnerTest.kt
index 79435e93..bac968d2 100644
--- a/pkl-cli/src/test/kotlin/org/pkl/cli/CliTestRunnerTest.kt
+++ b/pkl-cli/src/test/kotlin/org/pkl/cli/CliTestRunnerTest.kt
@@ -107,6 +107,140 @@ class CliTestRunnerTest {
assertThat(err.toString()).isEqualTo("")
}
+ @Test
+ fun `CliTestRunner with thrown error in facts`(@TempDir tempDir: Path) {
+ val code =
+ """
+ amends "pkl:test"
+
+ facts {
+ ["fail"] {
+ throw("uh oh")
+ }
+ }
+ """
+ .trimIndent()
+ val input = tempDir.resolve("test.pkl").writeString(code).toString()
+ val out = StringWriter()
+ val err = StringWriter()
+ val opts = CliBaseOptions(sourceModules = listOf(input.toUri()), settings = URI("pkl:settings"))
+ val testOpts = CliTestOptions()
+ val runner = CliTestRunner(opts, testOpts, consoleWriter = out, errWriter = err)
+ assertThatCode { runner.run() }.hasMessage("Tests failed.")
+
+ assertThat(out.toString().stripFileAndLines(tempDir))
+ .isEqualToNormalizingNewlines(
+ """
+ module test
+ fail ❌
+ Error:
+ –– Pkl Error ––
+ uh oh
+
+ 5 | throw("uh oh")
+ ^^^^^^^^^^^^^^
+ at test#facts["fail"][#1]
+
+ """
+ .trimIndent()
+ )
+ assertThat(err.toString()).isEqualTo("")
+ }
+
+ @Test
+ fun `CliTestRunner with thrown error in examples -- no expected output`(@TempDir tempDir: Path) {
+ val code =
+ """
+ amends "pkl:test"
+
+ examples {
+ ["fail"] {
+ throw("uh oh")
+ }
+ }
+ """
+ .trimIndent()
+ val input = tempDir.resolve("test.pkl").writeString(code).toString()
+ val out = StringWriter()
+ val err = StringWriter()
+ val opts = CliBaseOptions(sourceModules = listOf(input.toUri()), settings = URI("pkl:settings"))
+ val testOpts = CliTestOptions()
+ val runner = CliTestRunner(opts, testOpts, consoleWriter = out, errWriter = err)
+ assertThatCode { runner.run() }.hasMessage("Tests failed.")
+
+ assertThat(out.toString().stripFileAndLines(tempDir))
+ .isEqualTo(
+ """
+ module test
+ fail ❌
+ Error:
+ –– Pkl Error ––
+ uh oh
+
+ 5 | throw("uh oh")
+ ^^^^^^^^^^^^^^
+ at test#examples["fail"][#1]
+
+ """
+ .trimIndent()
+ )
+ assertThat(err.toString()).isEqualTo("")
+ }
+
+ @Test
+ fun `CliTestRunner with thrown error in examples -- existing expected output`(
+ @TempDir tempDir: Path
+ ) {
+ val code =
+ """
+ amends "pkl:test"
+
+ examples {
+ ["fail"] {
+ throw("uh oh")
+ }
+ }
+ """
+ .trimIndent()
+ val input = tempDir.resolve("test.pkl").writeString(code).toString()
+ tempDir
+ .resolve("test.pkl-expected.pcf")
+ .writeString(
+ """
+ examples {
+ ["fail"] {
+ "never compared to"
+ }
+ }
+ """
+ .trimIndent()
+ )
+ val out = StringWriter()
+ val err = StringWriter()
+ val opts = CliBaseOptions(sourceModules = listOf(input.toUri()), settings = URI("pkl:settings"))
+ val testOpts = CliTestOptions()
+ val runner = CliTestRunner(opts, testOpts, consoleWriter = out, errWriter = err)
+ assertThatCode { runner.run() }.hasMessage("Tests failed.")
+
+ assertThat(out.toString().stripFileAndLines(tempDir))
+ .isEqualToNormalizingNewlines(
+ """
+ module test
+ fail ❌
+ Error:
+ –– Pkl Error ––
+ uh oh
+
+ 5 | throw("uh oh")
+ ^^^^^^^^^^^^^^
+ at test#examples["fail"][#1]
+
+ """
+ .trimIndent()
+ )
+ assertThat(err.toString()).isEqualTo("")
+ }
+
@Test
fun `CliTestRunner JUnit reports`(@TempDir tempDir: Path) {
val code =
@@ -149,6 +283,54 @@ class CliTestRunnerTest {
)
}
+ @Test
+ fun `CliTestRunner JUnit reports, with thrown error`(@TempDir tempDir: Path) {
+ val code =
+ """
+ amends "pkl:test"
+
+ facts {
+ ["foo"] {
+ 9 == trace(9)
+ "foo" == "foo"
+ }
+ ["fail"] {
+ throw("uh oh")
+ }
+ }
+ """
+ .trimIndent()
+ val input = tempDir.resolve("test.pkl").writeString(code).toString()
+ val opts = CliBaseOptions(sourceModules = listOf(input.toUri()), settings = URI("pkl:settings"))
+ val testOpts = CliTestOptions(junitDir = tempDir)
+ val runner = CliTestRunner(opts, testOpts)
+ assertThatCode { runner.run() }.hasMessageContaining("failed")
+
+ val junitReport = tempDir.resolve("test.xml").readString().stripFileAndLines(tempDir)
+ assertThat(junitReport)
+ .isEqualTo(
+ """
+
+
+
+
+ –– Pkl Error ––
+ uh oh
+
+ 9 | throw("uh oh")
+ ^^^^^^^^^^^^^^
+ at test#facts["fail"][#1]
+
+
+
+
+
+ """
+ .trimIndent()
+ )
+ }
+
@Test
fun `CliTestRunner duplicated JUnit reports`(@TempDir tempDir: Path) {
val foo =
diff --git a/pkl-core/src/main/java/org/pkl/core/ast/MemberNode.java b/pkl-core/src/main/java/org/pkl/core/ast/MemberNode.java
index 548b542c..fb7c659a 100644
--- a/pkl-core/src/main/java/org/pkl/core/ast/MemberNode.java
+++ b/pkl-core/src/main/java/org/pkl/core/ast/MemberNode.java
@@ -22,7 +22,6 @@ import java.util.function.Function;
import org.pkl.core.ast.member.DefaultPropertyBodyNode;
import org.pkl.core.runtime.VmExceptionBuilder;
import org.pkl.core.runtime.VmLanguage;
-import org.pkl.core.runtime.VmUtils;
import org.pkl.core.util.Nullable;
public abstract class MemberNode extends PklRootNode {
@@ -57,19 +56,6 @@ public abstract class MemberNode extends PklRootNode {
return new VmExceptionBuilder().withSourceSection(getHeaderSection());
}
- /**
- * If true, the property value computed by this node is not the final value exposed to user code
- * but will still be amended.
- *
- *
Used to disable type check for to-be-amended properties. See {@link
- * org.pkl.core.runtime.VmUtils#SKIP_TYPECHECK_MARKER}. IDEA: might be more appropriate to only
- * skip constraints check
- */
- protected final boolean shouldRunTypeCheck(VirtualFrame frame) {
- return frame.getArguments().length != 4
- || frame.getArguments()[3] != VmUtils.SKIP_TYPECHECK_MARKER;
- }
-
public boolean isUndefined() {
return bodyNode instanceof DefaultPropertyBodyNode propBodyNode && propBodyNode.isUndefined();
}
diff --git a/pkl-core/src/main/java/org/pkl/core/ast/builder/AstBuilder.java b/pkl-core/src/main/java/org/pkl/core/ast/builder/AstBuilder.java
index 8ed49b91..a4acd001 100644
--- a/pkl-core/src/main/java/org/pkl/core/ast/builder/AstBuilder.java
+++ b/pkl-core/src/main/java/org/pkl/core/ast/builder/AstBuilder.java
@@ -442,13 +442,21 @@ public final class AstBuilder extends AbstractAstBuilder