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:
Daniel Chao
2024-11-04 14:14:19 -08:00
committed by GitHub
parent 4b4d81ba93
commit 40a08affa6
18 changed files with 688 additions and 381 deletions

View File

@@ -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)