Debugger tests: migrate to new API
(cherry picked from commit 430c718)
This commit is contained in:
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.idea.debugger;
|
|||||||
|
|
||||||
import com.intellij.debugger.impl.DescriptorTestCase;
|
import com.intellij.debugger.impl.DescriptorTestCase;
|
||||||
import com.intellij.debugger.impl.OutputChecker;
|
import com.intellij.debugger.impl.OutputChecker;
|
||||||
|
import com.intellij.execution.configurations.JavaParameters;
|
||||||
import com.intellij.openapi.application.ApplicationManager;
|
import com.intellij.openapi.application.ApplicationManager;
|
||||||
import com.intellij.openapi.projectRoots.Sdk;
|
import com.intellij.openapi.projectRoots.Sdk;
|
||||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||||
@@ -28,24 +29,26 @@ import com.intellij.openapi.util.Computable;
|
|||||||
import com.intellij.openapi.vfs.VfsUtil;
|
import com.intellij.openapi.vfs.VfsUtil;
|
||||||
import com.intellij.openapi.vfs.VirtualFile;
|
import com.intellij.openapi.vfs.VirtualFile;
|
||||||
import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess;
|
import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess;
|
||||||
|
import com.intellij.pom.java.LanguageLevel;
|
||||||
import com.intellij.psi.JavaPsiFacade;
|
import com.intellij.psi.JavaPsiFacade;
|
||||||
import com.intellij.psi.PsiClass;
|
import com.intellij.psi.PsiClass;
|
||||||
import com.intellij.psi.search.GlobalSearchScope;
|
import com.intellij.psi.search.GlobalSearchScope;
|
||||||
import com.intellij.testFramework.UsefulTestCase;
|
import com.intellij.testFramework.IdeaTestUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.kotlin.asJava.FakeLightClassForFileOfPackage;
|
import org.jetbrains.kotlin.asJava.FakeLightClassForFileOfPackage;
|
||||||
import org.jetbrains.kotlin.asJava.KotlinLightClassForPackage;
|
import org.jetbrains.kotlin.asJava.KotlinLightClassForPackage;
|
||||||
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime;
|
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime;
|
||||||
|
import org.jetbrains.kotlin.idea.test.ConfigLibraryUtil;
|
||||||
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase;
|
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase;
|
||||||
import org.jetbrains.kotlin.idea.test.ProjectDescriptorWithStdlibSources;
|
import org.jetbrains.kotlin.idea.test.ProjectDescriptorWithStdlibSources;
|
||||||
import org.jetbrains.kotlin.load.kotlin.PackageClassUtils;
|
import org.jetbrains.kotlin.load.kotlin.PackageClassUtils;
|
||||||
import org.jetbrains.kotlin.name.FqName;
|
import org.jetbrains.kotlin.name.FqName;
|
||||||
import org.jetbrains.kotlin.psi.JetFile;
|
import org.jetbrains.kotlin.psi.JetFile;
|
||||||
import org.jetbrains.kotlin.idea.test.ConfigLibraryUtil;
|
|
||||||
import org.jetbrains.kotlin.test.JetTestUtils;
|
import org.jetbrains.kotlin.test.JetTestUtils;
|
||||||
import org.jetbrains.kotlin.test.MockLibraryUtil;
|
import org.jetbrains.kotlin.test.MockLibraryUtil;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -62,7 +65,7 @@ public abstract class KotlinDebuggerTestCase extends DescriptorTestCase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected OutputChecker initOutputChecker() {
|
protected OutputChecker initOutputChecker() {
|
||||||
return new KotlinOutputChecker(TINY_APP);
|
return new KotlinOutputChecker(getTestAppPath(), getAppOutputPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -75,26 +78,6 @@ public abstract class KotlinDebuggerTestCase extends DescriptorTestCase {
|
|||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
VfsRootAccess.allowRootAccess(JetTestUtils.getHomeDirectory());
|
VfsRootAccess.allowRootAccess(JetTestUtils.getHomeDirectory());
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
|
||||||
UsefulTestCase.edt(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
ModifiableRootModel model = ModuleRootManager.getInstance(getModule()).getModifiableModel();
|
|
||||||
|
|
||||||
projectDescriptor.configureModule(getModule(), model);
|
|
||||||
|
|
||||||
VirtualFile customLibrarySources = VfsUtil.findFileByIoFile(CUSTOM_LIBRARY_SOURCES, false);
|
|
||||||
assert customLibrarySources != null : "VirtualFile for customLibrary sources should be found";
|
|
||||||
configureCustomLibrary(model, customLibrarySources);
|
|
||||||
|
|
||||||
model.commit();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void configureCustomLibrary(@NotNull ModifiableRootModel model, @NotNull VirtualFile customLibrarySources) {
|
private static void configureCustomLibrary(@NotNull ModifiableRootModel model, @NotNull VirtualFile customLibrarySources) {
|
||||||
@@ -116,22 +99,46 @@ public abstract class KotlinDebuggerTestCase extends DescriptorTestCase {
|
|||||||
|
|
||||||
@SuppressWarnings("AssignmentToStaticFieldFromInstanceMethod")
|
@SuppressWarnings("AssignmentToStaticFieldFromInstanceMethod")
|
||||||
@Override
|
@Override
|
||||||
protected void ensureCompiledAppExists() throws Exception {
|
protected void setUpModule() {
|
||||||
|
super.setUpModule();
|
||||||
|
|
||||||
|
IdeaTestUtil.setModuleLanguageLevel(myModule, LanguageLevel.JDK_1_6);
|
||||||
|
|
||||||
if (!IS_TINY_APP_COMPILED) {
|
if (!IS_TINY_APP_COMPILED) {
|
||||||
String modulePath = getTestAppPath();
|
String modulePath = getTestAppPath();
|
||||||
|
|
||||||
CUSTOM_LIBRARY_JAR = MockLibraryUtil.compileLibraryToJar(CUSTOM_LIBRARY_SOURCES.getPath(), "debuggerCustomLibrary", false);
|
CUSTOM_LIBRARY_JAR = MockLibraryUtil.compileLibraryToJar(CUSTOM_LIBRARY_SOURCES.getPath(), "debuggerCustomLibrary", false);
|
||||||
|
|
||||||
String outputDir = modulePath + File.separator + "classes";
|
String outputDir = getAppOutputPath();
|
||||||
String sourcesDir = modulePath + File.separator + "src";
|
String sourcesDir = modulePath + File.separator + "src";
|
||||||
|
|
||||||
MockLibraryUtil.compileKotlin(sourcesDir, new File(outputDir), CUSTOM_LIBRARY_JAR.getPath());
|
MockLibraryUtil.compileKotlin(sourcesDir, new File(outputDir), CUSTOM_LIBRARY_JAR.getPath());
|
||||||
|
|
||||||
List<String> options = Arrays.asList("-d", outputDir, "-classpath", ForTestCompileRuntime.runtimeJarForTests().getPath());
|
List<String> options = Arrays.asList("-d", outputDir, "-classpath", ForTestCompileRuntime.runtimeJarForTests().getPath());
|
||||||
JetTestUtils.compileJavaFiles(findJavaFiles(new File(sourcesDir)), options);
|
try {
|
||||||
|
JetTestUtils.compileJavaFiles(findJavaFiles(new File(sourcesDir)), options);
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
IS_TINY_APP_COMPILED = true;
|
IS_TINY_APP_COMPILED = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
ModifiableRootModel model = ModuleRootManager.getInstance(getModule()).getModifiableModel();
|
||||||
|
|
||||||
|
projectDescriptor.configureModule(getModule(), model);
|
||||||
|
|
||||||
|
VirtualFile customLibrarySources = VfsUtil.findFileByIoFile(CUSTOM_LIBRARY_SOURCES, false);
|
||||||
|
assert customLibrarySources != null : "VirtualFile for customLibrary sources should be found";
|
||||||
|
configureCustomLibrary(model, customLibrarySources);
|
||||||
|
|
||||||
|
model.commit();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<File> findJavaFiles(@NotNull File directory) {
|
private static List<File> findJavaFiles(@NotNull File directory) {
|
||||||
@@ -154,27 +161,31 @@ public abstract class KotlinDebuggerTestCase extends DescriptorTestCase {
|
|||||||
|
|
||||||
private static class KotlinOutputChecker extends OutputChecker {
|
private static class KotlinOutputChecker extends OutputChecker {
|
||||||
|
|
||||||
public KotlinOutputChecker(@NotNull String appPath) {
|
public KotlinOutputChecker(@NotNull String appPath, @NotNull String outputPath) {
|
||||||
super(appPath);
|
super(appPath, outputPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String replaceAdditionalInOutput(String str) {
|
protected String replaceAdditionalInOutput(String str) {
|
||||||
//noinspection ConstantConditions
|
//noinspection ConstantConditions
|
||||||
String jdkPath = PluginTestCaseBase.fullJdk().getHomePath().replace('/', File.separatorChar);
|
try {
|
||||||
return super.replaceAdditionalInOutput(
|
return super.replaceAdditionalInOutput(
|
||||||
str.replace(ForTestCompileRuntime.runtimeJarForTests().getPath(), "!KOTLIN_RUNTIME!")
|
str.replace(ForTestCompileRuntime.runtimeJarForTests().getCanonicalPath(), "!KOTLIN_RUNTIME!")
|
||||||
.replace(CUSTOM_LIBRARY_JAR.getPath(), "!CUSTOM_LIBRARY!")
|
.replace(CUSTOM_LIBRARY_JAR.getCanonicalPath(), "!CUSTOM_LIBRARY!")
|
||||||
.replace(jdkPath, "!JDK_HOME!")
|
);
|
||||||
);
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getAppClassesPath() {
|
protected JavaParameters createJavaParameters(String mainClass) {
|
||||||
return super.getAppClassesPath() + File.pathSeparator +
|
JavaParameters parameters = super.createJavaParameters(mainClass);
|
||||||
ForTestCompileRuntime.runtimeJarForTests().getPath() + File.pathSeparator +
|
parameters.getClassPath().add(ForTestCompileRuntime.runtimeJarForTests());
|
||||||
CUSTOM_LIBRARY_JAR.getPath();
|
parameters.getClassPath().add(CUSTOM_LIBRARY_JAR);
|
||||||
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user