1 module cucumber.formatter.base; 2 3 import std.array : join; 4 import std..string : format; 5 import std.stdio : write, writeln; 6 import std.typecons : Nullable, tuple; 7 8 import cucumber.result : Result, ResultSummary, RunResult, ScenarioResult, StepResult; 9 import gherkin : Feature, Scenario, Step, Examples, TableRow, Comment; 10 11 /// 12 interface Formatter 13 { 14 /// 15 void feature(Feature); 16 17 /// 18 void scenario(ref Scenario); 19 20 /// 21 void scenarioOutline(ref Scenario); 22 23 /// 24 void examples(Examples); 25 26 /// 27 void tableRow(TableRow, ref TableRow[], string); 28 29 /// 30 void tableRow(TableRow, ref TableRow[], ScenarioResult); 31 32 /// 33 void step(Step, StepResult); 34 35 /// 36 void emptyLine(); 37 38 /// 39 void comment(Comment); 40 41 /// 42 void summarizeResult(RunResult); 43 44 /// 45 string color(string); 46 47 /// 48 final string resultSummary(ResultSummary summary) 49 { 50 string[] result; 51 foreach (t; [ 52 tuple("failed", summary.failed), tuple("skipped", summary.skipped), 53 tuple("undefined", summary.undefined), 54 tuple("passed", summary.passed) 55 ]) 56 { 57 if (t[1] > 0) 58 { 59 result ~= "%s%d %s%s".format(color(t[0]), t[1], t[0], color("reset")); 60 } 61 } 62 return result.join(", "); 63 } 64 65 /// 66 final void runResult(RunResult runResult) 67 { 68 string result; 69 foreach (k, v; runResult.resultSummaries) 70 { 71 result ~= "%s %s".format(v.total, k); 72 if (v.total > 0) 73 { 74 result ~= " (%s)".format(resultSummary(v)); 75 } 76 result ~= "\n"; 77 } 78 result ~= runResult.time.toString(); 79 80 writeln(result); 81 } 82 }