mirror of
https://github.com/apple/pkl.git
synced 2026-03-22 17:19:13 +01:00
Use ANSI colors for test results; more polish (#771)
Any thrown Pkl Errors are colored in the simple test report! Also: * Refactor `TextFormatter` to be more generic; rename to `TextFormattingStringBuilder` * Adjust test report slightly (no emojis, add more spacing). * Introduce `ColorTheme` class. * Make stack frame descriptors colored as "faint" Also: this changes the summary so it summarizes _all_ modules, rather than a summary per module. --------- Co-authored-by: Islon Scherer <islonscherer@gmail.com> Co-authored-by: Philip K.F. Hölzenspies <holzensp@gmail.com>
This commit is contained in:
@@ -20,6 +20,7 @@ import org.pkl.commons.cli.*
|
||||
import org.pkl.core.Closeables
|
||||
import org.pkl.core.EvaluatorBuilder
|
||||
import org.pkl.core.ModuleSource.uri
|
||||
import org.pkl.core.TestResults
|
||||
import org.pkl.core.stdlib.test.report.JUnitReport
|
||||
import org.pkl.core.stdlib.test.report.SimpleReport
|
||||
import org.pkl.core.util.ErrorMessages
|
||||
@@ -62,14 +63,17 @@ constructor(
|
||||
var failed = false
|
||||
var isExampleWrittenFailure = true
|
||||
val moduleNames = mutableSetOf<String>()
|
||||
val reporter = SimpleReport(useColor)
|
||||
val allTestResults = mutableListOf<TestResults>()
|
||||
for ((idx, moduleUri) in sources.withIndex()) {
|
||||
try {
|
||||
val results = evaluator.evaluateTest(uri(moduleUri), testOptions.overwrite)
|
||||
allTestResults.add(results)
|
||||
if (!failed) {
|
||||
failed = results.failed()
|
||||
isExampleWrittenFailure = results.isExampleWrittenFailure.and(isExampleWrittenFailure)
|
||||
}
|
||||
SimpleReport().report(results, consoleWriter)
|
||||
reporter.report(results, consoleWriter)
|
||||
if (sources.size > 1 && idx != sources.size - 1) {
|
||||
consoleWriter.append('\n')
|
||||
}
|
||||
@@ -102,6 +106,9 @@ constructor(
|
||||
failed = true
|
||||
}
|
||||
}
|
||||
consoleWriter.append('\n')
|
||||
reporter.summarize(allTestResults, consoleWriter)
|
||||
consoleWriter.flush()
|
||||
if (failed) {
|
||||
val exitCode = if (isExampleWrittenFailure) 10 else 1
|
||||
throw CliTestException(ErrorMessages.create("testsFailed"), exitCode)
|
||||
|
||||
@@ -37,7 +37,6 @@ import org.pkl.commons.writeString
|
||||
import org.pkl.core.Release
|
||||
|
||||
class CliTestRunnerTest {
|
||||
|
||||
@Test
|
||||
fun `CliTestRunner succeed test`(@TempDir tempDir: Path) {
|
||||
val code =
|
||||
@@ -65,8 +64,9 @@ class CliTestRunnerTest {
|
||||
"""
|
||||
module test
|
||||
facts
|
||||
✅ succeed
|
||||
✅ 100.0% tests pass [1 passed], 100.0% asserts pass [2 passed]
|
||||
✔ succeed
|
||||
|
||||
100.0% tests pass [1 passed], 100.0% asserts pass [2 passed]
|
||||
|
||||
"""
|
||||
.trimIndent()
|
||||
@@ -101,9 +101,10 @@ class CliTestRunnerTest {
|
||||
"""
|
||||
module test
|
||||
facts
|
||||
❌ fail
|
||||
✘ fail
|
||||
4 == 9 (/tempDir/test.pkl, line xx)
|
||||
❌ 0.0% tests pass [1/1 failed], 50.0% asserts pass [1/2 failed]
|
||||
|
||||
0.0% tests pass [1/1 failed], 50.0% asserts pass [1/2 failed]
|
||||
|
||||
"""
|
||||
.trimIndent()
|
||||
@@ -137,14 +138,15 @@ class CliTestRunnerTest {
|
||||
"""
|
||||
module test
|
||||
facts
|
||||
❌ fail
|
||||
✘ fail
|
||||
–– Pkl Error ––
|
||||
uh oh
|
||||
|
||||
5 | throw("uh oh")
|
||||
^^^^^^^^^^^^^^
|
||||
at test#facts["fail"][#1] (/tempDir/test.pkl, line xx)
|
||||
❌ 0.0% tests pass [1/1 failed], 0.0% asserts pass [1/1 failed]
|
||||
|
||||
0.0% tests pass [1/1 failed], 0.0% asserts pass [1/1 failed]
|
||||
|
||||
"""
|
||||
.trimIndent()
|
||||
@@ -178,14 +180,15 @@ class CliTestRunnerTest {
|
||||
"""
|
||||
module test
|
||||
examples
|
||||
❌ fail
|
||||
✘ fail
|
||||
–– Pkl Error ––
|
||||
uh oh
|
||||
|
||||
5 | throw("uh oh")
|
||||
^^^^^^^^^^^^^^
|
||||
at test#examples["fail"][#1] (/tempDir/test.pkl, line xx)
|
||||
❌ 0.0% tests pass [1/1 failed], 0.0% asserts pass [1/1 failed]
|
||||
|
||||
0.0% tests pass [1/1 failed], 0.0% asserts pass [1/1 failed]
|
||||
|
||||
"""
|
||||
.trimIndent()
|
||||
@@ -233,14 +236,15 @@ class CliTestRunnerTest {
|
||||
"""
|
||||
module test
|
||||
examples
|
||||
❌ fail
|
||||
✘ fail
|
||||
–– Pkl Error ––
|
||||
uh oh
|
||||
|
||||
5 | throw("uh oh")
|
||||
^^^^^^^^^^^^^^
|
||||
at test#examples["fail"][#1] (/tempDir/test.pkl, line xx)
|
||||
❌ 0.0% tests pass [1/1 failed], 0.0% asserts pass [1/1 failed]
|
||||
|
||||
0.0% tests pass [1/1 failed], 0.0% asserts pass [1/1 failed]
|
||||
|
||||
"""
|
||||
.trimIndent()
|
||||
@@ -435,10 +439,11 @@ class CliTestRunnerTest {
|
||||
"""
|
||||
module test
|
||||
examples
|
||||
❌ nums
|
||||
✘ nums
|
||||
(/tempDir/test.pkl, line xx)
|
||||
Output mismatch: Expected "nums" to contain 1 examples, but found 2
|
||||
❌ 0.0% tests pass [1/1 failed], 0.0% asserts pass [1/1 failed]
|
||||
|
||||
0.0% tests pass [1/1 failed], 0.0% asserts pass [1/1 failed]
|
||||
|
||||
"""
|
||||
.trimIndent()
|
||||
@@ -474,6 +479,7 @@ class CliTestRunnerTest {
|
||||
module test
|
||||
examples
|
||||
✍️ nums
|
||||
|
||||
1 examples written
|
||||
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user