mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 22:51:17 +07:00
[junit] explicitly add filter on package name (IDEA-276463)
this way non-JVM engines won't need to filter by class name, when package name is enough avoid filtering by class names when package name can be used instead = keep filters for pattern configurations only GitOrigin-RevId: 25e9a87cbb39c6d50e4bcfa3d8cb7956b90b4110
This commit is contained in:
committed by
intellij-monorepo-bot
parent
e285a471d8
commit
ce78107b99
@@ -0,0 +1,6 @@
|
||||
package tests1;
|
||||
|
||||
class MyTest5 {
|
||||
@org.junit.jupiter.api.Test
|
||||
void method() { }
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.java.execution;
|
||||
|
||||
import com.intellij.execution.Location;
|
||||
@@ -67,6 +67,12 @@ public abstract class BaseConfigurationTestCase extends JavaProjectTestCase {
|
||||
}
|
||||
|
||||
protected void createModule(VirtualFile module1Content, boolean addSource) {
|
||||
createModule(module1Content, addSource, "JUnit4");
|
||||
}
|
||||
|
||||
protected void createModule(VirtualFile module1Content,
|
||||
boolean addSource,
|
||||
String junitLibName) {
|
||||
Module module = createEmptyModule();
|
||||
if (addSource) {
|
||||
PsiTestUtil.addSourceRoot(module, module1Content, true);
|
||||
@@ -75,11 +81,13 @@ public abstract class BaseConfigurationTestCase extends JavaProjectTestCase {
|
||||
PsiTestUtil.addContentRoot(module, module1Content);
|
||||
}
|
||||
|
||||
IntelliJProjectConfiguration.LibraryRoots junit4Library = IntelliJProjectConfiguration.getProjectLibrary("JUnit4");
|
||||
ModuleRootModificationUtil.addModuleLibrary(module, "JUnit4", junit4Library.getClassesUrls(), junit4Library.getSourcesUrls());
|
||||
IntelliJProjectConfiguration.LibraryRoots junit4Library = IntelliJProjectConfiguration.getProjectLibrary(junitLibName);
|
||||
ModuleRootModificationUtil.addModuleLibrary(module, junitLibName, junit4Library.getClassesUrls(), junit4Library.getSourcesUrls());
|
||||
ModuleRootModificationUtil.setModuleSdk(module, ModuleRootManager.getInstance(myModule).getSdk());
|
||||
GlobalSearchScope scope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module);
|
||||
if ("JUnit4".equals(junitLibName)) {
|
||||
assertNotNull(JavaPsiFacade.getInstance(getProject()).findClass(JUnitUtil.TEST_CASE_CLASS, scope));
|
||||
}
|
||||
Module missingModule = createTempModule();
|
||||
addDependency(module, missingModule);
|
||||
ModuleManager.getInstance(myProject).disposeModule(missingModule);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.java.execution;
|
||||
|
||||
import com.intellij.application.options.ModuleDescriptionsComboBox;
|
||||
@@ -158,6 +158,23 @@ public class ConfigurationsTest extends BaseConfigurationTestCase {
|
||||
assertEquals(myJdk.getHomeDirectory().getPresentableUrl(), parameters.getJdkPath());
|
||||
}
|
||||
|
||||
|
||||
public void testRunAllInPackageJUnit5() throws ExecutionException, IOException {
|
||||
|
||||
VirtualFile module1Content = findFile("module7");
|
||||
createModule(module1Content, true, "JUnit5");
|
||||
Module module = getModule(3);
|
||||
PsiPackage psiPackage = JavaPsiFacade.getInstance(myProject).findPackage("tests1");
|
||||
JUnitConfiguration configuration = createConfiguration(psiPackage, module);
|
||||
configuration.setSearchScope(TestSearchScope.SINGLE_MODULE);
|
||||
JavaParameters parameters = checkCanRun(configuration);
|
||||
List<String> lines = extractAllInPackageTests(parameters, psiPackage);
|
||||
assertEquals(Arrays.asList("", //category
|
||||
"" //filters
|
||||
),
|
||||
lines);
|
||||
}
|
||||
|
||||
public void testRunningAllInPackage() throws IOException, ExecutionException {
|
||||
Module module1 = getModule1();
|
||||
GlobalSearchScope module1AndLibraries = GlobalSearchScope.moduleWithLibrariesScope(module1);
|
||||
|
||||
@@ -159,7 +159,7 @@ public class TestPackage extends TestObject {
|
||||
}
|
||||
|
||||
protected @NlsSafe String getFilters(Set<Location<?>> foundClasses, @NlsSafe String packageName) {
|
||||
return foundClasses.isEmpty() ? packageName.isEmpty() ? ".*" : packageName + "\\..*" : "";
|
||||
return "";
|
||||
}
|
||||
|
||||
protected void searchTests5(Module module, Set<Location<?>> classes) throws CantRunException { }
|
||||
|
||||
@@ -1,18 +1,4 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.junit5;
|
||||
|
||||
import org.junit.platform.commons.util.AnnotationUtils;
|
||||
@@ -20,6 +6,7 @@ import org.junit.platform.engine.DiscoverySelector;
|
||||
import org.junit.platform.engine.discovery.ClassNameFilter;
|
||||
import org.junit.platform.engine.discovery.ClasspathRootSelector;
|
||||
import org.junit.platform.engine.discovery.DiscoverySelectors;
|
||||
import org.junit.platform.engine.discovery.PackageNameFilter;
|
||||
import org.junit.platform.launcher.LauncherDiscoveryRequest;
|
||||
import org.junit.platform.launcher.TagFilter;
|
||||
import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder;
|
||||
@@ -93,6 +80,9 @@ public class JUnit5TestRunnerUtil {
|
||||
}
|
||||
else {
|
||||
builder = builder.selectors(selectors);
|
||||
if (!packageName.isEmpty()) {
|
||||
builder = builder.filters(PackageNameFilter.includePackageNames(packageName));
|
||||
}
|
||||
}
|
||||
if (filters != null && !filters.isEmpty()) {
|
||||
String[] classNames = filters.split("\\|\\|");
|
||||
|
||||
Reference in New Issue
Block a user