trial.executor.single 34/49(69%) line coverage

      
10
20
30
40
50
60
70
80
90
100
110
120
130
140
150
160
170
180
190
200
211
221
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
551
560
570
580
590
600
611
620
630
640
650
661
671
681
690
700
710
720
730
740
750
760
77122
78122
790
800
810
820
830
840
850
860
870
880
890
900
910
920
930
94122
95122
960
97122
98122
990
100122
1010
102122
103122
1040
105122
1060
107122
1080
109122
1100
111122
1120
1130
1140
1150
1160
1170
118122
119122
1200
121122
1220
1237
1240
1256
1266
1276
1280
1290
1307
1317
1320
1330
134122
135122
136122
137122
1380
139122
1400
1410
1420
1430
1440
1450
module trial.executor.single; public import trial.interfaces; import trial.runner; import std.datetime; import trial.step; import trial.stackresult; class DefaultExecutor : ITestExecutor, IStepLifecycleListener, IAttachmentListener { private { SuiteResult suiteResult; TestResult testResult; StepResult currentStep; StepResult[] stepStack; } this() { suiteResult = SuiteResult("unknown"); } void attach(ref const Attachment attachment) { if(currentStep is null) { suiteResult.attachments ~= Attachment(attachment.name, attachment.file, attachment.mime); return; } currentStep.attachments ~= Attachment(attachment.name, attachment.file, attachment.mime); } void begin(string suite, string test, ref StepResult step) { currentStep.steps ~= step; stepStack ~= currentStep; currentStep = step; LifeCycleListeners.instance.update(); } void end(string suite, string test, ref StepResult step) { currentStep = stepStack[stepStack.length - 1]; stepStack = stepStack[0 .. $ - 1]; LifeCycleListeners.instance.update(); } SuiteResult[] beginExecution(ref const(TestCase)[]) { return []; } SuiteResult[] endExecution() { if (suiteResult.begin == SysTime.fromUnixTime(0)) { return []; } LifeCycleListeners.instance.update(); LifeCycleListeners.instance.end(suiteResult); return [ suiteResult ]; } protected { void runTest(ref const(TestCase) testCase, TestResult testResult) { try { testCase.func(); testResult.status = TestResult.Status.success; } catch (PendingTestException) { testResult.status = TestResult.Status.pending; } catch (Throwable t) { testResult.status = TestResult.Status.failure; testResult.throwable = t.toTestException; } } void createTestResult(const(TestCase) testCase) { testResult = testCase.toTestResult; testResult.begin = Clock.currTime; testResult.status = TestResult.Status.started; currentStep = testResult; stepStack = []; Step.suite = testCase.suiteName; Step.test = testCase.name; LifeCycleListeners.instance.begin(testCase.suiteName, testResult); runTest(testCase, testResult); testResult.end = Clock.currTime; LifeCycleListeners.instance.end(testCase.suiteName, testResult); } } SuiteResult[] execute(ref const(TestCase) testCase) { SuiteResult[] result; LifeCycleListeners.instance.update(); if (suiteResult.name != testCase.suiteName) { if (suiteResult.begin != SysTime.fromUnixTime(0)) { suiteResult.end = Clock.currTime; LifeCycleListeners.instance.end(suiteResult); result = [suiteResult]; } suiteResult = SuiteResult(testCase.suiteName, Clock.currTime, Clock.currTime); LifeCycleListeners.instance.begin(suiteResult); } createTestResult(testCase); suiteResult.tests ~= testResult; currentStep = null; LifeCycleListeners.instance.update(); return result; } }