Search in sources :

Example 86 with Runner

use of org.junit.runner.Runner in project ceylon by eclipse.

the class CeylonModuleRunner method makeModuleRunnerInNewJvm.

private void makeModuleRunnerInNewJvm(final ModuleSpecifier module) {
    final Description description = Description.createTestDescription(getClass(), "Run " + module.module() + " in new JVM");
    Runner runner = new Runner() {

        @Override
        public Description getDescription() {
            return description;
        }

        @Override
        public void run(RunNotifier notifier) {
            notifier.fireTestStarted(description);
            try {
                String moduleName = module.module();
                String version = Module.DEFAULT_MODULE_NAME.equals(moduleName) ? null : module.version();
                String runClass = module.runClass();
                if (runClass.isEmpty())
                    runClass = moduleName + ".run_";
                runModuleInNewJvm(moduleName, version, runClass);
            } catch (Exception x) {
                x.printStackTrace();
                notifier.fireTestFailure(new Failure(description, x));
            }
            notifier.fireTestFinished(description);
        }
    };
    children.put(runner, description);
}
Also used : Runner(org.junit.runner.Runner) ParentRunner(org.junit.runners.ParentRunner) Description(org.junit.runner.Description) RunNotifier(org.junit.runner.notification.RunNotifier) URISyntaxException(java.net.URISyntaxException) MalformedURLException(java.net.MalformedURLException) Failure(org.junit.runner.notification.Failure)

Example 87 with Runner

use of org.junit.runner.Runner in project ceylon by eclipse.

the class CeylonModuleRunner method compileAndRun.

private boolean compileAndRun(File srcDir, File resDir, File outRepo, String[] modules, String[] dependencies, String[] options, Set<String> removeAtRuntime, String[] modulesUsingCheckFunction, String[] modulesUsingCheckModule) throws Exception {
    // Compile all the .ceylon files into a .car
    Context context = new Context();
    final ErrorCollector listener = new ErrorCollector();
    // can't create it until Log
    CeyloncFileManager.preRegister(context);
    // has been set up
    CeylonLog.preRegister(context);
    context.put(DiagnosticListener.class, listener);
    org.eclipse.ceylon.compiler.java.launcher.Main compiler = new org.eclipse.ceylon.compiler.java.launcher.Main("ceylonc");
    List<String> args = new ArrayList<>();
    // args.add("-verbose:code");
    args.add("-g");
    args.add("-sysrep");
    args.add("../dist/dist/repo");
    args.add("-src");
    args.add(srcDir.getCanonicalPath());
    args.add("-res");
    args.add(resDir.getCanonicalPath());
    args.add("-out");
    args.add(outRepo.getAbsolutePath());
    for (String option : options) {
        args.add(option);
    }
    for (String module : modules) args.add(module);
    for (String module : dependencies) args.add(module);
    Result result = compiler.compile(args.toArray(new String[args.size()]), context);
    TreeSet<CompilerError> errors = listener.get(Kind.ERROR);
    if (!errors.isEmpty()) {
        List<Runner> errorRunners = new LinkedList<Runner>();
        for (final CompilerError compileError : errors) {
            createFailingTest(errorRunners, compileError.filename, new CompilationException(compileError.toString()));
        }
        for (Runner errorRunner : errorRunners) {
            children.put(errorRunner, errorRunner.getDescription());
        }
        // absolutely no point going on if we have errors
        return false;
    }
    // for invalid options we don't get errors from the listener
    if (!result.isOK()) {
        List<Runner> errorRunners = new LinkedList<Runner>();
        createFailingTest(errorRunners, "Invalid option?", new CompilationException("Invalid option? Check stdout."));
        for (Runner errorRunner : errorRunners) {
            children.put(errorRunner, errorRunner.getDescription());
        }
        // absolutely no point going on if we have errors
        return false;
    }
    // remove what we need for runtime
    for (String module : removeAtRuntime) {
        File moduleFolder = new File(outRepo, module.replace('.', File.separatorChar));
        FileUtil.delete(moduleFolder);
    }
    for (String module : modules) {
        postCompile(context, listener, module, srcDir, dependencies, removeAtRuntime, modulesUsingCheckFunction, modulesUsingCheckModule);
    }
    return true;
}
Also used : ArtifactContext(org.eclipse.ceylon.cmr.api.ArtifactContext) Context(org.eclipse.ceylon.langtools.tools.javac.util.Context) Runner(org.junit.runner.Runner) ParentRunner(org.junit.runners.ParentRunner) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Result(org.eclipse.ceylon.langtools.tools.javac.main.Main.Result) File(java.io.File)

Example 88 with Runner

use of org.junit.runner.Runner in project ceylon by eclipse.

the class CeylonModuleRunner method postCompile.

private void postCompile(Context context, ErrorCollector listener, String moduleName, File srcDir, String[] dependencies, Set<String> removeAtRuntime, String[] modulesUsingCheckFunction, String[] modulesUsingCheckModule) throws Exception {
    // now fetch stuff from the context
    PhasedUnits phasedUnits = LanguageCompiler.getPhasedUnitsInstance(context);
    List<Runner> moduleRunners = new LinkedList<Runner>();
    // Get a class loader for the car
    // XXX Need to use CMR if the module has dependencies
    URL[] carUrls = getCarUrls(moduleName, dependencies, removeAtRuntime, outRepo);
    URLClassLoader cl = classLoaderForModule(carUrls);
    Runnable moduleInitialiser = getModuleInitialiser(moduleName, carUrls, dependencies, removeAtRuntime, cl);
    if (cl != null) {
        loadCompiledTests(moduleRunners, srcDir, cl, phasedUnits, moduleName, modulesUsingCheckFunction, modulesUsingCheckModule);
    }
    CeylonTestGroup ceylonTestGroup = new CeylonTestGroup(moduleRunners, moduleName, moduleInitialiser);
    children.put(ceylonTestGroup, ceylonTestGroup.getDescription());
}
Also used : Runner(org.junit.runner.Runner) ParentRunner(org.junit.runners.ParentRunner) URLClassLoader(java.net.URLClassLoader) PhasedUnits(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnits) LinkedList(java.util.LinkedList) URL(java.net.URL)

Example 89 with Runner

use of org.junit.runner.Runner in project ceylon by eclipse.

the class CeylonModuleRunner method createFailingTest.

void createFailingTest(List<Runner> moduleRunners, final String testName, final Exception ex) {
    final Description description = Description.createTestDescription(getClass(), testName);
    Runner runner = new Runner() {

        @Override
        public Description getDescription() {
            return description;
        }

        @Override
        public void run(RunNotifier notifier) {
            notifier.fireTestStarted(description);
            notifier.fireTestFailure(new Failure(description, ex));
            notifier.fireTestFinished(description);
        }
    };
    moduleRunners.add(runner);
}
Also used : Runner(org.junit.runner.Runner) ParentRunner(org.junit.runners.ParentRunner) Description(org.junit.runner.Description) RunNotifier(org.junit.runner.notification.RunNotifier) Failure(org.junit.runner.notification.Failure)

Example 90 with Runner

use of org.junit.runner.Runner in project android-test by android.

the class AndroidLogOnlyBuilderTest method builderHandlesJUnit3TestSuites.

@Test
public void builderHandlesJUnit3TestSuites() throws Throwable {
    Runner selectedRunner = androidLogOnlyBuilder.runnerForClass(JUnit3FailingTestSuiteWithSuite.class);
    assertThat(selectedRunner).isNotNull();
    runWithRunner(selectedRunner, 1, 0);
}
Also used : Runner(org.junit.runner.Runner) JUnit4ParameterizedTest(androidx.test.testing.fixtures.JUnit4ParameterizedTest) Test(org.junit.Test)

Aggregations

Runner (org.junit.runner.Runner)106 Test (org.junit.Test)39 RunNotifier (org.junit.runner.notification.RunNotifier)22 ArrayList (java.util.ArrayList)18 Description (org.junit.runner.Description)18 JUnitCore (org.junit.runner.JUnitCore)18 ParentRunner (org.junit.runners.ParentRunner)16 Request (org.junit.runner.Request)15 Result (org.junit.runner.Result)13 Filter (org.junit.runner.manipulation.Filter)12 NoTestsRemainException (org.junit.runner.manipulation.NoTestsRemainException)12 InitializationError (org.junit.runners.model.InitializationError)10 Method (java.lang.reflect.Method)9 JUnit4ParameterizedTest (androidx.test.testing.fixtures.JUnit4ParameterizedTest)7 SuiteConfiguration (org.eclipse.reddeer.junit.internal.configuration.SuiteConfiguration)7 Failure (org.junit.runner.notification.Failure)7 ErrorReportingRunner (org.junit.internal.runners.ErrorReportingRunner)6 Filterable (org.junit.runner.manipulation.Filterable)6 BlockJUnit4ClassRunner (org.junit.runners.BlockJUnit4ClassRunner)6 Field (java.lang.reflect.Field)5