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
320
330
340
350
361
370
380
390
400
410
420
430
440
450
460
470
480
490
500
510
520
530
540
550
560
570
581
590
601
610
620
630
640
651
661
671
680
690
700
710
720
730
740
750
760
770
780
790
800
810
820
830
840
850
8610
8720
8810
890
900
910
920
9311
9411
950
9611
9711
980
9911
1000
10110
10220
10310
1040
1050
1060
1071
1082
1090
1100
11111
1120
1130
1140
1150
1160
1170
1180
1190
1200
1210
1220
1230
1240
1251
1261
1270
1281
1291
1301
1311
1320
1332
1340
1351
1360
13733
1380
13910
14010
1410
14210
14320
14420
1450
1460
/++ 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; version (Have_fluent_asserts) { version = Have_fluent_asserts_core; } /// 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_core) { 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]); } }