package nz.ac.auckland.morc;

import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.joran.JoranConfigurator;
import ch.qos.logback.core.joran.spi.JoranException;
import org.junit.internal.TextListener;
import org.junit.runner.JUnitCore;
import org.slf4j.LoggerFactory;

/**
 * A convenience class that helps to quickly instantiate test cases using a scripting tool like Groovy.
 * I realize this breaks Java naming convention, but it fits the name used elsewhere better.
 *
 * @author David MacDonald <d.macdonald@auckland.ac.nz>
 */
public class morc {

    /**
     * A method that will run the builder as a suite of JUnit tests
     *
     * @param builder A set of test specifications that need to be built
     */
    public static void run(MorcTestBuilder builder) {

        JoranConfigurator configurator = new JoranConfigurator();
        LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
        try {
            configurator.setContext(context);
            context.reset();
            configurator.doConfigure(MorcTestBuilder.classpath("/logback-morc.xml"));
        } catch (JoranException e) {
            throw new RuntimeException(e);
        }

        JUnitCore core = new JUnitCore();
        core.addListener(new TextListener(System.out));
        try {
            core.run(new MorcParameterized(builder));
        } catch (Throwable t) {
            throw new RuntimeException(t);
        }
    }
}

@@ -251,16 +251,48 @@
 itCore;%0A
+import org.junit.runner.Result;%0A
 import o
@@ -706,16 +706,18 @@
 builder 
+  
 A set of
@@ -759,16 +759,67 @@
 e built%0A
+     * @return          The number of failed tests%0A
      */%0A
@@ -840,12 +840,11 @@
 tic 
-void
+int
  run
@@ -1406,24 +1406,35 @@
 %0A           
+ Result r =
  core.run(ne
@@ -1460,24 +1460,64 @@
 (builder));%0A
+            return r.getFailureCount();%0A
         %7D ca

return failure count for #25 to enable monitoring with scripts