trial.reporters.specsteps 85/90(94%) 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
501
510
520
530
540
550
560
570
580
590
600
610
620
630
640
650
660
670
680
690
704
710
724
730
740
750
760
774
780
790
800
810
820
830
840
850
866
876
880
890
900
910
926
930
946
953
963
972
982
991
1001
1010
1020
1030
1040
1056
1060
1077
1080
1090
1100
1116
1121
1130
1140
1156
1160
1170
1180
1190
1200
1216
1226
1236
1240
1250
1260
1270
1286
1290
1300
1310
1320
1330
1340
1350
1360
1370
1380
1390
1400
1410
1421
1431
1440
1451
1461
1471
1480
1491
1501
1510
1521
1531
1540
1551
1561
1571
1581
1591
1601
1610
1621
1630
1641
1651
1660
1671
1680
1692
1700
1710
1720
1730
1740
1750
1760
1770
1780
1790
1800
1810
1820
1831
1841
1850
1861
1871
1881
1890
1901
1911
1921
1930
1941
1950
1962
1970
1980
1990
2000
2010
2020
2030
2040
2050
2061
2071
2080
2091
2101
2111
2121
2131
2140
2151
2161
2171
2180
2191
2200
2212
2220
2230
2240
2250
2260
2270
2280
2290
2300
2311
2321
2330
2341
2351
2361
2370
2381
2391
2400
2411
2421
2430
2441
2451
2461
2471
2481
2491
2500
2511
2520
2531
2541
2550
2561
2570
2582
2590
2600
2610
2620
2630
2640
2650
2660
2670
/++ A module containing the SpecStepsReporter This is an example of how this reporter looks <script type="text/javascript" src="https://asciinema.org/a/bsk6do8t4zay9k9vznvh8yn71.js" id="asciicast-bsk6do8t4zay9k9vznvh8yn71" async></script> Copyright: © 2017 Szabo Bogdan License: Subject to the terms of the MIT license, as written in the included LICENSE.txt file. Authors: Szabo Bogdan +/ module trial.reporters.specsteps; import trial.interfaces; import trial.reporters.spec; import trial.reporters.writer; import trial.settings; import std.datetime; import std.conv; version (Have_fluent_asserts) { version = Have_fluent_asserts_core; } /// A structure containing the glyphs used for the spec steps reporter struct SpecStepsGlyphs { version(Windows) { /// string testBegin = "/"; /// string testEnd = "\\"; /// string step = "|"; } else { /// string testBegin = "┌"; /// string testEnd = "└"; /// string step = "│"; } } /// string specStepsGlyphsToCode(SpecStepsGlyphs glyphs) { return "SpecStepsGlyphs(`" ~ glyphs.testBegin ~ "`, `" ~ glyphs.testEnd ~ "`, `" ~ glyphs.step ~ "`)"; } /// A flavour of the "spec" reporter that show the tests and the steps of your tests. class SpecStepsReporter : SpecReporter, ISuiteLifecycleListener, IStepLifecycleListener { private { size_t indents; size_t stepIndents; Settings settings; } this(Settings settings) { super(settings); this.settings = settings; } this(ReportWriter writer) { super(writer); } void begin(ref SuiteResult suite) { indents = printSuite(suite.name); } void end(ref SuiteResult) { } override { void begin(string suite, ref TestResult test) { stepIndents = 0; write!(Type.none)(settings.glyphs.specSteps.testBegin ~ " " ~ test.name ~ "\n", indents); } void end(string suite, ref TestResult test) { write!(Type.none)(settings.glyphs.specSteps.testEnd ~ " ", indents); if(test.status == TestResult.Status.success) { write!(Type.success)("Success", 0); } else if(test.status == TestResult.Status.failure) { write!(Type.failure)("Failure", 0); failedTests++; } else if(test.status == TestResult.Status.pending) { write!(Type.pending)("Pending", 0); } else { write!(Type.none)("Unknown", 0); } auto timeDiff = (test.end - test.begin).total!"msecs"; if(timeDiff >= settings.warningTestDuration && timeDiff < settings.dangerTestDuration) { write!(Type.warning)(" (" ~ timeDiff.to!string ~ "ms)", 0); } if(timeDiff >= settings.dangerTestDuration) { write!(Type.danger)(" (" ~ timeDiff.to!string ~ "ms)", 0); } write!(Type.none)("\n", 0); } } void begin(string suite, string test, ref StepResult s) { stepIndents++; write!(Type.none)(settings.glyphs.specSteps.step, indents); write!(Type.none)(" " ~ s.name ~ "\n", stepIndents); } void end(string suite, string test, ref StepResult) { stepIndents--; } } version (unittest) { version(Have_fluent_asserts_core) { import fluent.asserts; } } @("it should format the steps for a success test") unittest { auto writer = new BufferedWriter; auto reporter = new SpecStepsReporter(writer); auto suite = SuiteResult("some suite"); auto test = new TestResult("some test"); test.status = TestResult.Status.success; auto step = new StepResult(); step.name = "some step"; reporter.begin(suite); reporter.begin("some suite", test); reporter.begin("some suite", "some test", step); reporter.begin("some suite", "some test", step); reporter.end("some suite", "some test", step); reporter.end("some suite", "some test", step); reporter.begin("some suite", "some test", step); reporter.end("some suite", "some test", step); reporter.end("some suite", test); reporter.begin("some suite", test); reporter.end("some suite", test); reporter.end(suite); writer.buffer.should.equal("\n" ~ " some suite\n" ~ " ┌ some test\n" ~ " │ some step\n" ~ " │ some step\n" ~ " │ some step\n" ~ " └ ✓ Success\n" ~ " ┌ some test\n" ~ " └ ✓ Success\n"); } @("it should format a pending test") unittest { auto writer = new BufferedWriter; auto reporter = new SpecStepsReporter(writer); auto suite = SuiteResult("some suite"); auto test = new TestResult("some test"); test.status = TestResult.Status.pending; reporter.begin(suite); reporter.begin("some suite", test); reporter.end("some suite", test); reporter.end(suite); writer.buffer.should.equal("\n" ~ " some suite\n" ~ " ┌ some test\n" ~ " └ - Pending\n"); } @("it should print the duration of a long test") unittest { auto writer = new BufferedWriter; auto reporter = new SpecStepsReporter(writer); auto suite = SuiteResult("some suite"); auto test = new TestResult("some test"); test.status = TestResult.Status.success; test.end = Clock.currTime; test.begin = test.end - 200.msecs; reporter.begin(suite); reporter.begin("some suite", test); reporter.end("some suite", test); reporter.end(suite); writer.buffer.should.equal("\n" ~ " some suite\n" ~ " ┌ some test\n" ~ " └ ✓ Success (200ms)\n"); } @("it should format the steps for a failing test") unittest { auto writer = new BufferedWriter; auto reporter = new SpecStepsReporter(writer); auto suite = SuiteResult("some suite"); auto test = new TestResult("some test"); test.status = TestResult.Status.failure; auto step = new StepResult(); step.name = "some step"; reporter.begin(suite); reporter.begin("some suite", test); reporter.begin("some suite", "some test", step); reporter.begin("some suite", "some test", step); reporter.end("some suite", "some test", step); reporter.end("some suite", "some test", step); reporter.begin("some suite", "some test", step); reporter.end("some suite", "some test", step); reporter.end("some suite", test); reporter.begin("some suite", test); reporter.end("some suite", test); reporter.end(suite); writer.buffer.should.equal("\n" ~ " some suite\n" ~ " ┌ some test\n" ~ " │ some step\n" ~ " │ some step\n" ~ " │ some step\n" ~ " └ 0) Failure\n" ~ " ┌ some test\n" ~ " └ 1) Failure\n"); }