Fix pkl:test fact power assertions when member source section is unavailable (#1571)

Power assertions only work when the source section is available. If it
is unavailable, power assertions throw a ParserError (unexpected EOF on
an empty input) when re-parsing the expression for presentation.
This commit is contained in:
Jen Basch
2026-05-04 12:25:15 -07:00
committed by GitHub
parent 9c1a9cb4f8
commit b7ba6a8649
3 changed files with 33 additions and 1 deletions
@@ -32,6 +32,7 @@ import org.assertj.core.api.Assertions.assertThatCode
import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.Timeout
import org.junit.jupiter.api.assertDoesNotThrow
import org.junit.jupiter.api.assertThrows
import org.junit.jupiter.api.condition.EnabledOnOs
import org.junit.jupiter.api.condition.OS
@@ -695,6 +696,32 @@ class EvaluatorTest {
}
}
@Test
fun `power assertions work with test facts with unavailable source section`() {
val evaluator =
with(EvaluatorBuilder.preconfigured()) {
powerAssertionsEnabled = true
build()
}
assertDoesNotThrow {
evaluator.evaluateTest(
text(
"""
amends "pkl:test"
facts {
["foo"] {
...List(false)
}
}
"""
.trimIndent()
),
false,
)
}
}
private fun checkModule(module: PModule) {
assertThat(module.properties.size).isEqualTo(2)
assertThat(module.getProperty("name")).isEqualTo("pigeon")