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
77883
78883
790
800
810
820
830
840
850
860
870
880
890
900
910
920
930
94883
95883
960
97883
98883
990
100883
1010
102883
103883
1040
105883
1060
107883
1080
109883
1100
111883
1120
1130
1140
1150
1160
1170
118883
119883
1200
121883
1220
123139
1240
125138
126138
127138
1280
1290
130139
131139
1320
1330
134883
135883
136883
137883
1380
139883
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; } }