mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 03:21:12 +07:00
support module path and options on fork per module/class/ect (IDEA-171419)
GitOrigin-RevId: 5012cf6a8509998a1b13de64f7c415b030403d94
This commit is contained in:
committed by
intellij-monorepo-bot
parent
ed74d06909
commit
ce2dcf2884
@@ -76,6 +76,11 @@ public abstract class JavaTestFrameworkRunnableState<T extends
|
||||
private static final Logger LOG = Logger.getInstance(JavaTestFrameworkRunnableState.class);
|
||||
|
||||
private static final ExtensionPointName<JUnitPatcher> JUNIT_PATCHER_EP = new ExtensionPointName<>("com.intellij.junitPatcher");
|
||||
private static final String JIGSAW_OPTIONS = "Jigsaw Options";
|
||||
|
||||
public static ParamsGroup getJigsawOptions(JavaParameters parameters) {
|
||||
return parameters.getVMParametersList().getParamsGroup(JIGSAW_OPTIONS);
|
||||
}
|
||||
|
||||
protected ServerSocket myServerSocket;
|
||||
protected File myTempFile;
|
||||
@@ -205,7 +210,7 @@ public abstract class JavaTestFrameworkRunnableState<T extends
|
||||
return result;
|
||||
}
|
||||
|
||||
protected abstract void configureRTClasspath(JavaParameters javaParameters) throws CantRunException;
|
||||
protected abstract void configureRTClasspath(JavaParameters javaParameters, Module module) throws CantRunException;
|
||||
|
||||
@Override
|
||||
protected JavaParameters createJavaParameters() throws ExecutionException {
|
||||
@@ -358,7 +363,7 @@ public abstract class JavaTestFrameworkRunnableState<T extends
|
||||
else {
|
||||
JavaParametersUtil.configureProject(getConfiguration().getProject(), javaParameters, pathType, jreHome);
|
||||
}
|
||||
configureRTClasspath(javaParameters);
|
||||
configureRTClasspath(javaParameters, module);
|
||||
}
|
||||
|
||||
protected static PsiJavaModule findJavaModule(Module module, boolean inTests) {
|
||||
@@ -370,7 +375,11 @@ public abstract class JavaTestFrameworkRunnableState<T extends
|
||||
PsiJavaModule testModule = findJavaModule(module, true);
|
||||
if (testModule != null) {
|
||||
//adding the test module explicitly as it is unreachable from `idea.rt`
|
||||
ParametersList vmParametersList = javaParameters.getVMParametersList();
|
||||
ParametersList vmParametersList = javaParameters
|
||||
.getVMParametersList()
|
||||
.addParamsGroup(JIGSAW_OPTIONS)
|
||||
.getParametersList();
|
||||
|
||||
vmParametersList.add("--add-modules");
|
||||
vmParametersList.add(testModule.getName());
|
||||
//setup module path
|
||||
@@ -400,7 +409,9 @@ public abstract class JavaTestFrameworkRunnableState<T extends
|
||||
|
||||
putDependenciesOnModulePath(modulePath, classPath, prodModule);
|
||||
|
||||
ParametersList vmParametersList = javaParameters.getVMParametersList();
|
||||
ParametersList vmParametersList = javaParameters.getVMParametersList()
|
||||
.addParamsGroup(JIGSAW_OPTIONS)
|
||||
.getParametersList();
|
||||
//ensure test output is merged to the production module
|
||||
VirtualFile testOutput = compilerExt.getCompilerOutputPathForTests();
|
||||
if (testOutput != null) {
|
||||
@@ -538,12 +549,28 @@ public abstract class JavaTestFrameworkRunnableState<T extends
|
||||
|
||||
if (classpath == null) {
|
||||
final JavaParameters parameters = new JavaParameters();
|
||||
parameters.getClassPath().add(JavaSdkUtil.getIdeaRtJarPath());
|
||||
try {
|
||||
configureRTClasspath(parameters);
|
||||
JavaParametersUtil.configureModule(module, parameters, JavaParameters.JDK_AND_CLASSES_AND_TESTS,
|
||||
getConfiguration().isAlternativeJrePathEnabled() ? getConfiguration().getAlternativeJrePath() : null);
|
||||
try {
|
||||
JavaParametersUtil.configureModule(module, parameters, JavaParameters.JDK_AND_CLASSES_AND_TESTS,
|
||||
getConfiguration().isAlternativeJrePathEnabled() ? getConfiguration()
|
||||
.getAlternativeJrePath() : null);
|
||||
if (JavaSdkUtil.isJdkAtLeast(parameters.getJdk(), JavaSdkVersion.JDK_1_9)) {
|
||||
configureModulePath(parameters, module);
|
||||
}
|
||||
configureRTClasspath(parameters, module);
|
||||
parameters.getClassPath().add(JavaSdkUtil.getIdeaRtJarPath());
|
||||
wWriter.println(parameters.getClassPath().getPathsString());
|
||||
wWriter.println(parameters.getModulePath().getPathsString());
|
||||
ParamsGroup paramsGroup = getJigsawOptions(parameters);
|
||||
if (paramsGroup == null) {
|
||||
wWriter.println(0);
|
||||
}
|
||||
else {
|
||||
List<String> parametersList = paramsGroup.getParametersList().getList();
|
||||
wWriter.println(parametersList.size());
|
||||
for (String option : parametersList) {
|
||||
wWriter.println(option);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (CantRunException e) {
|
||||
wWriter.println(javaParameters.getClassPath().getPathsString());
|
||||
|
||||
@@ -63,7 +63,7 @@ public abstract class ForkedByModuleSplitter {
|
||||
}
|
||||
|
||||
//read output from wrappers
|
||||
protected int startChildFork(final List args, File workingDir, String classpath, String repeatCount) throws IOException, InterruptedException {
|
||||
protected int startChildFork(final List args, File workingDir, String classpath, List moduleOptions, String repeatCount) throws IOException, InterruptedException {
|
||||
List vmParameters = new ArrayList(myVMParameters);
|
||||
|
||||
myForkedDebuggerHelper.setupDebugger(vmParameters);
|
||||
@@ -89,6 +89,10 @@ public abstract class ForkedByModuleSplitter {
|
||||
builder.add(classpath);
|
||||
}
|
||||
|
||||
if (moduleOptions != null) {
|
||||
builder.add(moduleOptions);
|
||||
}
|
||||
|
||||
builder.add(getStarterName());
|
||||
builder.add(args);
|
||||
if (repeatCount != null) {
|
||||
@@ -136,6 +140,16 @@ public abstract class ForkedByModuleSplitter {
|
||||
while ((workingDir = perDirReader.readLine()) != null) {
|
||||
final String moduleName = perDirReader.readLine();
|
||||
final String classpath = perDirReader.readLine();
|
||||
List moduleOptions = new ArrayList();
|
||||
String modulePath = perDirReader.readLine();
|
||||
if (modulePath != null && modulePath.length() > 0) {
|
||||
moduleOptions.add("-p");
|
||||
moduleOptions.add(modulePath);
|
||||
}
|
||||
final int optionsSize = Integer.parseInt(perDirReader.readLine());
|
||||
for (int i = 0; i < optionsSize; i++) {
|
||||
moduleOptions.add(perDirReader.readLine());
|
||||
}
|
||||
try {
|
||||
|
||||
List classNames = new ArrayList();
|
||||
@@ -151,7 +165,7 @@ public abstract class ForkedByModuleSplitter {
|
||||
}
|
||||
|
||||
String filters = perDirReader.readLine();
|
||||
final int childResult = startPerModuleFork(moduleName, classNames, packageName, workingDir, classpath, repeatCount, result, filters != null ? filters : "");
|
||||
final int childResult = startPerModuleFork(moduleName, classNames, packageName, workingDir, classpath, moduleOptions, repeatCount, result, filters != null ? filters : "");
|
||||
result = Math.min(childResult, result);
|
||||
}
|
||||
catch (Exception e) {
|
||||
@@ -172,8 +186,9 @@ public abstract class ForkedByModuleSplitter {
|
||||
String packageName,
|
||||
String workingDir,
|
||||
String classpath,
|
||||
String repeatCount,
|
||||
int result,
|
||||
List moduleOptions,
|
||||
String repeatCount,
|
||||
int result,
|
||||
String filters) throws Exception;
|
||||
|
||||
protected abstract String getStarterName();
|
||||
|
||||
@@ -40,12 +40,18 @@ public abstract class ForkedSplitter extends ForkedByModuleSplitter {
|
||||
}
|
||||
if (myWorkingDirsPath == null || new File(myWorkingDirsPath).length() == 0) {
|
||||
final String classpath = System.getProperty("java.class.path");
|
||||
final String modulePath = System.getProperty("jdk.module.path");
|
||||
final List moduleOptions = new ArrayList();
|
||||
if (modulePath != null && modulePath.length() > 0) {
|
||||
moduleOptions.add("-p");
|
||||
moduleOptions.add(modulePath);
|
||||
}
|
||||
if (repeatCount != null && RepeatCount.getCount(repeatCount) != 0 && myForkMode.equals("repeat")) {
|
||||
return startChildFork(createChildArgs(myRootDescription), null, classpath, repeatCount);
|
||||
return startChildFork(createChildArgs(myRootDescription), null, classpath, moduleOptions, repeatCount);
|
||||
}
|
||||
final List children = getChildren(myRootDescription);
|
||||
final boolean forkTillMethod = myForkMode.equalsIgnoreCase("method");
|
||||
return splitChildren(children, 0, forkTillMethod, null, classpath, repeatCount);
|
||||
return splitChildren(children, 0, forkTillMethod, null, classpath, moduleOptions, repeatCount);
|
||||
}
|
||||
else {
|
||||
return splitPerModule(repeatCount);
|
||||
@@ -57,12 +63,13 @@ public abstract class ForkedSplitter extends ForkedByModuleSplitter {
|
||||
String packageName,
|
||||
String workingDir,
|
||||
String classpath,
|
||||
String repeatCount,
|
||||
int result,
|
||||
List moduleOptions,
|
||||
String repeatCount,
|
||||
int result,
|
||||
String filters) throws Exception {
|
||||
if (myForkMode.equals("none")) {
|
||||
final List childArgs = createPerModuleArgs(packageName, workingDir, classNames, myRootDescription, filters);
|
||||
return startChildFork(childArgs, new File(workingDir), classpath, repeatCount);
|
||||
return startChildFork(childArgs, new File(workingDir), classpath, moduleOptions, repeatCount);
|
||||
}
|
||||
else {
|
||||
final List children = new ArrayList(getChildren(myRootDescription));
|
||||
@@ -72,7 +79,7 @@ public abstract class ForkedSplitter extends ForkedByModuleSplitter {
|
||||
}
|
||||
}
|
||||
final boolean forkTillMethod = myForkMode.equalsIgnoreCase("method");
|
||||
return splitChildren(children, result, forkTillMethod, new File(workingDir), classpath, repeatCount);
|
||||
return splitChildren(children, result, forkTillMethod, new File(workingDir), classpath, moduleOptions, repeatCount);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,16 +87,18 @@ public abstract class ForkedSplitter extends ForkedByModuleSplitter {
|
||||
int result,
|
||||
boolean forkTillMethod,
|
||||
File workingDir,
|
||||
String classpath, String repeatCount) throws IOException, InterruptedException {
|
||||
String classpath,
|
||||
List moduleOptions,
|
||||
String repeatCount) throws IOException, InterruptedException {
|
||||
for (int i = 0, argsLength = children.size(); i < argsLength; i++) {
|
||||
final Object child = children.get(i);
|
||||
final List childTests = getChildren(child);
|
||||
final int childResult;
|
||||
if (childTests.isEmpty() || !forkTillMethod) {
|
||||
childResult = startChildFork(createChildArgs(child), workingDir, classpath, repeatCount);
|
||||
childResult = startChildFork(createChildArgs(child), workingDir, classpath, moduleOptions, repeatCount);
|
||||
}
|
||||
else {
|
||||
childResult = splitChildren(childTests, result, forkTillMethod, workingDir, classpath, repeatCount);
|
||||
childResult = splitChildren(childTests, result, forkTillMethod, workingDir, classpath, moduleOptions, repeatCount);
|
||||
}
|
||||
result = Math.min(childResult, result);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
package com.intellij.java.execution;
|
||||
|
||||
import com.intellij.codeInsight.TestFrameworks;
|
||||
import com.intellij.execution.JavaTestFrameworkRunnableState;
|
||||
import com.intellij.execution.configurations.JavaParameters;
|
||||
import com.intellij.execution.configurations.ParamsGroup;
|
||||
import com.intellij.execution.junit.JUnitConfiguration;
|
||||
import com.intellij.execution.junit.TestObject;
|
||||
import com.intellij.openapi.application.ex.PathManagerEx;
|
||||
@@ -35,17 +37,18 @@ public class ModulePathTest extends BaseConfigurationTestCase {
|
||||
new JpsMavenRepositoryLibraryDescriptor("org.junit.jupiter", "junit-jupiter-api", "5.3.0");
|
||||
JUnitConfiguration configuration = setupConfiguration(nonModularizedJupiterDescription, "prod1", module);
|
||||
JavaParameters params4Tests = configuration.getTestObject().createJavaParameters4Tests();
|
||||
assertEquals("-ea" +
|
||||
" --patch-module m1=" + CompilerModuleExtension.getInstance(module).getCompilerOutputPathForTests().getPath() +
|
||||
ParamsGroup moduleOptions = JavaTestFrameworkRunnableState.getJigsawOptions(params4Tests);
|
||||
assertNotNull(moduleOptions);
|
||||
assertEquals("--patch-module m1=" + CompilerModuleExtension.getInstance(module).getCompilerOutputPathForTests().getPath() +
|
||||
" --add-reads m1=ALL-UNNAMED" +
|
||||
" --add-modules m1 -Didea.test.cyclic.buffer.size=1048576", params4Tests.getVMParametersList().getParametersString());
|
||||
" --add-modules m1", moduleOptions.getParametersList().getParametersString());
|
||||
|
||||
checkLibrariesOnPathList(module, params4Tests.getClassPath());
|
||||
|
||||
//production module output is on the module path
|
||||
PathsList modulePath = params4Tests.getModulePath();
|
||||
assertTrue("module path: " + modulePath.getPathsString(),
|
||||
modulePath.getPathList().contains(CompilerModuleExtension.getInstance(module).getCompilerOutputPath().getPath()));
|
||||
modulePath.getPathList().contains(getCompilerOutputPath(module)));
|
||||
}
|
||||
|
||||
public void testModuleInfoInProductionModularizedJUnit() throws Exception {
|
||||
@@ -63,22 +66,22 @@ public class ModulePathTest extends BaseConfigurationTestCase {
|
||||
Module module = createEmptyModule();
|
||||
JUnitConfiguration configuration = setupConfiguration(modularizedJupiterDescription, "prod1", module);
|
||||
JavaParameters params4Tests = configuration.getTestObject().createJavaParameters4Tests();
|
||||
assertEquals("-ea" +
|
||||
" --patch-module m1=" + CompilerModuleExtension.getInstance(module).getCompilerOutputPathForTests().getPath() +
|
||||
ParamsGroup moduleOptions = JavaTestFrameworkRunnableState.getJigsawOptions(params4Tests);
|
||||
assertNotNull(moduleOptions);
|
||||
assertEquals("--patch-module m1=" + CompilerModuleExtension.getInstance(module).getCompilerOutputPathForTests().getPath() +
|
||||
" --add-reads m1=ALL-UNNAMED" +
|
||||
" --add-modules m1" +
|
||||
" -Didea.test.cyclic.buffer.size=1048576", params4Tests.getVMParametersList().getParametersString());
|
||||
" --add-modules m1", moduleOptions.getParametersList().getParametersString());
|
||||
|
||||
checkLibrariesOnPathList(module, params4Tests.getClassPath());
|
||||
|
||||
//production module output is on the module path
|
||||
PathsList modulePath = params4Tests.getModulePath();
|
||||
assertTrue("module path: " + modulePath.getPathsString(),
|
||||
modulePath.getPathList().contains(CompilerModuleExtension.getInstance(module).getCompilerOutputPath().getPath()));
|
||||
modulePath.getPathList().contains(getCompilerOutputPath(module)));
|
||||
|
||||
//test output on the classpath
|
||||
assertFalse("module path: " + modulePath.getPathsString(),
|
||||
modulePath.getPathList().contains(CompilerModuleExtension.getInstance(module).getCompilerOutputPathForTests().getPath()));
|
||||
modulePath.getPathList().contains(getCompilerOutputPath(module, true)));
|
||||
}
|
||||
|
||||
private static void checkLibrariesOnPathList(Module module, PathsList classPath) {
|
||||
@@ -87,7 +90,7 @@ public class ModulePathTest extends BaseConfigurationTestCase {
|
||||
.withoutDepModules()
|
||||
.withoutSdk()
|
||||
.recursively().exportedOnly().classes().usingCache().getRoots())
|
||||
.map(f -> JarFileSystem.getInstance().getVirtualFileForJar(f).getPath())
|
||||
.map(f -> PathUtil.getLocalPath(JarFileSystem.getInstance().getVirtualFileForJar(f)))
|
||||
.forEach(path -> assertTrue("path " + path + " is located on the classpath: " + classPath.getPathsString(),
|
||||
classPath.getPathList().contains(path)));
|
||||
}
|
||||
@@ -111,9 +114,9 @@ public class ModulePathTest extends BaseConfigurationTestCase {
|
||||
new JpsMavenRepositoryLibraryDescriptor("org.junit.jupiter", "junit-jupiter-api", "5.3.0");
|
||||
JUnitConfiguration configuration = setupConfiguration(nonModularizedJupiterDescription, "test1", module);
|
||||
JavaParameters params4Tests = configuration.getTestObject().createJavaParameters4Tests();
|
||||
assertEquals("-ea" +
|
||||
" --add-modules m1" +
|
||||
" -Didea.test.cyclic.buffer.size=1048576", params4Tests.getVMParametersList().getParametersString());
|
||||
ParamsGroup moduleOptions = JavaTestFrameworkRunnableState.getJigsawOptions(params4Tests);
|
||||
assertNotNull(moduleOptions);
|
||||
assertEquals("--add-modules m1", moduleOptions.getParametersList().getParametersString());
|
||||
|
||||
PathsList modulePath = params4Tests.getModulePath();
|
||||
|
||||
@@ -121,11 +124,11 @@ public class ModulePathTest extends BaseConfigurationTestCase {
|
||||
|
||||
//production module output is on the module path
|
||||
assertTrue("module path: " + modulePath.getPathsString(),
|
||||
modulePath.getPathList().contains(CompilerModuleExtension.getInstance(module).getCompilerOutputPath().getPath()));
|
||||
modulePath.getPathList().contains(getCompilerOutputPath(module)));
|
||||
//test module output is on the module path
|
||||
modulePath = params4Tests.getModulePath();
|
||||
assertTrue("module path: " + modulePath.getPathsString(),
|
||||
modulePath.getPathList().contains(CompilerModuleExtension.getInstance(module).getCompilerOutputPathForTests().getPath()));
|
||||
modulePath.getPathList().contains(getCompilerOutputPath(module, true)));
|
||||
|
||||
//launcher should be put on the classpath
|
||||
assertTrue(params4Tests.getClassPath().getPathList().stream().anyMatch(filePath -> filePath.contains("launcher")));
|
||||
@@ -137,10 +140,10 @@ public class ModulePathTest extends BaseConfigurationTestCase {
|
||||
new JpsMavenRepositoryLibraryDescriptor("org.junit.jupiter", "junit-jupiter-api", "5.5.2");
|
||||
JUnitConfiguration configuration = setupConfiguration(nonModularizedJupiterDescription, "test1", module);
|
||||
JavaParameters params4Tests = configuration.getTestObject().createJavaParameters4Tests();
|
||||
assertEquals("-ea" +
|
||||
" --add-modules m1" +
|
||||
" --add-modules org.junit.platform.launcher" +
|
||||
" -Didea.test.cyclic.buffer.size=1048576", params4Tests.getVMParametersList().getParametersString());
|
||||
ParamsGroup moduleOptions = JavaTestFrameworkRunnableState.getJigsawOptions(params4Tests);
|
||||
assertNotNull(moduleOptions);
|
||||
assertEquals("--add-modules m1" +
|
||||
" --add-modules org.junit.platform.launcher", moduleOptions.getParametersList().getParametersString());
|
||||
|
||||
checkLibrariesOnPathList(module, params4Tests.getModulePath());
|
||||
|
||||
@@ -152,11 +155,11 @@ public class ModulePathTest extends BaseConfigurationTestCase {
|
||||
//production module output is on the module path
|
||||
PathsList modulePath = params4Tests.getModulePath();
|
||||
assertTrue("module path: " + modulePath.getPathsString(),
|
||||
modulePath.getPathList().contains(CompilerModuleExtension.getInstance(module).getCompilerOutputPath().getPath()));
|
||||
modulePath.getPathList().contains(getCompilerOutputPath(module)));
|
||||
//test module output is on the module path
|
||||
modulePath = params4Tests.getModulePath();
|
||||
assertTrue("module path: " + modulePath.getPathsString(),
|
||||
modulePath.getPathList().contains(CompilerModuleExtension.getInstance(module).getCompilerOutputPathForTests().getPath()));
|
||||
modulePath.getPathList().contains(getCompilerOutputPath(module, true)));
|
||||
}
|
||||
|
||||
private JUnitConfiguration setupConfiguration(JpsMavenRepositoryLibraryDescriptor libraryDescriptor, String sources, Module module) throws Exception {
|
||||
@@ -187,4 +190,14 @@ public class ModulePathTest extends BaseConfigurationTestCase {
|
||||
File.separator + path;
|
||||
return LocalFileSystem.getInstance().findFileByPath(filePath.replace(File.separatorChar, '/'));
|
||||
}
|
||||
|
||||
private static String getCompilerOutputPath(Module module) {
|
||||
return getCompilerOutputPath(module, false);
|
||||
}
|
||||
|
||||
private static String getCompilerOutputPath(Module module, boolean forTests) {
|
||||
CompilerModuleExtension moduleExtension = CompilerModuleExtension.getInstance(module);
|
||||
return PathUtil.getLocalPath(forTests ? moduleExtension.getCompilerOutputPathForTests()
|
||||
: moduleExtension.getCompilerOutputPath());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ package com.intellij.execution.junit;
|
||||
import com.intellij.execution.*;
|
||||
import com.intellij.execution.configurations.JavaParameters;
|
||||
import com.intellij.execution.configurations.ParametersList;
|
||||
import com.intellij.execution.configurations.ParamsGroup;
|
||||
import com.intellij.execution.configurations.RuntimeConfigurationException;
|
||||
import com.intellij.execution.junit.testDiscovery.TestBySource;
|
||||
import com.intellij.execution.junit.testDiscovery.TestsByChanges;
|
||||
@@ -204,7 +205,7 @@ public abstract class TestObject extends JavaTestFrameworkRunnableState<JUnitCon
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configureRTClasspath(JavaParameters javaParameters) throws CantRunException {
|
||||
protected void configureRTClasspath(JavaParameters javaParameters, Module module) throws CantRunException {
|
||||
final String path = System.getProperty(DEBUG_RT_PATH);
|
||||
javaParameters.getClassPath().addFirst(path != null ? path : PathUtil.getJarPathForClass(JUnitStarter.class));
|
||||
|
||||
@@ -214,7 +215,6 @@ public abstract class TestObject extends JavaTestFrameworkRunnableState<JUnitCon
|
||||
String preferredRunner = getRunner();
|
||||
if (JUnitStarter.JUNIT5_PARAMETER.equals(preferredRunner)) {
|
||||
final Project project = getConfiguration().getProject();
|
||||
Module module = getConfiguration().getConfigurationModule().getModule();
|
||||
GlobalSearchScope globalSearchScope = getScopeForJUnit(module, project);
|
||||
appendJUnit5LauncherClasses(javaParameters, project, globalSearchScope, module != null && findJavaModule(module,true) != null);
|
||||
}
|
||||
@@ -293,7 +293,9 @@ public abstract class TestObject extends JavaTestFrameworkRunnableState<JUnitCon
|
||||
VersionComparatorUtil.compare(launcherVersion, "1.5.0") >= 0;
|
||||
|
||||
if (isModularized) { //for modularized junit ensure launcher is included in the module graph
|
||||
ParametersList vmParametersList = javaParameters.getVMParametersList();
|
||||
ParamsGroup group = getJigsawOptions(javaParameters);
|
||||
LOG.assertTrue(group != null);
|
||||
ParametersList vmParametersList = group.getParametersList();
|
||||
String launcherModuleName = "org.junit.platform.launcher";
|
||||
if (!vmParametersList.hasParameter(launcherModuleName)) {
|
||||
vmParametersList.add("--add-modules");
|
||||
|
||||
@@ -68,6 +68,8 @@ public class JUnitClasspathTest extends JavaCodeInsightFixtureTestCase {
|
||||
"MODULE_1\n" + //working dir
|
||||
"mod1\n" + //module name
|
||||
"CLASSPATH\n" +
|
||||
"\n" + //module path
|
||||
"0\n" +
|
||||
"1\n" + //number of classes
|
||||
"p.T1\n" + //list of classes
|
||||
"\n" + //empty filters
|
||||
@@ -75,6 +77,8 @@ public class JUnitClasspathTest extends JavaCodeInsightFixtureTestCase {
|
||||
"MODULE_2\n" + //working dir
|
||||
"mod2\n" + //module name
|
||||
"CLASSPATH\n" +
|
||||
"\n" + //module path
|
||||
"0\n" +
|
||||
"1\n" + //number of classes
|
||||
"p.T2", //class names
|
||||
file);
|
||||
@@ -129,7 +133,7 @@ public class JUnitClasspathTest extends JavaCodeInsightFixtureTestCase {
|
||||
fileContent = StringUtil.convertLineSeparators(fileContent);
|
||||
final String[] lines = fileContent.split("\n");
|
||||
lines[3] = "CLASSPATH";
|
||||
lines[9] = "CLASSPATH";
|
||||
lines[11] = "CLASSPATH";
|
||||
return StringUtil.join(lines, "\n");
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
// 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.
|
||||
package com.intellij.junit4;
|
||||
|
||||
import com.intellij.execution.ExecutionException;
|
||||
import com.intellij.execution.configurations.RunConfiguration;
|
||||
import com.intellij.execution.junit.JUnitConfiguration;
|
||||
import com.intellij.execution.testframework.TestSearchScope;
|
||||
import com.intellij.java.execution.AbstractTestFrameworkCompilingIntegrationTest;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.projectRoots.impl.JavaAwareProjectJdkTableImpl;
|
||||
import com.intellij.openapi.roots.ContentEntry;
|
||||
import com.intellij.openapi.roots.LanguageLevelModuleExtension;
|
||||
import com.intellij.openapi.roots.ModuleRootModificationUtil;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.JavaPsiFacade;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiPackage;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import jetbrains.buildServer.messages.serviceMessages.TestStarted;
|
||||
import org.jetbrains.idea.maven.aether.ArtifactRepositoryManager;
|
||||
import org.jetbrains.jps.model.library.JpsMavenRepositoryLibraryDescriptor;
|
||||
|
||||
//RUN ON JAVA 11 ONLY
|
||||
public class JUnitForkWithModuleInfoIntegrationTest extends AbstractTestFrameworkCompilingIntegrationTest {
|
||||
|
||||
@Override
|
||||
protected String getTestContentRoot() {
|
||||
return VfsUtilCore.pathToUrl(PlatformTestUtil.getCommunityPath() + "/plugins/junit5_rt_tests/testData/integration/forkProjectWithModuleInfo");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setupModule() throws Exception {
|
||||
super.setupModule();
|
||||
|
||||
final ArtifactRepositoryManager repoManager = getRepoManager();
|
||||
Module module2 = createEmptyModule();
|
||||
|
||||
ModuleRootModificationUtil.setModuleSdk(module2, JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk());
|
||||
ModuleRootModificationUtil.updateModel(module2, model -> {
|
||||
String contentUrl = getTestContentRoot() + "/module2";
|
||||
ContentEntry contentEntry = model.addContentEntry(contentUrl);
|
||||
contentEntry.addSourceFolder(contentUrl + "/test", true);
|
||||
//add dependency between modules
|
||||
if (getTestName(false).endsWith("WithDependency")) {
|
||||
model.addModuleOrderEntry(myModule);
|
||||
}
|
||||
model.getModuleExtension(LanguageLevelModuleExtension.class).setLanguageLevel(LanguageLevel.JDK_11);
|
||||
});
|
||||
|
||||
ModuleRootModificationUtil.updateModel(myModule, model -> {
|
||||
model.getModuleExtension(LanguageLevelModuleExtension.class).setLanguageLevel(LanguageLevel.JDK_11);
|
||||
});
|
||||
|
||||
JpsMavenRepositoryLibraryDescriptor junit5Lib =
|
||||
new JpsMavenRepositoryLibraryDescriptor("org.junit.jupiter", "junit-jupiter-api", "5.5.2");
|
||||
addMavenLibs(myModule, junit5Lib, repoManager);
|
||||
addMavenLibs(module2, junit5Lib, repoManager);
|
||||
}
|
||||
|
||||
public void testForkPerModuleForModuleInfoInTestRoot() throws ExecutionException {
|
||||
PsiPackage aPackage = JavaPsiFacade.getInstance(myProject).findPackage("p");
|
||||
assertNotNull(aPackage);
|
||||
RunConfiguration runConfiguration = createConfiguration(aPackage);
|
||||
assertInstanceOf(runConfiguration, JUnitConfiguration.class);
|
||||
final JUnitConfiguration configuration = (JUnitConfiguration)runConfiguration;
|
||||
configuration.setWorkingDirectory("$MODULE_WORKING_DIR$");
|
||||
configuration.setSearchScope(TestSearchScope.WHOLE_PROJECT);
|
||||
|
||||
ProcessOutput processOutput = doStartTestsProcess(configuration);
|
||||
|
||||
assertTrue(processOutput.sys.toString().contains("-junit5"));
|
||||
assertEmpty(processOutput.out);
|
||||
assertSize(3, ContainerUtil.filter(processOutput.messages, TestStarted.class::isInstance));
|
||||
}
|
||||
|
||||
public void testForkPerMethodForModuleInfoInTestRoot() throws ExecutionException {
|
||||
PsiClass aClass = JavaPsiFacade.getInstance(myProject).findClass("p.MyTest1",
|
||||
GlobalSearchScope.projectScope(getProject()));
|
||||
assertNotNull(aClass);
|
||||
RunConfiguration runConfiguration = createConfiguration(aClass);
|
||||
assertInstanceOf(runConfiguration, JUnitConfiguration.class);
|
||||
final JUnitConfiguration configuration = (JUnitConfiguration)runConfiguration;
|
||||
configuration.setForkMode(JUnitConfiguration.FORK_METHOD);
|
||||
|
||||
ProcessOutput processOutput = doStartTestsProcess(configuration);
|
||||
|
||||
assertTrue(processOutput.sys.toString().contains("-junit5"));
|
||||
assertEmpty(processOutput.out);
|
||||
assertSize(2, ContainerUtil.filter(processOutput.messages, TestStarted.class::isInstance));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
open module a {
|
||||
requires org.junit.jupiter.api;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package p;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class MyTest1 {
|
||||
@Test
|
||||
void emptyTest1() { }
|
||||
|
||||
@Test
|
||||
void emptyTest2() { }
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
open module b {
|
||||
requires org.junit.jupiter.api;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package p;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class MyTest2 {
|
||||
@Test
|
||||
void emptyTest5() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -88,7 +88,7 @@ public class TestNGRunnableState extends JavaTestFrameworkRunnableState<TestNGCo
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configureRTClasspath(JavaParameters javaParameters) {
|
||||
protected void configureRTClasspath(JavaParameters javaParameters, Module module) {
|
||||
javaParameters.getClassPath().addFirst(PathUtil.getJarPathForClass(RemoteTestNGStarter.class));
|
||||
javaParameters.getClassPath().addTail(PathUtil.getJarPathForClass(JCommander.class));
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@@ -21,10 +22,14 @@ public class TestNGForkTest {
|
||||
final File tempFile = FileUtil.createTempFile(tempDirectory, "workingDir", null);
|
||||
final String workingDirFromFile = "MODULE_1";
|
||||
final String classpathFromFile = "CLASSPATH";
|
||||
final String modulePathFromFile = "MODULE_PATH";
|
||||
List<String> moduleExpectedOptions = Arrays.asList("-p", modulePathFromFile);
|
||||
FileUtil.writeToFile(tempFile, "p\n" +
|
||||
workingDirFromFile + "\n" +
|
||||
"mod1\n" +
|
||||
classpathFromFile + "\n" +
|
||||
modulePathFromFile + "\n" +
|
||||
"0\n" +
|
||||
"1\n" +
|
||||
"p.T1\n");
|
||||
final File commandLineFile = FileUtil.createTempFile(tempDirectory, "commandline", null);
|
||||
@@ -34,12 +39,13 @@ public class TestNGForkTest {
|
||||
new TestNGForkedSplitter(tempFile.getCanonicalPath(), Collections.singletonList(tempFile.getCanonicalPath())) {
|
||||
private boolean myStarted = false;
|
||||
@Override
|
||||
protected int startChildFork(List args, File workingDir, String classpath, String repeatCount) throws IOException {
|
||||
protected int startChildFork(List args, File workingDir, String classpath, List moduleOptions, String repeatCount) throws IOException {
|
||||
Assert.assertEquals(dynamicClasspath, myDynamicClasspath);
|
||||
Assert.assertArrayEquals(vmParams, myVMParameters.toArray());
|
||||
Assert.assertEquals(workingDirFromFile, workingDir.getName());
|
||||
Assert.assertEquals(classpathFromFile, classpath);
|
||||
Assert.assertTrue(args.size() == 1);
|
||||
Assert.assertEquals(moduleExpectedOptions, moduleOptions);
|
||||
Assert.assertEquals(1, args.size());
|
||||
final String generatedSuite = FileUtil.loadFile(new File((String)args.get(0)));
|
||||
Assert.assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
|
||||
"<!DOCTYPE suite SYSTEM \"http://testng.org/testng-1.0.dtd\">\n" +
|
||||
|
||||
@@ -33,6 +33,7 @@ public class TestNGForkedSplitter extends ForkedByModuleSplitter {
|
||||
String packageName,
|
||||
String workingDir,
|
||||
String classpath,
|
||||
List moduleOptions,
|
||||
String repeatCount, int result, final String filters) throws Exception {
|
||||
final LinkedHashMap<String, Map<String, List<String>>> classes = new LinkedHashMap<String, Map<String, List<String>>>();
|
||||
for (Object className : classNames) {
|
||||
@@ -48,7 +49,9 @@ public class TestNGForkedSplitter extends ForkedByModuleSplitter {
|
||||
TestNGXmlSuiteHelper.writeSuite(classes, new LinkedHashMap<String, String>(), moduleName, rootPath, TestNGXmlSuiteHelper.Logger.DEAF);
|
||||
file.deleteOnExit();
|
||||
|
||||
return Math.min(result, startChildFork(Collections.singletonList(file.getAbsolutePath()), new File(workingDir), classpath, repeatCount));
|
||||
return Math.min(result, startChildFork(Collections.singletonList(file.getAbsolutePath()), new File(workingDir), classpath,
|
||||
moduleOptions,
|
||||
repeatCount));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user