Improve testing with stats and errors per test section (#498)

* Emojis are moves to the left to be aligned
* A summary line is added with test counts
* Facts and Examples are grouped under their own section
This commit is contained in:
Javier Maestro
2024-10-24 07:00:35 +01:00
committed by GitHub
parent 2040f14b07
commit 86d870ba09
8 changed files with 858 additions and 393 deletions

View File

@@ -60,13 +60,16 @@ constructor(
evaluator.use {
var failed = false
val moduleNames = mutableSetOf<String>()
for (moduleUri in sources) {
for ((idx, moduleUri) in sources.withIndex()) {
try {
val results = evaluator.evaluateTest(uri(moduleUri), testOptions.overwrite)
if (!failed) {
failed = results.failed()
}
SimpleReport().report(results, consoleWriter)
if (sources.size > 1 && idx != sources.size - 1) {
consoleWriter.append('\n')
}
consoleWriter.flush()
val junitDir = testOptions.junitDir
if (junitDir != null) {

View File

@@ -63,8 +63,10 @@ class CliTestRunnerTest {
.isEqualTo(
"""
module test
succeed ✅
facts
✅ succeed
✅ 100.0% tests pass [1 passed], 100.0% asserts pass [2 passed]
"""
.trimIndent()
)
@@ -80,7 +82,7 @@ class CliTestRunnerTest {
facts {
["fail"] {
4 == 9
"foo" == "bar"
"foo" != "bar"
}
}
"""
@@ -97,10 +99,11 @@ class CliTestRunnerTest {
.isEqualTo(
"""
module test
fail ❌
4 == 9
"foo" == "bar" ❌
facts
fail
4 == 9
❌ 0.0% tests pass [1/1 failed], 50.0% asserts pass [1/2 failed]
"""
.trimIndent()
)
@@ -132,14 +135,15 @@ class CliTestRunnerTest {
.isEqualToNormalizingNewlines(
"""
module test
fail ❌
Error:
Pkl Error
uh oh
5 | throw("uh oh")
^^^^^^^^^^^^^^
at test#facts["fail"][#1]
facts
❌ fail
Pkl Error
uh oh
5 | throw("uh oh")
^^^^^^^^^^^^^^
at test#facts["fail"][#1]
❌ 0.0% tests pass [1/1 failed], 0.0% asserts pass [1/1 failed]
"""
.trimIndent()
@@ -172,14 +176,15 @@ class CliTestRunnerTest {
.isEqualTo(
"""
module test
fail ❌
Error:
Pkl Error
uh oh
5 | throw("uh oh")
^^^^^^^^^^^^^^
at test#examples["fail"][#1]
examples
❌ fail
Pkl Error
uh oh
5 | throw("uh oh")
^^^^^^^^^^^^^^
at test#examples["fail"][#1]
❌ 0.0% tests pass [1/1 failed], 0.0% asserts pass [1/1 failed]
"""
.trimIndent()
@@ -226,14 +231,15 @@ class CliTestRunnerTest {
.isEqualToNormalizingNewlines(
"""
module test
fail ❌
Error:
Pkl Error
uh oh
5 | throw("uh oh")
^^^^^^^^^^^^^^
at test#examples["fail"][#1]
examples
❌ fail
Pkl Error
uh oh
5 | throw("uh oh")
^^^^^^^^^^^^^^
at test#examples["fail"][#1]
❌ 0.0% tests pass [1/1 failed], 0.0% asserts pass [1/1 failed]
"""
.trimIndent()
@@ -252,7 +258,8 @@ class CliTestRunnerTest {
9 == trace(9)
"foo" == "foo"
}
["fail"] {
["bar"] {
"foo" == "foo"
5 == 9
}
}
@@ -270,9 +277,9 @@ class CliTestRunnerTest {
"""
<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="test" tests="2" failures="1">
<testcase classname="test" name="foo"></testcase>
<testcase classname="test" name="fail">
<failure message="Fact Failure">5 == 9</failure>
<testcase classname="test.facts" name="foo"></testcase>
<testcase classname="test.facts" name="bar">
<failure message="Fact Failure">5 == 9</failure>
</testcase>
<system-err><![CDATA[9 = 9
]]></system-err>
@@ -311,9 +318,9 @@ class CliTestRunnerTest {
.isEqualTo(
"""
<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="test" tests="2" failures="0">
<testcase classname="test" name="foo"></testcase>
<testcase classname="test" name="fail">
<testsuite name="test" tests="2" failures="1">
<testcase classname="test.facts" name="foo"></testcase>
<testcase classname="test.facts" name="fail">
<error message="uh oh"> Pkl Error
uh oh