trial.reporters.landing 34/37(91%) 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
321
330
340
350
360
370
380
390
400
410
420
430
440
450
460
470
480
490
500
510
520
530
541
550
561
570
580
590
600
611
621
631
640
650
660
670
680
690
700
710
720
730
740
750
760
770
780
790
800
810
8210
8320
8410
850
860
870
880
8911
9011
910
9211
9311
940
9511
960
9710
9820
9910
1000
1010
1020
1031
1042
1050
1060
10711
1080
1090
1100
1110
1120
1130
1140
1150
1160
1170
1180
1190
1200
1211
1221
1230
1241
1251
1261
1271
1280
1292
1300
1311
1320
13333
1340
13510
13610
1370
13810
13920
14020
1410
1420
/++ A module containing the LandingReporter This is an example of how this reporter looks <script type="text/javascript" src="https://asciinema.org/a/ar2qel0uzunpjmfzkg7xtvsa1.js" id="asciicast-ar2qel0uzunpjmfzkg7xtvsa1" 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.landing; 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; /// struct LandingGlyphs { string plane = "✈"; string margin = "━"; string lane = "⋅"; } /// string landingGlyphsToCode(LandingGlyphs glyphs) { return "LandingGlyphs(`"~ glyphs.plane ~"`,`"~ glyphs.margin ~"`,`"~ glyphs.lane ~"`)"; } /// The Landing Strip (landing) reporter is a gimmicky test reporter simulating a plane landing unicode ftw class LandingReporter : ITestCaseLifecycleListener, ILifecycleListener { private { ReportWriter writer; LandingGlyphs glyphs; ulong testCount; ulong currentTest; bool success = true; } this(LandingGlyphs glyphs) { writer = defaultWriter; this.glyphs = glyphs; } this(ReportWriter writer) { this.writer = writer; } void begin(ulong testCount) { this.testCount = testCount; writer.writeln("\n\n"); drawLane; } void update() { } void end(SuiteResult[]) { } void begin(string suite, ref TestResult test) { } void end(string suite, ref TestResult test) { currentTest++; success = success && test.status == TestResult.Status.success; drawLane; } private void drawLane() { size_t size = (writer.width / 4) * 3; size_t position = ((cast(double) currentTest / cast(double) testCount) * size).to!size_t; writer.goTo(3); writer.writeln(glyphs.margin.replicate(size), ReportWriter.Context.inactive); if (currentTest < testCount) { writer.write(glyphs.lane.replicate(position), ReportWriter.Context.inactive); writer.write(glyphs.plane, success ? ReportWriter.Context.active : ReportWriter.Context.danger); writer.writeln(glyphs.lane.replicate(size - position - 1), ReportWriter.Context.inactive); } else { writer.write(glyphs.lane.replicate(size), ReportWriter.Context.inactive); writer.writeln(glyphs.plane, success ? ReportWriter.Context.active : ReportWriter.Context.danger); } writer.writeln(glyphs.margin.replicate(size), ReportWriter.Context.inactive); } } version (unittest) { version(Have_fluent_asserts) { import fluent.asserts; } } @("it should print 10 success tests") unittest { auto writer = new BufferedWriter; auto reporter = new LandingReporter(writer); auto suite = SuiteResult("some suite"); auto test = new TestResult("some test"); test.status = TestResult.Status.success; reporter.begin(10); writer.buffer.should.equal("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n" ~ "✈⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅\n" ~ "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n"); auto position = [18, 36, 54, 72, 90, 108, 126, 144, 162, 180]; foreach (i; 0 .. 10) { reporter.begin("some suite", test); reporter.end("some suite", test); auto lines = writer.buffer.split("\n"); lines.length.should.equal(4); lines[1].indexOf("✈").should.equal(position[i]); } }