102030405060708090100110120130140150160170180190200210220230240250260270280290300310320330340350360370380390400410420430440450460470480490500510520530540550560570580590600610620630640650660670680690700710720730740750760770780790800810820830840850860870880890900910920930940950 module trial.reporters.progress; import std.stdio; import std.array; import std.conv; import std.datetime; import std.string; import std.algorithm; import trial.interfaces; import trial.reporters.writer; struct ProgressGlyphs { version(Windows) { string empty = "."; string fill = "#"; } else { string empty = "░"; string fill = "▓"; } } string progressGlyphsToCode(ProgressGlyphs glyphs) { return "ProgressGlyphs(`" ~ glyphs.empty ~ "`,`" ~ glyphs.fill ~ "`)"; } class ProgressReporter : ITestCaseLifecycleListener, ILifecycleListener { private { ReportWriter writer; ProgressGlyphs glyphs; ulong testCount; ulong currentTest; bool success = true; } this(ProgressGlyphs glyphs) { writer = defaultWriter; this.glyphs = glyphs; } this(ReportWriter writer) { this.writer = writer; } void begin(ulong testCount) { this.testCount = testCount; writer.writeln(""); draw; } void update() { } void end(SuiteResult[]) { } void begin(string suite, ref TestResult test) { } void end(string suite, ref TestResult test) { currentTest++; success = success && test.status == TestResult.Status.success; draw; } private void draw() { int size = min((writer.width / 4) * 3, testCount); size_t position = ((cast(double) currentTest / cast(double) testCount) * size).to!size_t; writer.goTo(1); writer.write(currentTest.to!string ~ "/" ~ testCount.to!string ~ " ", success ? ReportWriter.Context.active : ReportWriter.Context.danger); writer.write(glyphs.fill.replicate(position), ReportWriter.Context.active); writer.writeln(glyphs.empty.replicate(size - position), ReportWriter.Context.inactive); } }
module trial.reporters.progress; import std.stdio; import std.array; import std.conv; import std.datetime; import std.string; import std.algorithm; import trial.interfaces; import trial.reporters.writer; struct ProgressGlyphs { version(Windows) { string empty = "."; string fill = "#"; } else { string empty = "░"; string fill = "▓"; } } string progressGlyphsToCode(ProgressGlyphs glyphs) { return "ProgressGlyphs(`" ~ glyphs.empty ~ "`,`" ~ glyphs.fill ~ "`)"; } class ProgressReporter : ITestCaseLifecycleListener, ILifecycleListener { private { ReportWriter writer; ProgressGlyphs glyphs; ulong testCount; ulong currentTest; bool success = true; } this(ProgressGlyphs glyphs) { writer = defaultWriter; this.glyphs = glyphs; } this(ReportWriter writer) { this.writer = writer; } void begin(ulong testCount) { this.testCount = testCount; writer.writeln(""); draw; } void update() { } void end(SuiteResult[]) { } void begin(string suite, ref TestResult test) { } void end(string suite, ref TestResult test) { currentTest++; success = success && test.status == TestResult.Status.success; draw; } private void draw() { int size = min((writer.width / 4) * 3, testCount); size_t position = ((cast(double) currentTest / cast(double) testCount) * size).to!size_t; writer.goTo(1); writer.write(currentTest.to!string ~ "/" ~ testCount.to!string ~ " ", success ? ReportWriter.Context.active : ReportWriter.Context.danger); writer.write(glyphs.fill.replicate(position), ReportWriter.Context.active); writer.writeln(glyphs.empty.replicate(size - position), ReportWriter.Context.inactive); } }