trial.reporters.result 32/79(40%) line coverage

      
10
20
30
40
50
60
70
80
90
100
110
120
130
140
150
160
170
180
190
200
210
220
230
240
250
260
270
280
290
300
310
320
330
340
350
360
370
380
390
400
410
420
430
440
450
460
470
480
490
500
510
520
530
540
550
560
570
580
590
600
610
620
631
640
651
661
670
680
690
700
710
720
730
740
750
769
779
780
790
800
810
820
830
840
850
860
870
880
890
900
910
920
930
94166
950
960
97166
980
990
100166
1010
102166
1030
1040
1050
1060
1070
1080
1090
1100
1110
1120
1130
1140
1150
1160
1170
1180
1190
1200
1211
1220
1230
1240
1250
1261
1270
1281
1290
1301
1310
1321
1330
1341
1350
1360
1370
1380
1391
1400
1410
1420
1430
1441
1450
1461
1470
1480
1491
1500
1511
1520
1530
1540
1551
1560
1570
1580
1590
1600
1610
1620
1630
1640
1650
1660
1670
1680
1690
1700
1710
1720
1730
1740
1750
1760
1770
1780
1790
1800
1810
1820
1830
1840
1850
1860
1870
1880
1890
1900
1910
1920
1932
1941
1951
1961
1970
1981
1990
2000
2010
2020
2030
2041
2051
2061
2071
2081
2090
2100
2110
2120
2133
2140
2150
2160
2170
2180
2190
2200
2210
2220
2230
2240
2250
2260
2270
2280
2290
2300
2310
2320
2330
2340
2350
2360
2370
2380
2390
2400
2410
2420
2430
2440
2450
2460
2470
2480
2490
2500
2510
2520
2530
2540
2550
2560
2570
2580
2590
2600
2610
2620
2630
2640
2650
2660
2670
2680
2690
2700
2710
2720
2730
2740
2750
2760
2770
2780
2790
2800
2810
2820
module trial.reporters.result; import std.stdio; import std.array; import std.conv; import std.datetime; import trial.interfaces; import trial.reporters.writer; version(Have_fluent_asserts) { import fluentasserts.core.base; import fluentasserts.core.results; } struct TestResultGlyphs { version(Windows) { string error = "x"; } else { string error = "✖"; } } string testResultGlyphsToCode(TestResultGlyphs glyphs) { return "TestResultGlyphs(`" ~ glyphs.error ~ "`)"; } class ResultReporter : ILifecycleListener, ITestCaseLifecycleListener, ISuiteLifecycleListener, IStepLifecycleListener { private { TestResultGlyphs glyphs; int suites; int tests; int pending; int failedTests; SysTime beginTime; ReportWriter writer; Throwable[] exceptions; string[] failedTestNames; string currentSuite; } this() { writer = defaultWriter; } this(TestResultGlyphs glyphs) { writer = defaultWriter; this.glyphs = glyphs; } this(ReportWriter writer) { this.writer = writer; } void begin(ref SuiteResult suite) { suites++; currentSuite = suite.name; } void end(ref SuiteResult suite) { } void update() { } void begin(string suite, ref TestResult test) { } void end(string suite, ref TestResult test) { if(test.status == TestResult.Status.pending) { pending++; } else { tests++; } if (test.status != TestResult.Status.failure) { return; } exceptions ~= test.throwable; failedTestNames ~= currentSuite ~ " " ~ test.name; failedTests++; } void begin(string suite, string test, ref StepResult step) { } void end(string suite, string test, ref StepResult step) { } void begin(ulong) { beginTime = Clock.currTime; } void end(SuiteResult[] results) { auto diff = Clock.currTime - beginTime; writer.writeln(""); reportExceptions; writer.writeln(""); if (tests == 0) { reportNoTest; } if (tests == 1) { reportOneTestResult; } if (tests > 1) { reportTestsResult; } if(pending == 1) { reportOnePendingTest; } else if(pending > 1) { reportManyPendingTests; } writer.writeln(""); } private { void reportNoTest() { writer.write("There are no tests to run."); } void reportOnePendingTest() { writer.write("There is a pending test.\n", ReportWriter.Context.info); } void reportManyPendingTests() { writer.write("There are " ~ pending.to!string ~ " pending tests.\n", ReportWriter.Context.info); } void reportOneTestResult() { auto timeDiff = Clock.currTime - beginTime; if (failedTests > 0) { writer.write(glyphs.error ~ " The test failed in " ~ timeDiff.to!string ~ ":", ReportWriter.Context.danger); return; } writer.write("The test succeeded in ", ReportWriter.Context.active); writer.write(timeDiff.to!string, ReportWriter.Context.info); writer.write("!\n", ReportWriter.Context.active); } void reportTestsResult() { string suiteText = suites == 1 ? "1 suite" : suites.to!string ~ " suites"; auto timeDiff = Clock.currTime - beginTime; writer.write("Executed ", ReportWriter.Context.active); writer.write(tests.to!string, ReportWriter.Context.info); if(failedTests > 0) { writer.write(" (", ReportWriter.Context.active); writer.write(failedTests.to!string ~ " failed", ReportWriter.Context.danger); writer.write(")", ReportWriter.Context.active); } writer.write(" tests in ", ReportWriter.Context.active); writer.write(suiteText, ReportWriter.Context.info); writer.write(" in ", ReportWriter.Context.active); writer.write(timeDiff.to!string, ReportWriter.Context.info); writer.write(".\n", ReportWriter.Context.info); } void reportExceptions() { foreach (size_t i, t; exceptions) { writer.writeln(""); writer.writeln(i.to!string ~ ") " ~ failedTestNames[i] ~ ":", ReportWriter.Context.danger); version(Have_fluent_asserts) { TestException e = cast(TestException) t; if (e is null) { writer.writeln(t.to!string); } else { e.print(new TrialResultPrinter(defaultWriter)); } } else { writer.writeln(t.to!string); } writer.writeln(""); } } } } version(Have_fluent_asserts) { class TrialResultPrinter : ResultPrinter { @trusted: ReportWriter writer; this(ReportWriter writer) { this.writer = writer; } void primary(string text) { writer.write(text, ReportWriter.Context._default); writer.write(""); } void info(string text) { writer.write(text, ReportWriter.Context.info); writer.write(""); } void danger(string text) { writer.write(text, ReportWriter.Context.danger); writer.write(""); } void success(string text) { writer.write(text, ReportWriter.Context.success); writer.write(""); } void dangerReverse(string text) { writer.writeReverse(text, ReportWriter.Context.danger); writer.write(""); } void successReverse(string text) { writer.writeReverse(text, ReportWriter.Context.success); writer.write(""); } } }