mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
junit 5: don't search for tests if junit 5 would run the package, leave it to discover what to run
This commit is contained in:
@@ -77,7 +77,6 @@ public class ConfigurationUtil {
|
||||
|
||||
Set<PsiClass> processed = ContainerUtil.newHashSet();
|
||||
boolean hasJunit4 = addAnnotatedMethodsAnSubclasses(manager, scope, testClassFilter, found, processed, JUnitUtil.TEST_ANNOTATION);
|
||||
hasJunit4 |= addAnnotatedMethodsAnSubclasses(manager, scope, testClassFilter, found, processed, JUnitUtil.TEST5_ANNOTATION);
|
||||
hasJunit4 |= addAnnotatedMethodsAnSubclasses(manager, scope, testClassFilter, found, processed, JUnitUtil.RUN_WITH);
|
||||
return hasJunit4;
|
||||
}
|
||||
|
||||
@@ -24,18 +24,16 @@ import com.intellij.execution.runners.ExecutionEnvironment;
|
||||
import com.intellij.execution.testframework.SearchForTestsTask;
|
||||
import com.intellij.execution.testframework.SourceScope;
|
||||
import com.intellij.execution.testframework.TestSearchScope;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ReadAction;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.DumbService;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.search.PackageScope;
|
||||
import com.intellij.refactoring.listeners.RefactoringElementListener;
|
||||
import com.intellij.util.Function;
|
||||
import gnu.trove.THashSet;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
@@ -43,7 +41,6 @@ import org.jetbrains.annotations.TestOnly;
|
||||
import java.io.File;
|
||||
|
||||
public class TestPackage extends TestObject {
|
||||
private boolean myFoundTests = true;
|
||||
|
||||
public TestPackage(JUnitConfiguration configuration, ExecutionEnvironment environment) {
|
||||
super(configuration, environment);
|
||||
@@ -65,15 +62,17 @@ public class TestPackage extends TestObject {
|
||||
@Override
|
||||
protected void search() {
|
||||
myClasses.clear();
|
||||
try {
|
||||
ConfigurationUtil.findAllTestClasses(getClassFilter(data), myClasses);
|
||||
SourceScope sourceScope = getSourceScope();
|
||||
if (sourceScope != null && !ReadAction.compute(() -> JUnitUtil.isJUnit5(sourceScope.getGlobalSearchScope(), myProject))) {
|
||||
try {
|
||||
ConfigurationUtil.findAllTestClasses(getClassFilter(data), myClasses);
|
||||
}
|
||||
catch (CantRunException ignored) {}
|
||||
}
|
||||
catch (CantRunException ignored) {}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFound() {
|
||||
myFoundTests = !myClasses.isEmpty();
|
||||
|
||||
try {
|
||||
addClassesListToJavaParameters(myClasses,
|
||||
@@ -130,16 +129,13 @@ public class TestPackage extends TestObject {
|
||||
|
||||
protected GlobalSearchScope filterScope(final JUnitConfiguration.Data data) throws CantRunException {
|
||||
final Ref<CantRunException> ref = new Ref<>();
|
||||
final GlobalSearchScope aPackage = ApplicationManager.getApplication().runReadAction(new Computable<GlobalSearchScope>() {
|
||||
@Override
|
||||
public GlobalSearchScope compute() {
|
||||
try {
|
||||
return PackageScope.packageScope(getPackage(data), true);
|
||||
}
|
||||
catch (CantRunException e) {
|
||||
ref.set(e);
|
||||
return null;
|
||||
}
|
||||
final GlobalSearchScope aPackage = ReadAction.compute(() -> {
|
||||
try {
|
||||
return PackageScope.packageScope(getPackage(data), true);
|
||||
}
|
||||
catch (CantRunException e) {
|
||||
ref.set(e);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
final CantRunException exception = ref.get();
|
||||
|
||||
@@ -57,7 +57,8 @@ public class JUnit5TestRunnerUtil {
|
||||
selectors.add(createSelector(line));
|
||||
}
|
||||
packageNameRef[0] = packageName.length() == 0 ? "<default package>" : packageName;
|
||||
return builder.selectors(selectors).build();
|
||||
return (selectors.isEmpty() ? builder.selectors(DiscoverySelectors.selectPackage(packageName))
|
||||
: builder.selectors(selectors)).build();
|
||||
}
|
||||
finally {
|
||||
reader.close();
|
||||
|
||||
Reference in New Issue
Block a user