diff --git a/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt b/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt index c8bb9ea73b3..33715325294 100644 --- a/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt +++ b/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt @@ -617,6 +617,7 @@ fun main(args: Array) { model("debugger/tinyApp/src/stepping/stepInto", testMethod = "doStepIntoTest", testClassName = "StepIntoOnly") model("debugger/tinyApp/src/stepping/stepOut", testMethod = "doStepOutTest") model("debugger/tinyApp/src/stepping/filters", testMethod = "doStepIntoTest") + model("debugger/tinyApp/src/stepping/custom", testMethod = "doCustomTest") } testClass(javaClass()) { diff --git a/idea/tests/org/jetbrains/kotlin/idea/debugger/AbstractKotlinSteppingTest.kt b/idea/tests/org/jetbrains/kotlin/idea/debugger/AbstractKotlinSteppingTest.kt index 24efb95f128..233b8feeecd 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/debugger/AbstractKotlinSteppingTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/debugger/AbstractKotlinSteppingTest.kt @@ -43,6 +43,29 @@ public abstract class AbstractKotlinSteppingTest : KotlinDebuggerTestBase() { doTest(path, "SMART_STEP_INTO") } + protected fun doCustomTest(path: String) { + val fileText = FileUtil.loadFile(File(path)) + configureSettings(fileText) + createAdditionalBreakpoints(fileText) + createDebugProcess(path) + + fun repeat(indexPrefix: String, f: SuspendContextImpl.() -> Unit) { + for (i in 1..(getPrefixedInt(fileText, indexPrefix) ?: 1)) { + onBreakpoint(f) + } + } + + File(path).readLines().forEach { + when { + it.startsWith("// STEP_INTO") -> repeat("// STEP_INTO: ") { stepInto() } + it.startsWith("// STEP_OUT") -> repeat("// STEP_OUT: ") { stepOut() } + it.startsWith("// SMART_STEP_INTO") -> repeat("// SMART_STEP_INTO: ") { smartStepInto() } + } + } + + finish() + } + private fun doTest(path: String, command: String) { val fileText = FileUtil.loadFile(File(path)) diff --git a/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinDebuggerTestBase.kt b/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinDebuggerTestBase.kt index 78ca3967e87..40cae78eb39 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinDebuggerTestBase.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinDebuggerTestBase.kt @@ -232,4 +232,40 @@ abstract class KotlinDebuggerTestBase : KotlinDebuggerTestCase() { runnable.invoke() } } + + protected 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()) + } } diff --git a/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinSteppingTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinSteppingTestGenerated.java index a15be2a3130..cc91f839772 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinSteppingTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinSteppingTestGenerated.java @@ -367,4 +367,19 @@ public class KotlinSteppingTestGenerated extends AbstractKotlinSteppingTest { doStepIntoTest(fileName); } } + + @TestMetadata("idea/testData/debugger/tinyApp/src/stepping/custom") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Custom extends AbstractKotlinSteppingTest { + public void testAllFilesPresentInCustom() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/debugger/tinyApp/src/stepping/custom"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("stepIntoStdlibInlineFun2step.kt") + public void testStepIntoStdlibInlineFun2step() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/stepping/custom/stepIntoStdlibInlineFun2step.kt"); + doCustomTest(fileName); + } + } } diff --git a/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/AbstractKotlinEvaluateExpressionTest.kt b/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/AbstractKotlinEvaluateExpressionTest.kt index 59e9454099a..62466ef1f9e 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/AbstractKotlinEvaluateExpressionTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/AbstractKotlinEvaluateExpressionTest.kt @@ -176,42 +176,6 @@ public abstract class AbstractKotlinEvaluateExpressionTest : KotlinDebuggerTestB 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);