Add tests for tracing frame
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.jetbrains.jet.plugin.debugger;
|
||||
|
||||
import com.intellij.debugger.DebuggerTestCase;
|
||||
import com.intellij.debugger.impl.DescriptorTestCase;
|
||||
import com.intellij.debugger.impl.OutputChecker;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
@@ -50,7 +50,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class KotlinDebuggerTestCase extends DebuggerTestCase {
|
||||
public abstract class KotlinDebuggerTestCase extends DescriptorTestCase {
|
||||
protected static final String TINY_APP = PluginTestCaseBase.getTestDataPathBase() + "/debugger/tinyApp";
|
||||
private static boolean IS_TINY_APP_COMPILED = false;
|
||||
|
||||
|
||||
+89
-16
@@ -40,9 +40,20 @@ import org.apache.log4j.AppenderSkeleton
|
||||
import org.apache.log4j.spi.LoggingEvent
|
||||
import org.apache.log4j.Level
|
||||
import org.apache.log4j.Logger
|
||||
import com.intellij.debugger.ui.impl.FrameVariablesTree
|
||||
import com.intellij.openapi.util.Disposer
|
||||
import com.intellij.debugger.ui.impl.watch.DebuggerTree
|
||||
import com.intellij.debugger.ui.impl.watch.DebuggerTreeNodeImpl
|
||||
import com.intellij.debugger.ui.impl.watch.DefaultNodeDescriptor
|
||||
import com.intellij.xdebugger.impl.ui.XDebuggerUIConstants
|
||||
import com.intellij.debugger.ui.tree.LocalVariableDescriptor
|
||||
import com.intellij.debugger.ui.tree.StackFrameDescriptor
|
||||
import com.intellij.debugger.ui.tree.StaticDescriptor
|
||||
import com.intellij.debugger.ui.impl.watch.ThisDescriptorImpl
|
||||
import com.intellij.debugger.ui.tree.FieldDescriptor
|
||||
import com.intellij.debugger.ui.impl.watch.NodeDescriptorImpl
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.util.Computable
|
||||
import com.intellij.psi.PsiDocumentManager
|
||||
|
||||
public abstract class AbstractKotlinEvaluateExpressionTest : KotlinDebuggerTestCase() {
|
||||
private val logger = Logger.getLogger(javaClass<KotlinEvaluateExpressionCache>())!!
|
||||
@@ -74,7 +85,11 @@ public abstract class AbstractKotlinEvaluateExpressionTest : KotlinDebuggerTestC
|
||||
|
||||
fun doSingleBreakpointTest(path: String) {
|
||||
val file = File(path)
|
||||
val expressions = loadTestDirectivesPairs(file, "// EXPRESSION: ", "// RESULT: ")
|
||||
val fileText = FileUtil.loadFile(file, true)
|
||||
|
||||
val shouldPrintFrame = InTextDirectivesUtils.isDirectiveDefined(fileText, "// PRINT_FRAME")
|
||||
|
||||
val expressions = loadTestDirectivesPairs(fileText, "// EXPRESSION: ", "// RESULT: ")
|
||||
|
||||
val blocks = findFilesWithBlocks(file).map { FileUtil.loadFile(it, true) }
|
||||
val expectedBlockResults = blocks.map { InTextDirectivesUtils.findLinesWithPrefixesRemoved(it, "// RESULT: ").makeString("\n") }
|
||||
@@ -83,15 +98,26 @@ public abstract class AbstractKotlinEvaluateExpressionTest : KotlinDebuggerTestC
|
||||
|
||||
onBreakpoint {
|
||||
val exceptions = linkedMapOf<String, Throwable>()
|
||||
for ((expression, expected) in expressions) {
|
||||
mayThrow(exceptions, expression) {
|
||||
evaluate(expression, CodeFragmentKind.EXPRESSION, expected)
|
||||
try {
|
||||
for ((expression, expected) in expressions) {
|
||||
mayThrow(exceptions, expression) {
|
||||
evaluate(expression, CodeFragmentKind.EXPRESSION, expected)
|
||||
}
|
||||
}
|
||||
|
||||
for ((i, block) in blocks.withIndices()) {
|
||||
mayThrow(exceptions, block) {
|
||||
evaluate(block, CodeFragmentKind.CODE_BLOCK, expectedBlockResults[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for ((i, block) in blocks.withIndices()) {
|
||||
mayThrow(exceptions, block) {
|
||||
evaluate(block, CodeFragmentKind.CODE_BLOCK, expectedBlockResults[i])
|
||||
finally {
|
||||
if (shouldPrintFrame) {
|
||||
printFrame()
|
||||
println(fileText, ProcessOutputTypes.SYSTEM)
|
||||
}
|
||||
else {
|
||||
resume(this)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +127,7 @@ public abstract class AbstractKotlinEvaluateExpressionTest : KotlinDebuggerTestC
|
||||
}
|
||||
|
||||
fun doMultipleBreakpointsTest(path: String) {
|
||||
val expressions = loadTestDirectivesPairs(File(path), "// EXPRESSION: ", "// RESULT: ")
|
||||
val expressions = loadTestDirectivesPairs(FileUtil.loadFile(File(path), true), "// EXPRESSION: ", "// RESULT: ")
|
||||
|
||||
createDebugProcess(path)
|
||||
|
||||
@@ -109,7 +135,12 @@ public abstract class AbstractKotlinEvaluateExpressionTest : KotlinDebuggerTestC
|
||||
for ((expression, expected) in expressions) {
|
||||
mayThrow(exceptions, expression) {
|
||||
onBreakpoint {
|
||||
evaluate(expression, CodeFragmentKind.EXPRESSION, expected)
|
||||
try {
|
||||
evaluate(expression, CodeFragmentKind.EXPRESSION, expected)
|
||||
}
|
||||
finally {
|
||||
resume(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -119,7 +150,53 @@ public abstract class AbstractKotlinEvaluateExpressionTest : KotlinDebuggerTestC
|
||||
finish()
|
||||
}
|
||||
|
||||
private fun SuspendContextImpl.printFrame() {
|
||||
val tree = FrameVariablesTree(getProject()!!)
|
||||
Disposer.register(getTestRootDisposable()!!, tree);
|
||||
|
||||
val debuggerContext = createDebuggerContext(this)
|
||||
invokeRatherLater(this) {
|
||||
tree.rebuild(debuggerContext)
|
||||
expandAll(tree, Runnable {
|
||||
PRINTER.printTree(tree)
|
||||
resume(this@printFrame)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
private val PRINTER = object {
|
||||
fun printTree(tree: DebuggerTree) {
|
||||
val root = tree.getMutableModel()!!.getRoot() as DebuggerTreeNodeImpl
|
||||
printNode(root, 0)
|
||||
}
|
||||
|
||||
private fun printNode(node: DebuggerTreeNodeImpl, indent: Int) {
|
||||
val descriptor: NodeDescriptorImpl = node.getDescriptor()!!
|
||||
if (descriptor is DefaultNodeDescriptor) return
|
||||
|
||||
val label = descriptor.getLabel()!!.replaceAll("-[\\w]*-[\\w|\\d]+", "-@packagePartHASH")
|
||||
if (label.endsWith(XDebuggerUIConstants.COLLECTING_DATA_MESSAGE)) return
|
||||
|
||||
val curIndent = " ".repeat(indent)
|
||||
when (descriptor) {
|
||||
is StackFrameDescriptor -> logDescriptor(descriptor, "$curIndent frame = $label\n")
|
||||
is LocalVariableDescriptor -> logDescriptor(descriptor, "$curIndent local = $label\n")
|
||||
is StaticDescriptor -> logDescriptor(descriptor, "$curIndent static = $label\n")
|
||||
is ThisDescriptorImpl -> logDescriptor(descriptor, "$curIndent this = $label\n")
|
||||
is FieldDescriptor -> logDescriptor(descriptor, "$curIndent field = $label\n")
|
||||
else -> logDescriptor(descriptor, "$curIndent unknown = $label\n")
|
||||
}
|
||||
|
||||
printChildren(node, indent + 2)
|
||||
}
|
||||
|
||||
private fun printChildren(node: DebuggerTreeNodeImpl, indent: Int) {
|
||||
val e = node.rawChildren()!!
|
||||
while (e.hasMoreElements()) {
|
||||
printNode(e.nextElement() as DebuggerTreeNodeImpl, indent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkExceptions(exceptions: MutableMap<String, Throwable>) {
|
||||
if (!exceptions.empty) {
|
||||
@@ -139,8 +216,7 @@ public abstract class AbstractKotlinEvaluateExpressionTest : KotlinDebuggerTestC
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadTestDirectivesPairs(file: File, directivePrefix: String, expectedPrefix: String): List<Pair<String, String>> {
|
||||
val fileContent = FileUtil.loadFile(file, true)
|
||||
private fun loadTestDirectivesPairs(fileContent: String, directivePrefix: String, expectedPrefix: String): List<Pair<String, String>> {
|
||||
val directives = InTextDirectivesUtils.findLinesWithPrefixesRemoved(fileContent, directivePrefix)
|
||||
val expected = InTextDirectivesUtils.findLinesWithPrefixesRemoved(fileContent, expectedPrefix)
|
||||
assert(directives.size == expected.size, "Sizes of test directives are different")
|
||||
@@ -194,9 +270,6 @@ public abstract class AbstractKotlinEvaluateExpressionTest : KotlinDebuggerTestC
|
||||
catch (e: EvaluateException) {
|
||||
Assert.assertTrue("Evaluate expression throws wrong exception for $text:\nexpected = $expectedResult\nactual = ${e.getMessage()}\n", expectedResult == e.getMessage()?.replaceFirst("id=[0-9]*", "id=ID"))
|
||||
}
|
||||
finally {
|
||||
resume(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+75
-1
@@ -30,7 +30,7 @@ import org.jetbrains.jet.plugin.debugger.evaluate.AbstractKotlinEvaluateExpressi
|
||||
|
||||
/** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@InnerTestClasses({KotlinEvaluateExpressionTestGenerated.SingleBreakpoint.class, KotlinEvaluateExpressionTestGenerated.MultipleBreakpoints.class})
|
||||
@InnerTestClasses({KotlinEvaluateExpressionTestGenerated.SingleBreakpoint.class, KotlinEvaluateExpressionTestGenerated.MultipleBreakpoints.class, KotlinEvaluateExpressionTestGenerated.Frame.class})
|
||||
public class KotlinEvaluateExpressionTestGenerated extends AbstractKotlinEvaluateExpressionTest {
|
||||
@TestMetadata("idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint")
|
||||
public static class SingleBreakpoint extends AbstractKotlinEvaluateExpressionTest {
|
||||
@@ -158,10 +158,84 @@ public class KotlinEvaluateExpressionTestGenerated extends AbstractKotlinEvaluat
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/debugger/tinyApp/src/evaluate/frame")
|
||||
public static class Frame extends AbstractKotlinEvaluateExpressionTest {
|
||||
public void testAllFilesPresentInFrame() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/debugger/tinyApp/src/evaluate/frame"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("frameAnonymousObject.kt")
|
||||
public void testFrameAnonymousObject() throws Exception {
|
||||
doSingleBreakpointTest("idea/testData/debugger/tinyApp/src/evaluate/frame/frameAnonymousObject.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("frameClassObject.kt")
|
||||
public void testFrameClassObject() throws Exception {
|
||||
doSingleBreakpointTest("idea/testData/debugger/tinyApp/src/evaluate/frame/frameClassObject.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("frameExtFunExtFun.kt")
|
||||
public void testFrameExtFunExtFun() throws Exception {
|
||||
doSingleBreakpointTest("idea/testData/debugger/tinyApp/src/evaluate/frame/frameExtFunExtFun.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("frameExtensionFun.kt")
|
||||
public void testFrameExtensionFun() throws Exception {
|
||||
doSingleBreakpointTest("idea/testData/debugger/tinyApp/src/evaluate/frame/frameExtensionFun.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("frameInnerClass.kt")
|
||||
public void testFrameInnerClass() throws Exception {
|
||||
doSingleBreakpointTest("idea/testData/debugger/tinyApp/src/evaluate/frame/frameInnerClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("frameInnerLambda.kt")
|
||||
public void testFrameInnerLambda() throws Exception {
|
||||
doSingleBreakpointTest("idea/testData/debugger/tinyApp/src/evaluate/frame/frameInnerLambda.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("frameLambda.kt")
|
||||
public void testFrameLambda() throws Exception {
|
||||
doSingleBreakpointTest("idea/testData/debugger/tinyApp/src/evaluate/frame/frameLambda.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("frameObject.kt")
|
||||
public void testFrameObject() throws Exception {
|
||||
doSingleBreakpointTest("idea/testData/debugger/tinyApp/src/evaluate/frame/frameObject.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("frameSharedVar.kt")
|
||||
public void testFrameSharedVar() throws Exception {
|
||||
doSingleBreakpointTest("idea/testData/debugger/tinyApp/src/evaluate/frame/frameSharedVar.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("frameSimple.kt")
|
||||
public void testFrameSimple() throws Exception {
|
||||
doSingleBreakpointTest("idea/testData/debugger/tinyApp/src/evaluate/frame/frameSimple.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("frameThis0.kt")
|
||||
public void testFrameThis0() throws Exception {
|
||||
doSingleBreakpointTest("idea/testData/debugger/tinyApp/src/evaluate/frame/frameThis0.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("frameThis0Ext.kt")
|
||||
public void testFrameThis0Ext() throws Exception {
|
||||
doSingleBreakpointTest("idea/testData/debugger/tinyApp/src/evaluate/frame/frameThis0Ext.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("frameThis0This0.kt")
|
||||
public void testFrameThis0This0() throws Exception {
|
||||
doSingleBreakpointTest("idea/testData/debugger/tinyApp/src/evaluate/frame/frameThis0This0.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
TestSuite suite = new TestSuite("KotlinEvaluateExpressionTestGenerated");
|
||||
suite.addTestSuite(SingleBreakpoint.class);
|
||||
suite.addTestSuite(MultipleBreakpoints.class);
|
||||
suite.addTestSuite(Frame.class);
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user