Class VisualTrialReporterParser

Parse the output from the visual trial reporter

class VisualTrialReporterParser ;

Methods

NameDescription
add add a line to the parser

Example

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;

Example

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;

Example

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);

Example

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;

Example

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);