Refactor tests for JetPositionManager
PositionManagerTestCase now inherits from MultiFileTestCase, which allows to call configureByFile to configure tests properly. Also multi-file tests are now done by copying test project file structure
This commit is contained in:
@@ -19,9 +19,9 @@ package org.jetbrains.jet.plugin.debugger;
|
|||||||
import com.intellij.debugger.engine.DebugProcess;
|
import com.intellij.debugger.engine.DebugProcess;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.codegen.ClassBuilderMode;
|
import org.jetbrains.jet.codegen.ClassBuilderMode;
|
||||||
|
import org.jetbrains.jet.codegen.binding.CodegenBinding;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
import org.jetbrains.jet.codegen.state.GenerationState;
|
||||||
import org.jetbrains.jet.codegen.state.JetTypeMapper;
|
import org.jetbrains.jet.codegen.state.JetTypeMapper;
|
||||||
import org.jetbrains.jet.codegen.binding.CodegenBinding;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
import org.jetbrains.jet.lang.resolve.DelegatingBindingTrace;
|
import org.jetbrains.jet.lang.resolve.DelegatingBindingTrace;
|
||||||
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
||||||
@@ -37,7 +37,12 @@ public class JetPositionManagerTest extends PositionManagerTestCase {
|
|||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NotNull
|
||||||
protected String getTestDataPath() {
|
protected String getTestDataPath() {
|
||||||
return PluginTestCaseBase.getTestDataPathBase() + "/debugger";
|
return PluginTestCaseBase.getTestDataPathBase();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getTestRoot() {
|
||||||
|
return "/debugger/";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -46,7 +51,7 @@ public class JetPositionManagerTest extends PositionManagerTestCase {
|
|||||||
JetPositionManager positionManager = (JetPositionManager) jetPositionManagerFactory.createPositionManager(process);
|
JetPositionManager positionManager = (JetPositionManager) jetPositionManagerFactory.createPositionManager(process);
|
||||||
assertNotNull(positionManager);
|
assertNotNull(positionManager);
|
||||||
|
|
||||||
final DelegatingBindingTrace bindingTrace = new DelegatingBindingTrace(state.getBindingContext());
|
DelegatingBindingTrace bindingTrace = new DelegatingBindingTrace(state.getBindingContext());
|
||||||
JetTypeMapper typeMapper = new JetTypeMapper(bindingTrace, true, ClassBuilderMode.FULL);
|
JetTypeMapper typeMapper = new JetTypeMapper(bindingTrace, true, ClassBuilderMode.FULL);
|
||||||
//noinspection unchecked
|
//noinspection unchecked
|
||||||
CodegenBinding.initTrace(bindingTrace, files);
|
CodegenBinding.initTrace(bindingTrace, files);
|
||||||
@@ -58,7 +63,7 @@ public class JetPositionManagerTest extends PositionManagerTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testMultiFileNamespace() {
|
public void testMultiFileNamespace() {
|
||||||
doMultiTest("multiFileNamespace/a.kt", "multiFileNamespace/b.kt");
|
doMultiTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAnonymousFunction() {
|
public void testAnonymousFunction() {
|
||||||
|
|||||||
@@ -25,21 +25,21 @@ import com.intellij.debugger.engine.DebugProcess;
|
|||||||
import com.intellij.debugger.engine.DebugProcessEvents;
|
import com.intellij.debugger.engine.DebugProcessEvents;
|
||||||
import com.intellij.debugger.jdi.VirtualMachineProxyImpl;
|
import com.intellij.debugger.jdi.VirtualMachineProxyImpl;
|
||||||
import com.intellij.openapi.application.ApplicationManager;
|
import com.intellij.openapi.application.ApplicationManager;
|
||||||
import com.intellij.openapi.util.io.FileUtil;
|
|
||||||
import com.intellij.openapi.util.text.StringUtil;
|
import com.intellij.openapi.util.text.StringUtil;
|
||||||
import com.intellij.testFramework.PlatformTestCase;
|
import com.intellij.openapi.vfs.VirtualFile;
|
||||||
|
import com.intellij.psi.PsiDocumentManager;
|
||||||
|
import com.intellij.psi.search.GlobalSearchScope;
|
||||||
|
import com.intellij.refactoring.MultiFileTestCase;
|
||||||
|
import com.intellij.testFramework.PsiTestUtil;
|
||||||
import com.sun.jdi.ReferenceType;
|
import com.sun.jdi.ReferenceType;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.JetTestUtils;
|
|
||||||
import org.jetbrains.jet.codegen.ClassFileFactory;
|
import org.jetbrains.jet.codegen.ClassFileFactory;
|
||||||
import org.jetbrains.jet.codegen.GenerationUtils;
|
import org.jetbrains.jet.codegen.GenerationUtils;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
import org.jetbrains.jet.codegen.state.GenerationState;
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.JetFilesProvider;
|
||||||
import org.jetbrains.jet.utils.ExceptionUtils;
|
import org.jetbrains.jet.utils.ExceptionUtils;
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@@ -47,7 +47,7 @@ import java.util.regex.Pattern;
|
|||||||
/**
|
/**
|
||||||
* @author udalov
|
* @author udalov
|
||||||
*/
|
*/
|
||||||
public abstract class PositionManagerTestCase extends PlatformTestCase {
|
public abstract class PositionManagerTestCase extends MultiFileTestCase {
|
||||||
|
|
||||||
// Breakpoint is given as a line comment on a specific line, containing the name of the class, where that line can be found.
|
// Breakpoint is given as a line comment on a specific line, containing the name of the class, where that line can be found.
|
||||||
// This pattern matches against these line comments and saves the class name in the first group
|
// This pattern matches against these line comments and saves the class name in the first group
|
||||||
@@ -59,76 +59,44 @@ public abstract class PositionManagerTestCase extends PlatformTestCase {
|
|||||||
@NotNull
|
@NotNull
|
||||||
protected abstract PositionManager createPositionManager(DebugProcess process, List<JetFile> files, GenerationState state);
|
protected abstract PositionManager createPositionManager(DebugProcess process, List<JetFile> files, GenerationState state);
|
||||||
|
|
||||||
@Override
|
|
||||||
protected final void setUp() throws Exception {
|
|
||||||
SwingUtilities.invokeAndWait(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
PositionManagerTestCase.super.setUp();
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
ExceptionUtils.rethrow(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected final void tearDown() throws Exception {
|
|
||||||
SwingUtilities.invokeAndWait(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
PositionManagerTestCase.super.tearDown();
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
ExceptionUtils.rethrow(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void runBareRunnable(Runnable runnable) {
|
|
||||||
runnable.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void doTest() {
|
protected void doTest() {
|
||||||
doTest(getTestDataPath() + "/" + getTestName(true) + ".kt");
|
String path = getTestRoot() + getTestName(true) + ".kt";
|
||||||
}
|
try {
|
||||||
|
configureByFile(path);
|
||||||
protected void doMultiTest(String... filenames) {
|
|
||||||
for (int i = 0; i < filenames.length; i++) {
|
|
||||||
filenames[i] = getTestDataPath() + "/" + filenames[i];
|
|
||||||
}
|
}
|
||||||
doTest(filenames);
|
catch (Exception e) {
|
||||||
|
ExceptionUtils.rethrow(e);
|
||||||
|
}
|
||||||
|
performTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doTest(String... filenames) {
|
protected void doMultiTest() {
|
||||||
final List<JetFile> files = Lists.newArrayList();
|
String path = getTestDataPath() + getTestRoot() + getTestName(true);
|
||||||
|
try {
|
||||||
|
VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, path, myFilesToDelete, false);
|
||||||
|
prepareProject(rootDir);
|
||||||
|
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
ExceptionUtils.rethrow(e);
|
||||||
|
}
|
||||||
|
performTest();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void performTest() {
|
||||||
|
List<JetFile> files = Lists.newArrayList(
|
||||||
|
JetFilesProvider.getInstance(getProject()).allInScope(GlobalSearchScope.allScope(getProject())));
|
||||||
|
|
||||||
final List<Breakpoint> breakpoints = Lists.newArrayList();
|
final List<Breakpoint> breakpoints = Lists.newArrayList();
|
||||||
|
for (JetFile file : files) {
|
||||||
for (String filename : filenames) {
|
breakpoints.addAll(extractBreakpointsInfo(file, file.getText()));
|
||||||
File file = new File(filename);
|
|
||||||
String fileContent;
|
|
||||||
try {
|
|
||||||
fileContent = FileUtil.loadFile(file);
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
throw ExceptionUtils.rethrow(e);
|
|
||||||
}
|
|
||||||
final JetFile jetFile = JetTestUtils.createFile(file.getAbsolutePath(), fileContent, getProject());
|
|
||||||
|
|
||||||
files.add(jetFile);
|
|
||||||
breakpoints.addAll(extractBreakpointsInfo(jetFile, fileContent));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GenerationState state = GenerationUtils.compileManyFilesGetGenerationStateForTest(getProject(), files);
|
GenerationState state = GenerationUtils.compileManyFilesGetGenerationStateForTest(getProject(), files);
|
||||||
|
|
||||||
Map<String, ReferenceType> referencesByName = getReferenceMap(state.getFactory());
|
Map<String, ReferenceType> referencesByName = getReferenceMap(state.getFactory());
|
||||||
|
|
||||||
final DebugProcess debugProcess = createDebugProcess(referencesByName);
|
DebugProcess debugProcess = createDebugProcess(referencesByName);
|
||||||
|
|
||||||
final PositionManager positionManager = createPositionManager(debugProcess, files, state);
|
final PositionManager positionManager = createPositionManager(debugProcess, files, state);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user