trial.reporters.stats 0/37(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
1130
1140
1150
1160
1170
1180
1190
1200
1210
1220
1230
1240
1250
1260
1270
1280
1290
1300
1310
1320
1330
1340
1350
1360
1370
1380
1390
1400
1410
1420
1430
1440
1450
1460
1470
1480
1490
1500
1510
1520
1530
1540
1550
1560
1570
1580
1590
1600
1610
1620
1630
1640
1650
1660
1670
1680
1690
1700
1710
1720
1730
1740
1750
1760
module trial.reporters.stats; import std.algorithm; import std.string; import std.conv; import std.exception; import std.array; import std.datetime; import std.stdio; import std.file; import std.path; import trial.runner; import trial.interfaces; struct Stat { string name; SysTime begin; SysTime end; TestResult.Status status = TestResult.Status.unknown; SourceLocation location; } class StatStorage { Stat[] values; } Stat find(StatStorage storage, const(string) name) { auto res = storage.values.filter!(a => a.name == name); if (res.empty) { return Stat("", SysTime.min, SysTime.min); } return res.front; } class StatsReporter : ILifecycleListener, ITestCaseLifecycleListener, ISuiteLifecycleListener, IStepLifecycleListener { private { immutable string destination; StatStorage storage; string[][string] path; } this(StatStorage storage, string destination) { this.storage = storage; this.destination = destination; } this(string destination) { this(new StatStorage, destination); } private { auto lastItem(string key) { enforce(path[key].length > 0, "There is no defined path"); return path[key][path.length - 1]; } } void update() { } void begin(ref SuiteResult suite) { } void end(ref SuiteResult suite) { storage.values ~= Stat(suite.name, suite.begin, Clock.currTime); } void begin(string suite, ref TestResult test) { } void end(string suite, ref TestResult test) { storage.values ~= Stat(suite ~ "." ~ test.name, test.begin, Clock.currTime, test.status, SourceLocation(test.fileName, test.line)); } void begin(string suite, string test, ref StepResult step) { string key = suite ~ "." ~ test; path[key] ~= step.name; } void end(string suite, string test, ref StepResult step) { string key = suite ~ "." ~ test; enforce(lastItem(key) == step.name, "Invalid step name"); storage.values ~= Stat(key ~ "." ~ path[key].join('.'), step.begin, Clock.currTime); path[key] = path[key][0 .. $ - 1]; } void begin(ulong) { } void end(SuiteResult[]) { auto parent = buildPath(pathSplitter(destination).array[0..$-1]); if(parent != "" && !parent.exists) { mkdirRecurse(parent); } std.file.write(destination, storage.toCsv); auto attachment = const Attachment("stats", destination, "text/csv"); if(LifeCycleListeners.instance !is null) { LifeCycleListeners.instance.attach(attachment); } } } string toCsv(const(StatStorage) storage) { return storage.values.map!(a => [a.name, a.begin.toISOExtString, a.end.toISOExtString, a.status.to!string, a.location.fileName, a.location.line.to!string]).map!(a => a.join(',')).join('\n'); } StatStorage toStatStorage(const(string) data) { auto stat = new StatStorage; stat.values = data .split('\n') .map!(a => a.split(',')) .filter!(a => a.length == 6) .map!(a => Stat(a[0], SysTime.fromISOExtString(a[1]), SysTime.fromISOExtString(a[2]), a[3].to!(TestResult.Status), SourceLocation(a[4], a[5].to!size_t))) .array; return stat; } StatStorage statsFromFile(string fileName) { if (!fileName.exists) { return new StatStorage(); } return fileName.readText.toStatStorage; }