Fix length of listings with computed index (#797)

Motivation:
The following expression evaluates to 2 instead of 1:
new Listing { "value" } { [0 + 0] = "override" }.length

Changes:
- fix length computation in EntriesLiteralNode
- improve `api/listing` tests
- make snippet test failures diffable in IntelliJ

Result:
- fixes https://github.com/apple/pkl/issues/780
- improved dev experience in IntelliJ
This commit is contained in:
translatenix
2024-11-13 10:29:37 -08:00
committed by GitHub
parent 3f91824dc2
commit 9faff5e551
4 changed files with 241 additions and 5 deletions

View File

@@ -19,6 +19,7 @@ import java.nio.file.Path
import java.util.stream.Collectors
import kotlin.io.path.*
import org.assertj.core.api.Assertions.fail
import org.opentest4j.AssertionFailedError
import org.pkl.commons.*
object FileTestUtils {
@@ -110,5 +111,11 @@ data class SnippetOutcome(val expectedOutFile: Path, val actual: String, val suc
}
private fun failWithDiff(message: String): Nothing =
throw PklAssertionFailedError(message, expected, actual)
if (System.getProperty("sun.java.command", "").contains("intellij")) {
// IntelliJ only shows diffs for AssertionFailedError
throw AssertionFailedError(message, expected, actual)
} else {
// Gradle test logging/report only shows diffs for PklAssertionFailedError
throw PklAssertionFailedError(message, expected, actual)
}
}