Refactor and generate tests on JetPositionManager
This commit is contained in:
@@ -99,6 +99,7 @@ import org.jetbrains.jet.plugin.debugger.AbstractSmartStepIntoTest
|
||||
import org.jetbrains.jet.plugin.stubs.AbstractStubBuilderTest
|
||||
import org.jetbrains.jet.plugin.codeInsight.AbstractJetInspectionTest
|
||||
import org.jetbrains.jet.plugin.debugger.AbstractKotlinSteppingTest
|
||||
import org.jetbrains.jet.plugin.debugger.AbstractJetPositionManagerTest
|
||||
import org.jetbrains.jet.completion.AbstractMultiFileJvmBasicCompletionTest
|
||||
import org.jetbrains.jet.plugin.refactoring.introduce.introduceVariable.AbstractJetExtractionTest
|
||||
import org.jetbrains.jet.formatter.AbstractJetTypingIndentationTestBase
|
||||
@@ -565,6 +566,11 @@ fun main(args: Array<String>) {
|
||||
model("editor/optimizeImports", extension = null, recursive = false)
|
||||
}
|
||||
|
||||
testClass(javaClass<AbstractJetPositionManagerTest>()) {
|
||||
model("debugger/positionManager", recursive = false, extension = "kt", testClassName = "SingleFile")
|
||||
model("debugger/positionManager", recursive = false, extension = null, testClassName = "MultiFile")
|
||||
}
|
||||
|
||||
testClass(javaClass<AbstractSmartStepIntoTest>()) {
|
||||
model("debugger/smartStepInto")
|
||||
}
|
||||
@@ -576,8 +582,8 @@ fun main(args: Array<String>) {
|
||||
}
|
||||
|
||||
testClass(javaClass<AbstractKotlinEvaluateExpressionTest>()) {
|
||||
model("debugger/tinyApp/src/evaluate/singleBreakpoint", testMethod = "doSingleBreakpointTest", recursive = true)
|
||||
model("debugger/tinyApp/src/evaluate/multipleBreakpoints", testMethod = "doMultipleBreakpointsTest", recursive = true)
|
||||
model("debugger/tinyApp/src/evaluate/singleBreakpoint", testMethod = "doSingleBreakpointTest")
|
||||
model("debugger/tinyApp/src/evaluate/multipleBreakpoints", testMethod = "doMultipleBreakpointsTest")
|
||||
}
|
||||
|
||||
testClass(javaClass<AbstractStubBuilderTest>()) {
|
||||
|
||||
+45
-35
@@ -33,52 +33,68 @@ import com.intellij.refactoring.MultiFileTestCase;
|
||||
import com.intellij.testFramework.PsiTestUtil;
|
||||
import com.sun.jdi.Location;
|
||||
import com.sun.jdi.ReferenceType;
|
||||
import kotlin.KotlinPackage;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.OutputFile;
|
||||
import org.jetbrains.jet.OutputFileCollection;
|
||||
import org.jetbrains.jet.codegen.GenerationUtils;
|
||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
||||
import org.jetbrains.jet.plugin.project.PluginJetFilesProvider;
|
||||
import org.jetbrains.jet.utils.UtilsPackage;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public abstract class PositionManagerTestCase extends MultiFileTestCase {
|
||||
|
||||
public abstract class AbstractJetPositionManagerTest 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.
|
||||
// This pattern matches against these line comments and saves the class name in the first group
|
||||
private static final Pattern BREAKPOINT_PATTERN = Pattern.compile("^.*//\\s*([a-zA-Z0-9._/$]*)\\s*$");
|
||||
|
||||
@NotNull
|
||||
protected abstract String getTestDataPath();
|
||||
|
||||
@NotNull
|
||||
protected abstract PositionManager createPositionManager(DebugProcess process, List<JetFile> files, GenerationState state);
|
||||
|
||||
protected void doTest() {
|
||||
String path = getTestRoot() + getTestName(true) + ".kt";
|
||||
try {
|
||||
configureByFile(path);
|
||||
}
|
||||
catch (Exception e) {
|
||||
UtilsPackage.rethrow(e);
|
||||
}
|
||||
performTest();
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return PluginTestCaseBase.getTestDataPathBase();
|
||||
}
|
||||
|
||||
protected void doMultiTest() {
|
||||
String path = getTestDataPath() + getTestRoot() + getTestName(true);
|
||||
try {
|
||||
VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, path, myFilesToDelete, false);
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTestRoot() {
|
||||
return "/debugger/positionManager/";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static JetPositionManager createPositionManager(
|
||||
@NotNull DebugProcess process,
|
||||
@NotNull List<JetFile> files,
|
||||
@NotNull GenerationState state
|
||||
) {
|
||||
JetPositionManager positionManager = (JetPositionManager) new JetPositionManagerFactory().createPositionManager(process);
|
||||
assertNotNull(positionManager);
|
||||
|
||||
for (JetFile file : files) {
|
||||
positionManager.addTypeMapper(file, state.getTypeMapper());
|
||||
}
|
||||
|
||||
return positionManager;
|
||||
}
|
||||
|
||||
protected void doTest(@NotNull String fileName) throws Exception {
|
||||
if (fileName.endsWith(".kt")) {
|
||||
String path = KotlinPackage.substringAfter(fileName, PluginTestCaseBase.TEST_DATA_PROJECT_RELATIVE.substring(1), fileName);
|
||||
configureByFile(path);
|
||||
}
|
||||
else {
|
||||
VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, fileName, myFilesToDelete, false);
|
||||
prepareProject(rootDir);
|
||||
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
|
||||
}
|
||||
catch (Exception e) {
|
||||
UtilsPackage.rethrow(e);
|
||||
}
|
||||
|
||||
performTest();
|
||||
}
|
||||
|
||||
@@ -100,6 +116,7 @@ public abstract class PositionManagerTestCase extends MultiFileTestCase {
|
||||
final PositionManager positionManager = createPositionManager(debugProcess, files, state);
|
||||
|
||||
ApplicationManager.getApplication().runReadAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
for (Breakpoint breakpoint : breakpoints) {
|
||||
@@ -107,7 +124,7 @@ public abstract class PositionManagerTestCase extends MultiFileTestCase {
|
||||
}
|
||||
}
|
||||
catch (NoDataException e) {
|
||||
UtilsPackage.rethrow(e);
|
||||
throw UtilsPackage.rethrow(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -138,9 +155,10 @@ public abstract class PositionManagerTestCase extends MultiFileTestCase {
|
||||
}
|
||||
|
||||
private DebugProcessEvents createDebugProcess(final Map<String, ReferenceType> referencesByName) {
|
||||
DebugProcessEvents events = new DebugProcessEvents(getProject()) {
|
||||
return new DebugProcessEvents(getProject()) {
|
||||
private VirtualMachineProxyImpl virtualMachineProxy;
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public VirtualMachineProxyImpl getVirtualMachineProxy() {
|
||||
if (virtualMachineProxy == null) {
|
||||
@@ -149,8 +167,6 @@ public abstract class PositionManagerTestCase extends MultiFileTestCase {
|
||||
return virtualMachineProxy;
|
||||
}
|
||||
};
|
||||
|
||||
return events;
|
||||
}
|
||||
|
||||
private static void assertBreakpointIsHandledCorrectly(Breakpoint breakpoint, PositionManager positionManager) throws NoDataException {
|
||||
@@ -201,13 +217,7 @@ public abstract class PositionManagerTestCase extends MultiFileTestCase {
|
||||
|
||||
@Override
|
||||
public List<ReferenceType> classesByName(String name) {
|
||||
ReferenceType ref = referencesByName.get(name);
|
||||
if (ref == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
else {
|
||||
return Collections.singletonList(ref);
|
||||
}
|
||||
return UtilsPackage.emptyOrSingletonList(referencesByName.get(name));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,137 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.plugin.debugger;
|
||||
|
||||
import com.intellij.debugger.engine.DebugProcess;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class JetPositionManagerTest extends PositionManagerTestCase {
|
||||
private final JetPositionManagerFactory jetPositionManagerFactory = new JetPositionManagerFactory();
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected String getTestDataPath() {
|
||||
return PluginTestCaseBase.getTestDataPathBase();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTestRoot() {
|
||||
return "/debugger/";
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected JetPositionManager createPositionManager(DebugProcess process, List<JetFile> files, GenerationState state) {
|
||||
JetPositionManager positionManager = (JetPositionManager) jetPositionManagerFactory.createPositionManager(process);
|
||||
assertNotNull(positionManager);
|
||||
|
||||
for (JetFile file : files) {
|
||||
positionManager.addTypeMapper(file, state.getTypeMapper());
|
||||
}
|
||||
|
||||
return positionManager;
|
||||
}
|
||||
|
||||
public void testMultiFilePackage() {
|
||||
doMultiTest();
|
||||
}
|
||||
|
||||
public void testMultiFileSameName() {
|
||||
doMultiTest();
|
||||
}
|
||||
|
||||
public void testAnonymousFunction() {
|
||||
doTest();
|
||||
}
|
||||
public void testAnonymousNamedFunction() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testFunctionLiteral() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testFunctionLiteralInVal() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testClass() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testClassObject() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testEnum() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testExtensionFunction() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testInnerClass() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testLocalFunction() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void test_DefaultPackage() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testPackage() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testObjectDeclaration() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testObjectExpression() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testPropertyAccessor() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testPropertyInitializer() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testTopLevelPropertyInitializer() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testTrait() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testTwoClasses() {
|
||||
doTest();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
/*
|
||||
* Copyright 2010-2014 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.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.plugin.debugger;
|
||||
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.test.InnerTestClasses;
|
||||
import org.jetbrains.jet.test.TestMetadata;
|
||||
import org.jetbrains.jet.JUnit3RunnerWithInners;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@InnerTestClasses({JetPositionManagerTestGenerated.SingleFile.class, JetPositionManagerTestGenerated.MultiFile.class})
|
||||
@RunWith(org.jetbrains.jet.JUnit3RunnerWithInners.class)
|
||||
public class JetPositionManagerTestGenerated extends AbstractJetPositionManagerTest {
|
||||
@TestMetadata("idea/testData/debugger/positionManager")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(org.jetbrains.jet.JUnit3RunnerWithInners.class)
|
||||
public static class SingleFile extends AbstractJetPositionManagerTest {
|
||||
public void testAllFilesPresentInSingleFile() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/debugger/positionManager"), Pattern.compile("^(.+)\\.kt$"), false);
|
||||
}
|
||||
|
||||
@TestMetadata("anonymousFunction.kt")
|
||||
public void testAnonymousFunction() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/debugger/positionManager/anonymousFunction.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("anonymousNamedFunction.kt")
|
||||
public void testAnonymousNamedFunction() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/debugger/positionManager/anonymousNamedFunction.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("class.kt")
|
||||
public void testClass() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/debugger/positionManager/class.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("classObject.kt")
|
||||
public void testClassObject() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/debugger/positionManager/classObject.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("enum.kt")
|
||||
public void testEnum() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/debugger/positionManager/enum.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("extensionFunction.kt")
|
||||
public void testExtensionFunction() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/debugger/positionManager/extensionFunction.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("functionLiteral.kt")
|
||||
public void testFunctionLiteral() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/debugger/positionManager/functionLiteral.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("functionLiteralInVal.kt")
|
||||
public void testFunctionLiteralInVal() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/debugger/positionManager/functionLiteralInVal.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("innerClass.kt")
|
||||
public void testInnerClass() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/debugger/positionManager/innerClass.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("localFunction.kt")
|
||||
public void testLocalFunction() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/debugger/positionManager/localFunction.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("objectDeclaration.kt")
|
||||
public void testObjectDeclaration() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/debugger/positionManager/objectDeclaration.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("objectExpression.kt")
|
||||
public void testObjectExpression() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/debugger/positionManager/objectExpression.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("package.kt")
|
||||
public void testPackage() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/debugger/positionManager/package.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("propertyAccessor.kt")
|
||||
public void testPropertyAccessor() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/debugger/positionManager/propertyAccessor.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("propertyInitializer.kt")
|
||||
public void testPropertyInitializer() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/debugger/positionManager/propertyInitializer.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("topLevelPropertyInitializer.kt")
|
||||
public void testTopLevelPropertyInitializer() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/debugger/positionManager/topLevelPropertyInitializer.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("trait.kt")
|
||||
public void testTrait() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/debugger/positionManager/trait.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("twoClasses.kt")
|
||||
public void testTwoClasses() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/debugger/positionManager/twoClasses.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("_DefaultPackage.kt")
|
||||
public void test_DefaultPackage() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/debugger/positionManager/_DefaultPackage.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/debugger/positionManager")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(org.jetbrains.jet.JUnit3RunnerWithInners.class)
|
||||
public static class MultiFile extends AbstractJetPositionManagerTest {
|
||||
public void testAllFilesPresentInMultiFile() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/debugger/positionManager"), Pattern.compile("^([^\\.]+)$"), false);
|
||||
}
|
||||
|
||||
@TestMetadata("multiFilePackage")
|
||||
public void testMultiFilePackage() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/debugger/positionManager/multiFilePackage/");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("multiFileSameName")
|
||||
public void testMultiFileSameName() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/debugger/positionManager/multiFileSameName/");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user