use of org.whole.lang.tests.model.IntLiteral in project whole by wholeplatform.
the class TestsInterpreterVisitor method visit.
@Override
public void visit(TestCase entity) {
String name = entity.getName().getValue();
Results results = TestsEntityFactory.instance.createResults();
printWriter().printf("* %s test case running:\n\n", name);
try {
IEntityIterator<BeforeTestCase> beforeIterator = IteratorFactory.<BeforeTestCase>childMatcherIterator().withPattern(BeforeTestCase);
beforeIterator.reset(entity.getAspects());
for (BeforeTestCase beforeTestCase : beforeIterator) {
beforeTestCase.accept(this);
getResult();
}
Tests tests = entity.getTests();
for (int i = 0; i < tests.wSize(); i++) {
Test test = tests.get(i);
if (getBindings().wIsSet("runSingleTest") && getBindings().wGet("runSingleTest") != test)
continue;
test.accept(this);
IntLiteral result = null;
switch(getResult().wGet(outcome).wEnumValue().getOrdinal()) {
case OutcomeEnum.ERROR_ord:
result = results.getErrors();
break;
case OutcomeEnum.FAILURE_ord:
result = results.getFailures();
break;
case OutcomeEnum.SUCCESS_ord:
result = results.getSuccesses();
break;
default:
throw new WholeIllegalArgumentException("unsupported outcome");
}
result.setValue(result.getValue() + 1);
}
IEntityIterator<AfterTestCase> afterIterator = IteratorFactory.<AfterTestCase>childMatcherIterator().withPattern(AfterTestCase);
afterIterator.reset(entity.getAspects());
for (AfterTestCase afterTestCase : afterIterator) {
afterTestCase.accept(this);
getResult();
}
boolean testCaseSuccess = results.getErrors().getValue() + results.getFailures().getValue() == 0;
printWriter().printf("\n* %s test case %s\n", name, testCaseSuccess ? "OK" : "FAILED");
} catch (OperationCanceledException e) {
throw e;
} catch (RuntimeException e) {
reportError(name, e);
results.getErrors().setValue(entity.getTests().wSize());
results.getFailures().setValue(0);
results.getSuccesses().setValue(0);
}
if (EntityUtils.isResolver(entity.getExpectedResults()))
entity.setExpectedResults(EntityUtils.clone(results));
if (!Matcher.match(results, entity.getActualResults()))
entity.setActualResults(results);
setResult(results);
}
Aggregations