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
360
370
380
390
401
410
420
430
440
450
460
470
480
490
500
510
520
530
540
550
560
570
580
590
600
611
620
631
640
650
660
670
681
691
701
710
720
730
740
750
760
770
780
790
800
810
820
830
840
850
860
870
880
8910
9020
9110
920
930
940
950
9611
9711
980
9911
1000
10111
10211
1030
10411
10511
1060
1070
1080
1090
1100
1110
1120
1130
1140
1150
1160
1170
1180
1191
1201
1210
1221
1231
1241
1251
1260
1272
1280
12933
1300
13110
13210
1330
1340
1352
1360
/++ 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; version (Have_fluent_asserts) { version = Have_fluent_asserts_core; } /// 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) { version(Have_fluent_asserts_core) { 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"); }