mirror of
https://github.com/apple/pkl.git
synced 2026-06-09 07:12:45 +02:00
Implement power assertions (#1384)
This adds power assertions to Pkl! This implements the SPICE described in https://github.com/apple/pkl-evolution/pull/29 This follows the power assertions style of reporting also found in Groovy, Kotlin, and others. * Literal values are not emitted in the diagram * Stdlib constructors of literals like `List(1, 2)` are also considered literals Power assertions are added to: * Failing type constraints * Failing test facts Power assertions are implemented as a truffle instrument to observe execution. When an assertion fails, the instrument is created and the assertion is run again to observe facts. This incurs runtime overhead to collect facts, but has no impact on code in the non-error case. --------- Co-authored-by: Islon Scherer <islonscherer@gmail.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -123,7 +123,11 @@ class TestsTest : AbstractTest() {
|
||||
✔ divide numbers
|
||||
✘ fail
|
||||
4 == 9 (file:///file, line x)
|
||||
│
|
||||
false
|
||||
"foo" == "bar" (file:///file, line x)
|
||||
│
|
||||
false
|
||||
examples
|
||||
✔ user 0
|
||||
✘ user 1
|
||||
@@ -233,14 +237,19 @@ class TestsTest : AbstractTest() {
|
||||
|
||||
assertThat(report)
|
||||
.isEqualTo(
|
||||
// language=xml
|
||||
"""
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<testsuite name="test" tests="5" failures="2">
|
||||
<testcase classname="test.facts" name="sum numbers"></testcase>
|
||||
<testcase classname="test.facts" name="divide numbers"></testcase>
|
||||
<testcase classname="test.facts" name="fail">
|
||||
<failure message="Fact Failure">4 == 9 (file:///file, line x)</failure>
|
||||
<failure message="Fact Failure">"foo" == "bar" (file:///file, line x)</failure>
|
||||
<failure message="Fact Failure">4 == 9 (file:///file, line x)
|
||||
│
|
||||
false</failure>
|
||||
<failure message="Fact Failure">"foo" == "bar" (file:///file, line x)
|
||||
│
|
||||
false</failure>
|
||||
</testcase>
|
||||
<testcase classname="test.examples" name="user 0"></testcase>
|
||||
<testcase classname="test.examples" name="user 1">
|
||||
@@ -259,7 +268,7 @@ class TestsTest : AbstractTest() {
|
||||
<system-err><![CDATA[8 = 8
|
||||
]]></system-err>
|
||||
</testsuite>
|
||||
|
||||
|
||||
"""
|
||||
.trimIndent()
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user