trial.runner 42/135(31%) line coverage

      
10
20
30
40
50
60
70
80
90
100
110
120
130
140
150
160
170
180
190
200
210
220
231
241
250
260
270
280
290
301
310
321
330
341
351
360
370
381
390
400
410
4210
430
441
450
460
470
481
490
500
510
520
530
540
550
560
570
580
591
601
610
620
630
641
650
660
670
680
690
700
710
720
730
740
750
760
770
780
790
800
810
820
830
840
853
861
871
881
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
1261
1271
1281
1290
1301
1311
1321
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
1770
1780
1790
1800
1810
1820
1830
1840
1850
1860
1870
1880
1890
1900
1910
1920
1930
1940
1950
1960
1970
1980
1990
2000
2010
2020
2030
2040
2050
2060
2070
2080
2090
2100
2110
2120
2130
2140
2150
2160
2170
2180
2190
2200
2210
2220
2230
2240
2250
2260
2270
2280
2290
2300
2310
2320
2330
2340
2350
2361
2370
2381
2390
2401
2410
2420
2430
2441
2450
2460
2470
2481
2490
2501
2510
2522994
253997
2540
2550
2561
2571
2580
2591
2600
2610
2620
2630
2642349
2650
2660
2670
2680
2690
2700
2710
2720
2730
2740
2750
2760
2770
2780
2790
2800
2810
2820
2830
2840
2850
2860
2870
2880
2890
2900
2910
2920
2930
2940
2950
2960
2970
2980
2990
3000
3010
3020
3030
3040
3050
3060
3070
3080
3090
3100
3110
3120
3130
3140
3150
3160
3170
3180
3190
3200
3210
3220
3230
3240
3250
3260
3270
3280
3290
3300
3310
3320
3330
3340
3351
3361
3371
3381
3391
3401
3411
3420
3430
3440
module trial.runner; import std.stdio; import std.algorithm; import std.datetime; import std.range; import std.traits; import std.string; import std.conv; import std.path; import std.getopt; import std.file; import std.path; import std.exception; import trial.settings; import trial.executor.single; import trial.executor.parallel; import trial.executor.process; static this() { if(LifeCycleListeners.instance is null) { LifeCycleListeners.instance = new LifeCycleListeners; } } void setupLifecycle(Settings settings) { settings.artifactsLocation = settings.artifactsLocation.asAbsolutePath.array; Attachment.destination = buildPath(settings.artifactsLocation, "attachment"); if(!Attachment.destination.exists) { Attachment.destination.mkdirRecurse; } if(LifeCycleListeners.instance is null) { LifeCycleListeners.instance = new LifeCycleListeners; } settings.reporters.map!(a => a.toLower).each!(a => addReporter(a, settings)); addExecutor(settings.executor, settings); } void addExecutor(string name, Settings settings) { switch(name) { case "default": LifeCycleListeners.instance.add(new DefaultExecutor); break; case "parallel": LifeCycleListeners.instance.add(new ParallelExecutor(settings.maxThreads)); break; case "process": LifeCycleListeners.instance.add(new ProcessExecutor()); break; default: if(name != "") { writeln("There is no `" ~ name ~ "` executor. Using the default."); } LifeCycleListeners.instance.add(new DefaultExecutor); } } void addReporter(string name, Settings settings) { import trial.reporters.spec; import trial.reporters.specprogress; import trial.reporters.specsteps; import trial.reporters.dotmatrix; import trial.reporters.landing; import trial.reporters.progress; import trial.reporters.list; import trial.reporters.html; import trial.reporters.allure; import trial.reporters.stats; import trial.reporters.result; import trial.reporters.xunit; import trial.reporters.tap; import trial.reporters.visualtrial; switch(name) { case "spec": LifeCycleListeners.instance.add(new SpecReporter(settings)); break; case "spec-progress": auto storage = statsFromFile(buildPath(settings.artifactsLocation, "stats.csv")); LifeCycleListeners.instance.add(new SpecProgressReporter(storage)); break; case "spec-steps": LifeCycleListeners.instance.add(new SpecStepsReporter(settings)); break; case "dot-matrix": LifeCycleListeners.instance.add(new DotMatrixReporter(settings.glyphs.dotMatrix)); break; case "landing": LifeCycleListeners.instance.add(new LandingReporter(settings.glyphs.landing)); break; case "list": LifeCycleListeners.instance.add(new ListReporter(settings)); break; case "progress": LifeCycleListeners.instance.add(new ProgressReporter(settings.glyphs.progress)); break; case "html": LifeCycleListeners.instance.add( new HtmlReporter(buildPath(settings.artifactsLocation, "result.html"), settings.warningTestDuration, settings.dangerTestDuration)); break; case "allure": LifeCycleListeners.instance.add(new AllureReporter(buildPath(settings.artifactsLocation, "allure"))); break; case "xunit": LifeCycleListeners.instance.add(new XUnitReporter(buildPath(settings.artifactsLocation, "xunit"))); break; case "result": LifeCycleListeners.instance.add(new ResultReporter(settings.glyphs.result)); break; case "stats": LifeCycleListeners.instance.add(new StatsReporter(buildPath(settings.artifactsLocation, "stats.csv"))); break; case "tap": LifeCycleListeners.instance.add(new TapReporter); break; case "visualtrial": LifeCycleListeners.instance.add(new VisualTrialReporter); break; default: writeln("There is no `" ~ name ~ "` reporter"); } } const(TestCase)[][string] describeTests() { return describeTests(LifeCycleListeners.instance.getTestCases); } const(TestCase)[][string] describeTests(const(TestCase)[] tests) { const(TestCase)[][string] groupedTests; foreach(test; tests) { groupedTests[test.suiteName] ~= test; } return groupedTests; } string toJSONHierarchy(T)(const(T)[][string] items) { struct Node { Node[string] nodes; const(T)[] values; void add(string[] path, const(T)[] values) { if(path.length == 0) { this.values = values; return; } if(path[0] !in nodes) { nodes[path[0]] = Node(); } nodes[path[0]].add(path[1..$], values); } string toString(int spaces = 2) { string prefix = leftJustify("", spaces); string endPrefix = leftJustify("", spaces - 2); string listValues = ""; string objectValues = ""; if(values.length > 0) { listValues = values .map!(a => a.toString) .map!(a => prefix ~ a) .join(",\n"); } if(nodes.keys.length > 0) { objectValues = nodes .byKeyValue .map!(a => `"` ~ a.key ~ `": ` ~ a.value.toString(spaces + 2)) .map!(a => prefix ~ a) .join(",\n"); } if(listValues != "" && objectValues != "") { return "{\n" ~ objectValues ~ ",\n" ~ prefix ~ "\"\": [\n" ~ listValues ~ "\n" ~ prefix ~ "]\n" ~ endPrefix ~ "}"; } if(listValues != "") { return "[\n" ~ listValues ~ "\n" ~ endPrefix ~ "]"; } return "{\n" ~ objectValues ~ "\n" ~ endPrefix ~ "}"; } } Node root; foreach(key; items.keys) { root.add(key.split("."), items[key]); } return root.toString; } auto runTests(const(TestCase)[] tests, string testName = "", string suiteName = "") { setupSegmentationHandler!true(); const(TestCase)[] filteredTests = tests; if(testName != "") { filteredTests = tests.filter!(a => a.name.indexOf(testName) != -1).array; } if(suiteName != "") { filteredTests = filteredTests.filter!(a => a.suiteName.indexOf(suiteName) != -1).array; } LifeCycleListeners.instance.begin(filteredTests.length); SuiteResult[] results = LifeCycleListeners.instance.beginExecution(filteredTests); foreach(test; filteredTests) { results ~= LifeCycleListeners.instance.execute(test); } results ~= LifeCycleListeners.instance.endExecution; LifeCycleListeners.instance.end(results); return results; } bool isSuccess(SuiteResult[] results) { return results.map!(a => a.tests).joiner.map!(a => a.status).all!(a => a == TestResult.Status.success || a == TestResult.Status.pending); } void setupSegmentationHandler(bool testRunner)() { import core.runtime; version(CRuntime_Glibc) import core.sys.linux.execinfo; else version(OSX) import core.sys.darwin.execinfo; else version(FreeBSD) import core.sys.freebsd.execinfo; else version(NetBSD) import core.sys.netbsd.execinfo; else version(Windows) import core.sys.windows.stacktrace; else version(Solaris) import core.sys.solaris.execinfo; static if( __traits( compiles, backtrace ) ) { version(Posix) { import core.sys.posix.signal; static extern (C) void unittestSegvHandler(int signum, siginfo_t* info, void* ptr ) nothrow { import core.stdc.stdio; core.stdc.stdio.printf("\n\n"); static if(testRunner) { if(signum == SIGSEGV) { core.stdc.stdio.printf("Got a Segmentation Fault running "); } if(signum == SIGBUS) { core.stdc.stdio.printf("Got a bus error running "); } if(LifeCycleListeners.instance.runningTest != "") { core.stdc.stdio.printf("%s\n\n", LifeCycleListeners.instance.runningTest.ptr); } else { core.stdc.stdio.printf("some setup step. This is probably a Trial bug. Please create an issue on github.\n\n"); } } else { if(signum == SIGSEGV) { core.stdc.stdio.printf("Got a Segmentation Fault! "); } if(signum == SIGBUS) { core.stdc.stdio.printf("Got a bus error! "); } core.stdc.stdio.printf(" This is probably a Trial bug. Please create an issue on github.\n\n"); } static enum MAXFRAMES = 128; void*[MAXFRAMES] callstack; int numframes; numframes = backtrace( callstack.ptr, MAXFRAMES ); backtrace_symbols_fd( callstack.ptr, numframes, 2); } sigaction_t action = void; (cast(byte*) &action)[0 .. action.sizeof] = 0; sigfillset( &action.sa_mask ); action.sa_flags = SA_SIGINFO | SA_RESETHAND; action.sa_sigaction = &unittestSegvHandler; sigaction( SIGSEGV, &action, null ); sigaction( SIGBUS, &action, null ); } } }