trial.reporters.specprogress 0/39(0%) 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
400
410
420
430
440
450
460
470
480
490
500
510
520
530
540
550
560
570
580
590
600
610
620
630
640
650
660
670
680
690
700
710
720
730
740
750
760
770
780
790
800
810
820
830
840
850
860
870
880
890
900
910
920
930
940
950
960
970
980
990
1000
1010
1020
1030
1040
1050
1060
1070
1080
1090
1100
1110
1120
module trial.reporters.specprogress; import std.stdio; import std.array; import std.conv; import std.datetime; import std.algorithm; import trial.interfaces; import trial.reporters.writer; import trial.reporters.stats; import trial.reporters.spec; class SpecProgressReporter : SpecReporter, ISuiteLifecycleListener, ILifecycleListener { private { alias UpdateFunction = void delegate(CueInfo info); struct CueInfo { string id; string name; long duration; SysTime begin; } size_t oldTextLength; StatStorage storage; string[] path; CueInfo[] cues; } this(StatStorage storage) { super(); this.storage = storage; writer.writeln(""); } this(ReportWriter writer, StatStorage storage) { super(writer); this.storage = storage; writer.writeln(""); } void clearProgress() { writer.goTo(1); writer.write("\n" ~ " ".replicate(oldTextLength)); writer.goTo(1); oldTextLength = 0; } void begin(ulong) {} void end(SuiteResult[]) {} void update() { writer.hideCursor; auto now = Clock.currTime; auto progress = cues.map!(cue => "*[" ~ (cue.duration - (now - cue.begin).total!"seconds").to!string ~ "s]" ~ cue.name).join(" ").to!string; auto spaces = ""; if(oldTextLength > progress.length) { spaces = " ".replicate(oldTextLength - progress.length); } writer.goTo(1); writer.write("\n" ~ progress ~ spaces ~ " "); oldTextLength = progress.length; writer.showCursor; } void removeCue(string id) { cues = cues.filter!(a => a.id != id).array; } void begin(ref SuiteResult suite) { auto stat = storage.find(suite.name); auto duration = (stat.end - stat.begin).total!"seconds"; cues ~= CueInfo(suite.name, suite.name, duration, Clock.currTime); update; } void end(ref SuiteResult suite) { removeCue(suite.name); update; } override { void begin(string suite, ref TestResult test) { super.begin(suite, test); auto stat = storage.find(suite ~ "." ~ test.name); auto duration = (stat.end - stat.begin).total!"seconds"; cues ~= CueInfo(suite ~ "." ~ test.name, test.name, duration, Clock.currTime); update; } void end(string suite, ref TestResult test) { clearProgress; super.end(suite, test); removeCue(suite ~ "." ~ test.name); writer.writeln(""); update; } } }