Search in sources :

Example 1 with MethodGlobFilter

use of com.carrotsearch.randomizedtesting.MethodGlobFilter in project randomizedtesting by randomizedtesting.

the class SlaveMain method execute.

/**
   * Execute tests.
   */
private void execute(Iterator<String> classNames) throws Throwable {
    final RunNotifier fNotifier = new OrderedRunNotifier();
    final Result result = new Result();
    final Writer debug = debugMessagesFile == null ? new NullWriter() : new OutputStreamWriter(new FileOutputStream(debugMessagesFile), "UTF-8");
    fNotifier.addListener(result.createListener());
    fNotifier.addListener(new StreamFlusherDecorator(new NoExceptionRunListenerDecorator(new RunListenerEmitter(serializer)) {

        @Override
        protected void exception(Throwable t) {
            warn("Event serializer exception.", t);
        }
    }));
    fNotifier.addListener(new RunListener() {

        public void testRunFinished(Result result) throws Exception {
            debug(debug, "testRunFinished(T:" + result.getRunCount() + ";F:" + result.getFailureCount() + ";I:" + result.getIgnoreCount() + ")");
            serializer.flush();
        }

        @Override
        public void testRunStarted(Description description) throws Exception {
            debug(debug, "testRunStarted(" + description + ")");
            serializer.flush();
        }

        @Override
        public void testStarted(Description description) throws Exception {
            debug(debug, "testStarted(" + description + ")");
            serializer.flush();
        }

        public void testFinished(Description description) throws Exception {
            debug(debug, "testFinished(" + description + ")");
            serializer.flush();
        }

        @Override
        public void testIgnored(Description description) throws Exception {
            debug(debug, "testIgnored(T:" + description + ")");
        }

        @Override
        public void testFailure(Failure failure) throws Exception {
            debug(debug, "testFailure(T:" + failure + ")");
        }

        @Override
        public void testAssumptionFailure(Failure failure) {
            try {
                debug(debug, "testAssumptionFailure(T:" + failure + ")");
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    });
    /*
     * Instantiate method filter if any.
     */
    String methodFilterGlob = Strings.emptyToNull(System.getProperty(SysGlobals.SYSPROP_TESTMETHOD()));
    Filter methodFilter = Filter.ALL;
    if (methodFilterGlob != null) {
        methodFilter = new MethodGlobFilter(methodFilterGlob);
    }
    /*
     * Important. Run each class separately so that we get separate 
     * {@link RunListener} callbacks for the top extracted description.
     */
    debug(debug, "Entering main suite loop.");
    try {
        while (classNames.hasNext()) {
            final String clName = classNames.next();
            debug(debug, "Instantiating: " + clName);
            Class<?> clazz = instantiate(clName);
            if (clazz == null)
                continue;
            Request request = Request.aClass(clazz);
            try {
                Runner runner = request.getRunner();
                methodFilter.apply(runner);
                fNotifier.fireTestRunStarted(runner.getDescription());
                debug(debug, "Runner.run(" + clName + ")");
                runner.run(fNotifier);
                debug(debug, "Runner.done(" + clName + ")");
                fNotifier.fireTestRunFinished(result);
            } catch (NoTestsRemainException e) {
            // Don't complain if all methods have been filtered out. 
            // I don't understand the reason why this exception has been
            // built in to filters at all.
            }
        }
    } catch (Throwable t) {
        debug(debug, "Main suite loop error: " + t);
        throw t;
    } finally {
        debug(debug, "Leaving main suite loop.");
        debug.close();
    }
}
Also used : Runner(org.junit.runner.Runner) Description(org.junit.runner.Description) MethodGlobFilter(com.carrotsearch.randomizedtesting.MethodGlobFilter) NoTestsRemainException(org.junit.runner.manipulation.NoTestsRemainException) Result(org.junit.runner.Result) Failure(org.junit.runner.notification.Failure) RunNotifier(org.junit.runner.notification.RunNotifier) Request(org.junit.runner.Request) IOException(java.io.IOException) IOException(java.io.IOException) NoTestsRemainException(org.junit.runner.manipulation.NoTestsRemainException) RunListener(org.junit.runner.notification.RunListener) MethodGlobFilter(com.carrotsearch.randomizedtesting.MethodGlobFilter) Filter(org.junit.runner.manipulation.Filter) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer)

Aggregations

MethodGlobFilter (com.carrotsearch.randomizedtesting.MethodGlobFilter)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 Description (org.junit.runner.Description)1 Request (org.junit.runner.Request)1 Result (org.junit.runner.Result)1 Runner (org.junit.runner.Runner)1 Filter (org.junit.runner.manipulation.Filter)1 NoTestsRemainException (org.junit.runner.manipulation.NoTestsRemainException)1 Failure (org.junit.runner.notification.Failure)1 RunListener (org.junit.runner.notification.RunListener)1 RunNotifier (org.junit.runner.notification.RunNotifier)1