Debugger: breakpoints in library source files
This commit is contained in:
@@ -210,6 +210,6 @@ public abstract class KotlinDebuggerTestCase extends DescriptorTestCase {
|
||||
|
||||
@Override
|
||||
protected Sdk getTestProjectJdk() {
|
||||
return PluginTestCaseBase.jdkFromIdeaHome();
|
||||
return PluginTestCaseBase.fullJdk();
|
||||
}
|
||||
}
|
||||
|
||||
+49
-2
@@ -53,7 +53,11 @@ 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.search.FilenameIndex
|
||||
import com.intellij.psi.PsiManager
|
||||
import com.intellij.debugger.DebuggerManagerEx
|
||||
import com.intellij.psi.PsiDocumentManager
|
||||
import com.intellij.openapi.application.ModalityState
|
||||
|
||||
public abstract class AbstractKotlinEvaluateExpressionTest : KotlinDebuggerTestCase() {
|
||||
private val logger = Logger.getLogger(javaClass<KotlinEvaluateExpressionCache>())!!
|
||||
@@ -87,6 +91,8 @@ public abstract class AbstractKotlinEvaluateExpressionTest : KotlinDebuggerTestC
|
||||
val file = File(path)
|
||||
val fileText = FileUtil.loadFile(file, true)
|
||||
|
||||
createAdditionalBreakpoints(fileText)
|
||||
|
||||
val shouldPrintFrame = InTextDirectivesUtils.isDirectiveDefined(fileText, "// PRINT_FRAME")
|
||||
|
||||
val expressions = loadTestDirectivesPairs(fileText, "// EXPRESSION: ", "// RESULT: ")
|
||||
@@ -127,10 +133,15 @@ public abstract class AbstractKotlinEvaluateExpressionTest : KotlinDebuggerTestC
|
||||
}
|
||||
|
||||
fun doMultipleBreakpointsTest(path: String) {
|
||||
val expressions = loadTestDirectivesPairs(FileUtil.loadFile(File(path), true), "// EXPRESSION: ", "// RESULT: ")
|
||||
val file = File(path)
|
||||
val fileText = FileUtil.loadFile(file, true)
|
||||
|
||||
createAdditionalBreakpoints(fileText)
|
||||
|
||||
createDebugProcess(path)
|
||||
|
||||
val expressions = loadTestDirectivesPairs(fileText, "// EXPRESSION: ", "// RESULT: ")
|
||||
|
||||
val exceptions = linkedMapOf<String, Throwable>()
|
||||
for ((expression, expected) in expressions) {
|
||||
mayThrow(exceptions, expression) {
|
||||
@@ -150,6 +161,42 @@ public abstract class AbstractKotlinEvaluateExpressionTest : KotlinDebuggerTestC
|
||||
finish()
|
||||
}
|
||||
|
||||
private fun createAdditionalBreakpoints(fileText: String) {
|
||||
val breakpoints = InTextDirectivesUtils.findLinesWithPrefixesRemoved(fileText, "// ADDITIONAL_BREAKPOINT: ")
|
||||
for (breakpoint in breakpoints) {
|
||||
val position = breakpoint.split(".kt:")
|
||||
assert(position.size == 2, "Couldn't parse position from test directive: directive = ${breakpoint}")
|
||||
createBreakpoint(position[0], position[1])
|
||||
}
|
||||
}
|
||||
|
||||
private fun createBreakpoint(fileName: String, lineMarker: String) {
|
||||
val project = getProject()!!
|
||||
val sourceFiles = FilenameIndex.getAllFilesByExt(project, "kt").filter {
|
||||
it.getName().contains(fileName) &&
|
||||
it.contentsToByteArray().toString("UTF-8").contains(lineMarker)
|
||||
}
|
||||
|
||||
assert(sourceFiles.size() == 1, "One source file should be found: name = $fileName, sourceFiles = $sourceFiles")
|
||||
|
||||
val runnable = Runnable() {
|
||||
val psiSourceFile = PsiManager.getInstance(project).findFile(sourceFiles.first())!!
|
||||
|
||||
val breakpointManager = DebuggerManagerEx.getInstanceEx(project)?.getBreakpointManager()!!
|
||||
val document = PsiDocumentManager.getInstance(project).getDocument(psiSourceFile)!!
|
||||
|
||||
val index = psiSourceFile.getText()!!.indexOf(lineMarker)
|
||||
val lineNumber = document.getLineNumber(index) + 1
|
||||
|
||||
val breakpoint = breakpointManager.addLineBreakpoint(document, lineNumber)
|
||||
if (breakpoint != null) {
|
||||
println("LineBreakpoint created at " + psiSourceFile.getName() + ":" + lineNumber, ProcessOutputTypes.SYSTEM);
|
||||
}
|
||||
}
|
||||
|
||||
DebuggerInvocationUtil.invokeAndWait(project, runnable, ModalityState.defaultModalityState())
|
||||
}
|
||||
|
||||
private fun SuspendContextImpl.printFrame() {
|
||||
val tree = FrameVariablesTree(getProject()!!)
|
||||
Disposer.register(getTestRootDisposable()!!, tree);
|
||||
|
||||
+36
-1
@@ -143,6 +143,7 @@ public class KotlinEvaluateExpressionTestGenerated extends AbstractKotlinEvaluat
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/debugger/tinyApp/src/evaluate/multipleBreakpoints")
|
||||
@InnerTestClasses({MultipleBreakpoints.Library.class})
|
||||
public static class MultipleBreakpoints extends AbstractKotlinEvaluateExpressionTest {
|
||||
public void testAllFilesPresentInMultipleBreakpoints() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/debugger/tinyApp/src/evaluate/multipleBreakpoints"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
@@ -178,6 +179,40 @@ public class KotlinEvaluateExpressionTestGenerated extends AbstractKotlinEvaluat
|
||||
doMultipleBreakpointsTest("idea/testData/debugger/tinyApp/src/evaluate/multipleBreakpoints/withoutBodyTypeParameters.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/debugger/tinyApp/src/evaluate/multipleBreakpoints/library")
|
||||
public static class Library extends AbstractKotlinEvaluateExpressionTest {
|
||||
public void testAllFilesPresentInLibrary() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/debugger/tinyApp/src/evaluate/multipleBreakpoints/library"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("customLibClassName.kt")
|
||||
public void testCustomLibClassName() throws Exception {
|
||||
doMultipleBreakpointsTest("idea/testData/debugger/tinyApp/src/evaluate/multipleBreakpoints/library/customLibClassName.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("stdlibDelegatedProperty.kt")
|
||||
public void testStdlibDelegatedProperty() throws Exception {
|
||||
doMultipleBreakpointsTest("idea/testData/debugger/tinyApp/src/evaluate/multipleBreakpoints/library/stdlibDelegatedProperty.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("stdlibRange.kt")
|
||||
public void testStdlibRange() throws Exception {
|
||||
doMultipleBreakpointsTest("idea/testData/debugger/tinyApp/src/evaluate/multipleBreakpoints/library/stdlibRange.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("stdlibSlice.kt")
|
||||
public void testStdlibSlice() throws Exception {
|
||||
doMultipleBreakpointsTest("idea/testData/debugger/tinyApp/src/evaluate/multipleBreakpoints/library/stdlibSlice.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Test innerSuite() {
|
||||
TestSuite suite = new TestSuite("MultipleBreakpoints");
|
||||
suite.addTestSuite(MultipleBreakpoints.class);
|
||||
suite.addTestSuite(Library.class);
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/debugger/tinyApp/src/evaluate/frame")
|
||||
@@ -261,7 +296,7 @@ public class KotlinEvaluateExpressionTestGenerated extends AbstractKotlinEvaluat
|
||||
public static Test suite() {
|
||||
TestSuite suite = new TestSuite("KotlinEvaluateExpressionTestGenerated");
|
||||
suite.addTestSuite(SingleBreakpoint.class);
|
||||
suite.addTestSuite(MultipleBreakpoints.class);
|
||||
suite.addTest(MultipleBreakpoints.innerSuite());
|
||||
suite.addTestSuite(Frame.class);
|
||||
return suite;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user