VisualTrialReporterParser

Parse the output from the visual trial reporter

Members

Aliases

OutputEvent
alias OutputEvent = void delegate(string)
Undocumented in source.
ResultEvent
alias ResultEvent = void delegate(TestResult)
Undocumented in source.

Functions

add
void add(string line)

add a line to the parser

Variables

onOutput
OutputEvent onOutput;
Undocumented in source.
onResult
ResultEvent onResult;
Undocumented in source.
readingTest
bool readingTest;
Undocumented in source.
suite
string suite;
Undocumented in source.
testResult
TestResult testResult;
Undocumented in source.

Examples

Parse a successful test

auto parser = new VisualTrialReporterParser();
parser.testResult.should.beNull;
auto begin = Clock.currTime;

parser.add("BEGIN TEST;");
parser.testResult.should.not.beNull;
parser.testResult.begin.should.be.greaterThan(begin);
parser.testResult.end.should.be.greaterThan(begin);
parser.testResult.status.should.equal(TestResult.Status.created);

parser.add("suite:suite name");
parser.suite.should.equal("suite name");

parser.add("test:test name");
parser.testResult.name.should.equal("test name");

parser.add("file:some file.d");
parser.testResult.fileName.should.equal("some file.d");

parser.add("line:22");
parser.testResult.line.should.equal(22);

parser.add(`labels:[ { "name": "name1", "value": "label1" }, { "name": "name2", "value": "label2" }]`);
parser.testResult.labels.should.equal([Label("name1", "label1"), Label("name2", "label2")]);

parser.add("status:success");
parser.testResult.status.should.equal(TestResult.Status.success);

parser.add("END TEST;");
parser.testResult.should.beNull;

Parse a failing test

auto parser = new VisualTrialReporterParser();
parser.testResult.should.beNull;
auto begin = Clock.currTime;

parser.add("BEGIN TEST;");

parser.add("errorFile:file.d");
parser.add("errorLine:147");
parser.add("message:line1");
parser.add("line2");
parser.add("line3");

parser.testResult.throwable.should.not.beNull;
parser.testResult.throwable.file.should.equal("file.d");
parser.testResult.throwable.line.should.equal(147);

parser.add("END TEST;");
parser.testResult.should.beNull;

Raise an event when the test is ended

bool called;

void checkResult(TestResult result) {
  called = true;
  result.should.not.beNull;
}

auto parser = new VisualTrialReporterParser();
parser.onResult = &checkResult;

parser.add("BEGIN TEST;");
parser.add("END TEST;");

called.should.equal(true);

It should not replace a test result that was already assigned

auto testResult = new TestResult("");

auto parser = new VisualTrialReporterParser();
parser.testResult = testResult;
parser.add("BEGIN TEST;");
parser.testResult.should.equal(testResult);

parser.add("END TEST;");
parser.testResult.should.beNull;

It should raise an event with unparsed lines

bool raised;
auto parser = new VisualTrialReporterParser();

void onOutput(string line) {
  line.should.equal("some output");
  raised = true;
}

parser.onOutput = &onOutput;
parser.add("BEGIN TEST;");
parser.add("some output");

raised.should.equal(true);

Meta