Search in sources :

Example 1 with SearchForTestsTask

use of com.intellij.execution.testframework.SearchForTestsTask in project intellij-community by JetBrains.

the class TestPackage method createSearchingForTestsTask.

@Override
public SearchForTestsTask createSearchingForTestsTask() {
    final JUnitConfiguration.Data data = getConfiguration().getPersistentData();
    return new SearchForTestsTask(getConfiguration().getProject(), myServerSocket) {

        private final THashSet<PsiClass> myClasses = new THashSet<>();

        @Override
        protected void search() {
            myClasses.clear();
            final SourceScope sourceScope = getSourceScope();
            final Module module = getConfiguration().getConfigurationModule().getModule();
            if (sourceScope != null && !ReadAction.compute(() -> isJUnit5(module, sourceScope, myProject))) {
                try {
                    final TestClassFilter classFilter = getClassFilter(data);
                    LOG.assertTrue(classFilter.getBase() != null);
                    ConfigurationUtil.findAllTestClasses(classFilter, module, myClasses);
                } catch (CantRunException ignored) {
                }
            }
        }

        @Override
        protected void onFound() {
            try {
                addClassesListToJavaParameters(myClasses, psiClass -> psiClass != null ? JavaExecutionUtil.getRuntimeQualifiedName(psiClass) : null, getPackageName(data), createTempFiles(), getJavaParameters());
            } catch (ExecutionException ignored) {
            }
        }
    };
}
Also used : SourceScope(com.intellij.execution.testframework.SourceScope) SearchForTestsTask(com.intellij.execution.testframework.SearchForTestsTask) Module(com.intellij.openapi.module.Module) THashSet(gnu.trove.THashSet)

Example 2 with SearchForTestsTask

use of com.intellij.execution.testframework.SearchForTestsTask in project intellij-community by JetBrains.

the class TestsPattern method createSearchingForTestsTask.

@Override
public SearchForTestsTask createSearchingForTestsTask() {
    final JUnitConfiguration.Data data = getConfiguration().getPersistentData();
    final Project project = getConfiguration().getProject();
    final Set<String> classNames = new LinkedHashSet<>();
    for (String className : data.getPatterns()) {
        final PsiClass psiClass = getTestClass(project, className);
        if (psiClass != null && JUnitUtil.isTestClass(psiClass)) {
            classNames.add(className);
        }
    }
    if (classNames.size() == data.getPatterns().size()) {
        return new SearchForTestsTask(project, myServerSocket) {

            @Override
            protected void search() throws ExecutionException {
                final Function<String, String> nameFunction = StringUtil.isEmpty(data.METHOD_NAME) ? FunctionUtil.<String>id() : (Function<String, String>) className -> className;
                addClassesListToJavaParameters(classNames, nameFunction, "", false, getJavaParameters());
            }

            @Override
            protected void onFound() {
            }
        };
    }
    return super.createSearchingForTestsTask();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) RuntimeConfigurationException(com.intellij.execution.configurations.RuntimeConfigurationException) ExecutionException(com.intellij.execution.ExecutionException) StringUtil(com.intellij.openapi.util.text.StringUtil) RefactoringElementListener(com.intellij.refactoring.listeners.RefactoringElementListener) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Set(java.util.Set) JavaExecutionUtil(com.intellij.execution.JavaExecutionUtil) Nullable(org.jetbrains.annotations.Nullable) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) RefactoringElementListenerComposite(com.intellij.refactoring.listeners.RefactoringElementListenerComposite) Function(com.intellij.util.Function) SearchForTestsTask(com.intellij.execution.testframework.SearchForTestsTask) Project(com.intellij.openapi.project.Project) com.intellij.psi(com.intellij.psi) FunctionUtil(com.intellij.util.FunctionUtil) CantRunException(com.intellij.execution.CantRunException) RuntimeConfigurationWarning(com.intellij.execution.configurations.RuntimeConfigurationWarning) Module(com.intellij.openapi.module.Module) LinkedHashSet(java.util.LinkedHashSet) Project(com.intellij.openapi.project.Project) SearchForTestsTask(com.intellij.execution.testframework.SearchForTestsTask)

Example 3 with SearchForTestsTask

use of com.intellij.execution.testframework.SearchForTestsTask in project intellij-community by JetBrains.

the class TestObject method createHandler.

@NotNull
protected OSProcessHandler createHandler(Executor executor) throws ExecutionException {
    appendForkInfo(executor);
    final String repeatMode = getConfiguration().getRepeatMode();
    if (!RepeatCount.ONCE.equals(repeatMode)) {
        final int repeatCount = getConfiguration().getRepeatCount();
        final String countString = RepeatCount.N.equals(repeatMode) && repeatCount > 0 ? RepeatCount.getCountString(repeatCount) : repeatMode;
        getJavaParameters().getProgramParametersList().add(countString);
    }
    final OSProcessHandler processHandler = new KillableColoredProcessHandler(createCommandLine());
    ProcessTerminatedListener.attach(processHandler);
    final SearchForTestsTask searchForTestsTask = createSearchingForTestsTask();
    if (searchForTestsTask != null) {
        searchForTestsTask.attachTaskToProcess(processHandler);
    }
    return processHandler;
}
Also used : OSProcessHandler(com.intellij.execution.process.OSProcessHandler) SearchForTestsTask(com.intellij.execution.testframework.SearchForTestsTask) KillableColoredProcessHandler(com.intellij.execution.process.KillableColoredProcessHandler) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with SearchForTestsTask

use of com.intellij.execution.testframework.SearchForTestsTask in project intellij-community by JetBrains.

the class ConfigurationsTest method checkCanRun.

private static JavaParameters checkCanRun(RunConfiguration configuration) throws ExecutionException {
    final RunProfileState state;
    state = ExecutionEnvironmentBuilder.create(DefaultRunExecutor.getRunExecutorInstance(), configuration).build().getState();
    assertNotNull(state);
    assertTrue(state instanceof JavaCommandLine);
    if (state instanceof TestPackage) {
        @SuppressWarnings("UnusedDeclaration") final JavaParameters parameters = ((TestPackage) state).getJavaParameters();
        final SearchForTestsTask task = ((TestPackage) state).createSearchingForTestsTask();
        assertNotNull(task);
        task.startSearch();
    }
    try {
        configuration.checkConfiguration();
    } catch (RuntimeConfigurationError e) {
        fail("cannot run: " + e.getMessage());
    } catch (RuntimeConfigurationException e) {
    //ignore
    }
    return ((JavaCommandLine) state).getJavaParameters();
}
Also used : SearchForTestsTask(com.intellij.execution.testframework.SearchForTestsTask)

Aggregations

SearchForTestsTask (com.intellij.execution.testframework.SearchForTestsTask)4 Module (com.intellij.openapi.module.Module)2 CantRunException (com.intellij.execution.CantRunException)1 ExecutionException (com.intellij.execution.ExecutionException)1 JavaExecutionUtil (com.intellij.execution.JavaExecutionUtil)1 RuntimeConfigurationException (com.intellij.execution.configurations.RuntimeConfigurationException)1 RuntimeConfigurationWarning (com.intellij.execution.configurations.RuntimeConfigurationWarning)1 KillableColoredProcessHandler (com.intellij.execution.process.KillableColoredProcessHandler)1 OSProcessHandler (com.intellij.execution.process.OSProcessHandler)1 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)1 SourceScope (com.intellij.execution.testframework.SourceScope)1 Project (com.intellij.openapi.project.Project)1 StringUtil (com.intellij.openapi.util.text.StringUtil)1 com.intellij.psi (com.intellij.psi)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 RefactoringElementListener (com.intellij.refactoring.listeners.RefactoringElementListener)1 RefactoringElementListenerComposite (com.intellij.refactoring.listeners.RefactoringElementListenerComposite)1 Function (com.intellij.util.Function)1 FunctionUtil (com.intellij.util.FunctionUtil)1 THashSet (gnu.trove.THashSet)1