trial.reporters.dotmatrix 40/45(88%) 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
371
380
390
400
410
420
430
440
450
460
470
480
490
500
510
520
530
540
550
563
570
583
590
600
610
620
630
640
650
660
673
680
691
701
711
720
731
741
751
760
771
781
791
800
810
820
830
840
850
860
870
880
890
900
910
920
930
940
950
960
971
981
990
1001
1011
1021
1030
1041
1052
1060
1071
1082
1090
1100
1110
1120
1130
1141
1151
1160
1171
1181
1191
1200
1211
1222
1230
1241
1252
1260
1270
1280
1290
1300
1311
1321
1330
1341
1351
1361
1370
1381
1392
1400
1411
1422
1430
/++ A module containing the DotMatrixReporter This is an example of how this reporter looks <script type="text/javascript" src="https://asciinema.org/a/aorvsrruse34n2xym8y7885m1.js" id="asciicast-aorvsrruse34n2xym8y7885m1" 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.dotmatrix; import std.stdio; import std.array; import std.conv; import std.datetime; import std.string; import std.algorithm; import trial.interfaces; import trial.reporters.writer; version (Have_fluent_asserts) { version = Have_fluent_asserts_core; } /// struct DotMatrixGlyphs { string success = "."; string failure = "!"; string unknown = "?"; string pending = "-"; } /// string dotMatrixGlyphsToCode(DotMatrixGlyphs glyphs) { return "DotMatrixGlyphs(`"~ glyphs.success ~"`,`"~ glyphs.failure ~"`,`"~ glyphs.unknown ~"`)"; } /// The dot matrix reporter is simply a series of characters which represent test cases. /// Failures highlight in red exclamation marks (!). /// Good if you prefer minimal output. class DotMatrixReporter : ITestCaseLifecycleListener { private { ReportWriter writer; DotMatrixGlyphs glyphs; } this(DotMatrixGlyphs glyphs) { writer = defaultWriter; this.glyphs = glyphs; } this(ReportWriter writer) { this.writer = writer; } void begin(string suite, ref TestResult test) { } void end(string suite, ref TestResult test) { switch (test.status) { case TestResult.Status.success: writer.write(glyphs.success, ReportWriter.Context.inactive); break; case TestResult.Status.failure: writer.write(glyphs.failure, ReportWriter.Context.danger); break; case TestResult.Status.pending: writer.write(glyphs.pending, ReportWriter.Context.info); break; default: writer.write(glyphs.unknown, ReportWriter.Context.warning); } } } version (unittest) { version(Have_fluent_asserts_core) { import fluent.asserts; } } @("it should print a success test") unittest { auto writer = new BufferedWriter; auto reporter = new DotMatrixReporter(writer); auto suite = SuiteResult("some suite"); auto test = new TestResult("some test"); test.status = TestResult.Status.success; reporter.begin("some suite", test); writer.buffer.should.equal(""); reporter.end("some suite", test); writer.buffer.should.equal("."); } @("it should print a failing test") unittest { auto writer = new BufferedWriter; auto reporter = new DotMatrixReporter(writer); auto suite = SuiteResult("some suite"); auto test = new TestResult("some test"); test.status = TestResult.Status.failure; reporter.begin("some suite", test); writer.buffer.should.equal(""); reporter.end("some suite", test); writer.buffer.should.equal("!"); } @("it should print a pending test") unittest { auto writer = new BufferedWriter; auto reporter = new DotMatrixReporter(writer); auto suite = SuiteResult("some suite"); auto test = new TestResult("some test"); test.status = TestResult.Status.pending; reporter.begin("some suite", test); writer.buffer.should.equal(""); reporter.end("some suite", test); writer.buffer.should.equal("-"); }