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
461
470
480
490
500
510
520
530
540
550
560
570
580
590
600
610
620
630
640
650
664
670
684
690
700
710
720
734
740
750
760
770
780
790
800
810
826
836
840
850
860
870
886
890
906
913
923
932
942
951
961
970
980
990
1000
1016
1020
1037
1040
1050
1060
1076
1081
1090
1100
1116
1120
1130
1140
1150
1160
1176
1186
1196
1200
1210
1220
1230
1246
1250
1260
1270
1280
1290
1300
1310
1320
1330
1340
1350
1361
1371
1380
1391
1401
1411
1420
1431
1441
1450
1461
1471
1480
1491
1501
1511
1521
1531
1541
1550
1561
1570
1581
1591
1600
1611
1620
1632
1640
1650
1660
1670
1680
1690
1700
1710
1720
1730
1740
1750
1760
1771
1781
1790
1801
1811
1821
1830
1841
1851
1861
1870
1881
1890
1902
1910
1920
1930
1940
1950
1960
1970
1980
1990
2001
2011
2020
2031
2041
2051
2061
2071
2080
2091
2101
2111
2120
2131
2140
2152
2160
2170
2180
2190
2200
2210
2220
2230
2240
2251
2261
2270
2281
2291
2301
2310
2321
2331
2340
2351
2361
2370
2381
2391
2401
2411
2421
2431
2440
2451
2460
2471
2481
2490
2501
2510
2522
2530
2540
2550
2560
2570
2580
2590
2600
2610
/++ 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; /// 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) { 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"); }