Skip to content

Commit

Permalink
add more detail to test suite runner
Browse files Browse the repository at this point in the history
  • Loading branch information
Herringway committed Sep 30, 2023
1 parent a3801bd commit f02b656
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions testsuite/source/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,37 @@ struct TestResult
string name;
TestState state;
string failMsg;
bool parserFailure;
bool dumperFailure;
bool composerFailure;

const void toString(OutputRange)(ref OutputRange writer)
if (isOutputRange!(OutputRange, char))
{
enum goodColour = 32;
enum badColour = 31;
enum skipColour = 93;
ubyte statusColour;
string statusString;
final switch (state) {
case TestState.success:
statusColour = 32;
statusColour = goodColour;
statusString = "Succeeded";
break;
case TestState.failure:
statusColour = 31;
statusColour = badColour;
statusString = "Failed";
break;
case TestState.skipped:
statusColour = 93;
statusColour = skipColour;
statusString = "Skipped";
break;
}
writer.formattedWrite!"[\033[%s;1m%s\033[0m] %s"(statusColour, statusString, name);
writer.formattedWrite!"[\033[%s;1m%s\033[0m]"(statusColour, statusString);
writer.formattedWrite!" [\033[%s;1mP\033[0m"(parserFailure ? badColour : goodColour);
writer.formattedWrite!"\033[%s;1mD\033[0m"(dumperFailure ? badColour : goodColour);
writer.formattedWrite!"\033[%s;1mC\033[0m] "(composerFailure ? badColour : goodColour);
put(writer, name);
if (state != TestState.success)
{
writer.formattedWrite!" (%s)"(failMsg.replace("\n", " "));
Expand Down Expand Up @@ -108,6 +118,7 @@ TestResult runTests(string yaml) @safe
catch (Exception e)
{
loadFailed = true;
output.composerFailure = true;
failMsg = e.msg;
}
}
Expand Down Expand Up @@ -159,12 +170,14 @@ TestResult runTests(string yaml) @safe
Appender!string buf;
dumper().dump(buf);
compareLineByLine(buf.data, compareYAMLString.get, false, "Dumped YAML mismatch");
output.dumperFailure = output.state == TestState.failure;
testsRun++;
}
if (!loadFailed && !events.isNull && !shouldFail)
{
const compare = dumpEventString(yamlString);
compareLineByLine(compare, events.get, true, "Event mismatch");
output.parserFailure = output.state == TestState.failure;
testsRun++;
}
if (loadFailed && !shouldFail)
Expand Down Expand Up @@ -199,9 +212,13 @@ void main(string[] args) @system

ulong total;
ulong successes;
ulong parserFails;
ulong dumperFails;
foreach (file; dirEntries(path, "*.yaml", SpanMode.shallow))
{
auto result = runTests(readText(file));
dumperFails += result.dumperFailure;
parserFails += result.parserFailure;
if (result.state == TestState.success)
{
debug(verbose) printResult(file.baseName, result);
Expand All @@ -213,7 +230,9 @@ void main(string[] args) @system
}
total++;
}
writefln!"%d/%d tests passed"(successes, total);
writefln!"Tests: %d/%d passed"(successes, total);
writefln!"Parser: %d/%d passed"(total - parserFails, total);
writefln!"Dumper: %d/%d passed"(total - dumperFails, total);
}

string cleanup(string input) @safe
Expand Down

0 comments on commit f02b656

Please sign in to comment.