package jetbrains.mps.baseLanguage.unitTest.execution.server; /*Generated by MPS */ import org.junit.runner.notification.RunListener; import org.junit.runner.Description; import org.junit.runner.notification.Failure; public class DefaultRunListener extends RunListener { private final CommandOutputStream myOutput; private int myFailureCount = 0; public DefaultRunListener(CommandOutputStream out) { myOutput = out; } @Override public void testFinished(Description description) throws Exception { this.printSyncToken(("<FINISH_TEST>"), description); } @Override public void testFailure(Failure failure) throws Exception { this.printSyncToken(("<TEST_FAILURE_BEGIN>"), failure.getDescription()); failure.getException().printStackTrace(System.err); this.printSyncToken(("<TEST_FAILURE_END>"), failure.getDescription()); ++myFailureCount; } @Override public void testAssumptionFailure(Failure failure) { this.printSyncToken(("<TEST_ASSUMPTION_FAILURE_BEGIN>"), failure.getDescription()); failure.getException().printStackTrace(System.err); this.printSyncToken(("<TEST_ASSUMPTION_FAILURE_END>"), failure.getDescription()); } @Override public void testIgnored(Description description) { this.printSyncToken(("<TEST_IGNORE_BEGIN>"), description); System.err.println(description + " ignored"); this.printSyncToken(("<TEST_IGNORE_END>"), description); } @Override public void testStarted(Description description) throws Exception { printSyncToken(("<START_TEST>"), description); } private void printSyncToken(String tokenPrefix, Description description) { StringBuilder builder = new StringBuilder(); builder.append(tokenPrefix); builder.append(description.getTestClass().getName()); if (description.getMethodName() != null) { builder.append(':').append(description.getMethodName()); } Runtime runtime = Runtime.getRuntime(); builder.append(":memory=").append(runtime.totalMemory() - runtime.freeMemory()); builder.append(":time=").append(System.currentTimeMillis()); synchronized (this.myOutput) { this.myOutput.writeCommand(builder.toString()); myOutput.flushSafe(); } } public int getFailureCount() { return myFailureCount; } }