trial.reporters.progress 27/30(90%) 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
571
580
591
600
610
620
630
641
651
661
670
680
690
700
710
720
730
740
750
760
770
780
790
800
810
820
830
840
8510
8620
8710
880
890
900
910
9211
9311
940
9511
960
9711
9811
990
10011
10111
1020
1030
1040
1050
1060
1070
1080
1090
1100
1110
1120
1131
1141
1150
1161
1171
1181
1191
1200
1212
1220
12333
1240
12510
12610
1270
1280
1292
1300
/++ A module containing the ProgressReporter This is an example of how this reporter looks <script type="text/javascript" src="https://asciinema.org/a/a3aspcv8cw5l04l59xw9vbtqa.js" id="asciicast-a3aspcv8cw5l04l59xw9vbtqa" 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.progress; 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 ProgressGlyphs { version(Windows) { string empty = "."; string fill = "#"; } else { string empty = "░"; string fill = "▓"; } } /// string progressGlyphsToCode(ProgressGlyphs glyphs) { return "ProgressGlyphs(`" ~ glyphs.empty ~ "`,`" ~ glyphs.fill ~ "`)"; } /// The “progress” reporter implements a simple progress-bar class ProgressReporter : ITestCaseLifecycleListener, ILifecycleListener { private { ReportWriter writer; ProgressGlyphs glyphs; ulong testCount; ulong currentTest; bool success = true; } this(ProgressGlyphs glyphs) { writer = defaultWriter; this.glyphs = glyphs; } this(ReportWriter writer) { this.writer = writer; } void begin(ulong testCount) { this.testCount = testCount; writer.writeln(""); draw; } 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; draw; } private void draw() { int size = min((writer.width / 4) * 3, testCount); size_t position = ((cast(double) currentTest / cast(double) testCount) * size).to!size_t; writer.goTo(1); writer.write(currentTest.to!string ~ "/" ~ testCount.to!string ~ " ", success ? ReportWriter.Context.active : ReportWriter.Context.danger); writer.write(glyphs.fill.replicate(position), ReportWriter.Context.active); writer.writeln(glyphs.empty.replicate(size - position), ReportWriter.Context.inactive); } } version (unittest) { import fluent.asserts; } @("it should print 10 success tests") unittest { auto writer = new BufferedWriter; auto reporter = new ProgressReporter(writer); auto suite = SuiteResult("some suite"); auto test = new TestResult("some test"); test.status = TestResult.Status.success; reporter.begin(10); writer.buffer.should.equal("0/10 ░░░░░░░░░░\n"); foreach (i; 0 .. 10) { reporter.begin("some suite", test); reporter.end("some suite", test); } writer.buffer.should.equal("10/10 ▓▓▓▓▓▓▓▓▓▓\n"); }