1020304050607080901001101201301401501601701801902002102202302402502602702802903003103203303403503603703803904004104204304404504604704804905005105205305405505605705805906006106206306406506606706816907017117207307407507607707807908008108208325688408508608708808925689009125689209313729413729513729609799798997999971009971010102010301040105010601070108010901100111011201130114011501160117011801190120199121199122012301240125012601270128012901301761310132176133176134176135013617613701381761391761400141112514201431991441991451991460147014817614901500151015201539971540155997156015717615801590160016182116201630164997165016699716701680169997170017101720173017499717501760177017801790180997181018299718301840185018699718701880189019099719101929971930194019501960 module trial.reporters.spec; import std.stdio; import std.array; import std.conv; import std.datetime; import std.string; import std.algorithm; import trial.interfaces; import trial.settings; import trial.reporters.writer; struct SpecGlyphs { version(Windows) { string ok = "+"; } else { string ok = "✓"; } string pending = "-"; } string specGlyphsToCode(SpecGlyphs glyphs) { return "SpecGlyphs(`" ~ glyphs.ok ~ "`)"; } class SpecReporter : ITestCaseLifecycleListener { enum Type { none, success, step, pending, failure, testBegin, testEnd, emptyLine, danger, warning } protected { int failedTests = 0; string lastSuiteName; ReportWriter writer; } private { Settings settings; } this() { writer = defaultWriter; } this(Settings settings) { writer = defaultWriter; this.settings = settings; } this(ReportWriter writer) { this.writer = writer; } private { string indentation(size_t cnt) pure { return " ".replicate(cnt); } } void write(Type t)(string text = "", size_t spaces = 0) { writer.write(indentation(spaces)); switch (t) { case Type.emptyLine: writer.writeln(""); break; case Type.success: writer.write(settings.glyphs.spec.ok, ReportWriter.Context.success); writer.write(" " ~ text, ReportWriter.Context.inactive); break; case Type.pending: writer.write(settings.glyphs.spec.pending, ReportWriter.Context.info); writer.write(" " ~ text, ReportWriter.Context.inactive); break; case Type.failure: writer.write(failedTests.to!string ~ ") " ~ text, ReportWriter.Context.danger); break; case Type.danger: writer.write(text, ReportWriter.Context.danger); break; case Type.warning: writer.write(text, ReportWriter.Context.warning); break; default: writer.write(text); } } void begin(string suite, ref TestResult test) { } protected auto printSuite(string suite) { size_t indents = 1; auto oldPieces = lastSuiteName.split("."); auto pieces = suite.split("."); lastSuiteName = suite; auto prefix = oldPieces.commonPrefix(pieces).array.length; write!(Type.emptyLine)(); indents += prefix; foreach (piece; pieces[prefix .. $]) { write!(Type.none)(piece, indents); write!(Type.emptyLine)(); indents++; } return indents; } void end(string suite, ref TestResult test) { size_t indents = 1; if (suite != lastSuiteName) { indents = printSuite(suite); } else { indents = suite.count('.') + 2; } if (test.status == TestResult.Status.success) { write!(Type.success)(test.name, indents); } if (test.status == TestResult.Status.pending) { write!(Type.pending)(test.name, indents); } if (test.status == TestResult.Status.failure) { write!(Type.failure)(test.name, indents); failedTests++; } auto timeDiff = (test.end - test.begin).total!"msecs"; if(timeDiff >= settings.warningTestDuration && timeDiff < settings.dangerTestDuration) { write!(Type.warning)(" (" ~ timeDiff.to!string ~ "ms)", 0); } if(timeDiff >= settings.dangerTestDuration) { write!(Type.danger)(" (" ~ timeDiff.to!string ~ "ms)", 0); } write!(Type.emptyLine); indents--; } }
module trial.reporters.spec; import std.stdio; import std.array; import std.conv; import std.datetime; import std.string; import std.algorithm; import trial.interfaces; import trial.settings; import trial.reporters.writer; struct SpecGlyphs { version(Windows) { string ok = "+"; } else { string ok = "✓"; } string pending = "-"; } string specGlyphsToCode(SpecGlyphs glyphs) { return "SpecGlyphs(`" ~ glyphs.ok ~ "`)"; } class SpecReporter : ITestCaseLifecycleListener { enum Type { none, success, step, pending, failure, testBegin, testEnd, emptyLine, danger, warning } protected { int failedTests = 0; string lastSuiteName; ReportWriter writer; } private { Settings settings; } this() { writer = defaultWriter; } this(Settings settings) { writer = defaultWriter; this.settings = settings; } this(ReportWriter writer) { this.writer = writer; } private { string indentation(size_t cnt) pure { return " ".replicate(cnt); } } void write(Type t)(string text = "", size_t spaces = 0) { writer.write(indentation(spaces)); switch (t) { case Type.emptyLine: writer.writeln(""); break; case Type.success: writer.write(settings.glyphs.spec.ok, ReportWriter.Context.success); writer.write(" " ~ text, ReportWriter.Context.inactive); break; case Type.pending: writer.write(settings.glyphs.spec.pending, ReportWriter.Context.info); writer.write(" " ~ text, ReportWriter.Context.inactive); break; case Type.failure: writer.write(failedTests.to!string ~ ") " ~ text, ReportWriter.Context.danger); break; case Type.danger: writer.write(text, ReportWriter.Context.danger); break; case Type.warning: writer.write(text, ReportWriter.Context.warning); break; default: writer.write(text); } } void begin(string suite, ref TestResult test) { } protected auto printSuite(string suite) { size_t indents = 1; auto oldPieces = lastSuiteName.split("."); auto pieces = suite.split("."); lastSuiteName = suite; auto prefix = oldPieces.commonPrefix(pieces).array.length; write!(Type.emptyLine)(); indents += prefix; foreach (piece; pieces[prefix .. $]) { write!(Type.none)(piece, indents); write!(Type.emptyLine)(); indents++; } return indents; } void end(string suite, ref TestResult test) { size_t indents = 1; if (suite != lastSuiteName) { indents = printSuite(suite); } else { indents = suite.count('.') + 2; } if (test.status == TestResult.Status.success) { write!(Type.success)(test.name, indents); } if (test.status == TestResult.Status.pending) { write!(Type.pending)(test.name, indents); } if (test.status == TestResult.Status.failure) { write!(Type.failure)(test.name, indents); failedTests++; } auto timeDiff = (test.end - test.begin).total!"msecs"; if(timeDiff >= settings.warningTestDuration && timeDiff < settings.dangerTestDuration) { write!(Type.warning)(" (" ~ timeDiff.to!string ~ "ms)", 0); } if(timeDiff >= settings.dangerTestDuration) { write!(Type.danger)(" (" ~ timeDiff.to!string ~ "ms)", 0); } write!(Type.emptyLine); indents--; } }