From bf890a1540bcc0c2aa9d70bb8abafa2697f60e43 Mon Sep 17 00:00:00 2001 From: Yan Zhulanow Date: Thu, 6 Feb 2020 21:14:48 +0900 Subject: [PATCH] Debugger, tests: Change ADDITIONAL_BREAKPOINT directive format - Make it extendable and easier to parse - Allow to create additional function breakpoints --- .../debugger/test/util/BreakpointCreator.kt | 47 ++++++++++--------- .../isInsideInlineLambda.kt | 10 ++-- .../library/customLibClassName.kt | 10 ++-- .../library/localFunInLibrary.kt | 2 +- .../singleBreakpoint/breakpointInInlineFun.kt | 4 +- .../singleBreakpoint/fileWithError.kt | 2 +- .../inlineFunctionBreakpointAnotherFile.kt | 2 +- .../custom/manyFilesWithInlineCalls1.kt | 2 +- .../custom/manyFilesWithInlineCalls2.kt | 2 +- .../custom/severalInlineCallsFromOtherFile.kt | 2 +- .../custom/stepIntoStdlibInlineFun2step.kt | 2 +- .../stepping/stepOver/inlineInObject.kt | 2 +- .../stepOver/stopInInlineInOtherFile.kt | 2 +- ...opInInlineInOtherFileWithLambdaArgument.kt | 2 +- .../stepping/stepOver/stopInWrongClass.kt | 2 +- 15 files changed, 49 insertions(+), 44 deletions(-) diff --git a/idea/jvm-debugger/jvm-debugger-test/test/org/jetbrains/kotlin/idea/debugger/test/util/BreakpointCreator.kt b/idea/jvm-debugger/jvm-debugger-test/test/org/jetbrains/kotlin/idea/debugger/test/util/BreakpointCreator.kt index 454aa061a7f..648cbc7aa82 100644 --- a/idea/jvm-debugger/jvm-debugger-test/test/org/jetbrains/kotlin/idea/debugger/test/util/BreakpointCreator.kt +++ b/idea/jvm-debugger/jvm-debugger-test/test/org/jetbrains/kotlin/idea/debugger/test/util/BreakpointCreator.kt @@ -87,7 +87,7 @@ internal class BreakpointCreator( createLineBreakpoint(breakpointManager, file, lineIndex, ordinal, condition) } comment.startsWith("//FunctionBreakpoint!") -> { - createFunctionBreakpoint(breakpointManager, file, lineIndex) + createFunctionBreakpoint(breakpointManager, file, lineIndex, false) } else -> throw AssertionError("Cannot create breakpoint at line ${lineIndex + 1}") } @@ -104,19 +104,23 @@ internal class BreakpointCreator( fun createAdditionalBreakpoints(fileContents: String) { val breakpoints = findLinesWithPrefixesRemoved(fileContents, "// ADDITIONAL_BREAKPOINT: ") for (breakpoint in breakpoints) { - val position = breakpoint.split(".kt:") - assert(position.size == 2) { "Couldn't parse position from test directive: directive = $breakpoint" } + val chunks = breakpoint.split('/').map { it.trim() } + val fileName = chunks.getOrNull(0) ?: continue + val lineMarker = chunks.getOrNull(1) ?: continue + val kind = chunks.getOrElse(2) { "line" } + val ordinal = chunks.getOrNull(3)?.toInt() - var lineMarker = position[1] - var ordinal: Int? = null + val breakpointManager = XDebuggerManager.getInstance(project).breakpointManager - if (lineMarker.contains(":(") && lineMarker.endsWith(")")) { - val lineMarkerAndOrdinal = lineMarker.split(":(") - lineMarker = lineMarkerAndOrdinal[0] - ordinal = lineMarkerAndOrdinal[1].substringBefore(")").toInt() + when (kind) { + "line" -> createBreakpoint(fileName, lineMarker) { psiFile, lineNumber -> + createLineBreakpoint(breakpointManager, psiFile, lineNumber + 1, ordinal, null) + } + "fun" -> createBreakpoint(fileName, lineMarker) { psiFile, lineNumber -> + createFunctionBreakpoint(breakpointManager, psiFile, lineNumber, true) + } + else -> error("Unknown breakpoint kind: $kind") } - - createBreakpoint(position[0], lineMarker, ordinal) } } @@ -133,34 +137,35 @@ internal class BreakpointCreator( return null } - private fun createBreakpoint(fileName: String, lineMarker: String, ordinal: Int?) { + private fun createBreakpoint(fileName: String, lineMarker: String, action: (PsiFile, Int) -> Unit) { val sourceFiles = runReadAction { FilenameIndex.getAllFilesByExt(project, "kt") - .filter { it.name.contains(fileName) && it.contentsToByteArray().toString(Charsets.UTF_8).contains(lineMarker) } + .filter { it.name == fileName && it.contentsToByteArray().toString(Charsets.UTF_8).contains(lineMarker) } } - assert(sourceFiles.size == 1) { "One source file should be found: name = $fileName, sourceFiles = $sourceFiles" } + val sourceFile = sourceFiles.singleOrNull() + ?: error("Single source file should be found: name = $fileName, sourceFiles = $sourceFiles") val runnable = Runnable { - val psiSourceFile = PsiManager.getInstance(project).findFile(sourceFiles.first())!! + val psiSourceFile = PsiManager.getInstance(project).findFile(sourceFile) + ?: error("Psi file not found for $sourceFile") - val breakpointManager = XDebuggerManager.getInstance(project).breakpointManager val document = PsiDocumentManager.getInstance(project).getDocument(psiSourceFile)!! val index = psiSourceFile.text!!.indexOf(lineMarker) - val lineNumber = document.getLineNumber(index) + 1 // lineMarker is for previous line - - createLineBreakpoint(breakpointManager, psiSourceFile, lineNumber, ordinal, null) + val lineNumber = document.getLineNumber(index) + action(psiSourceFile, lineNumber) } DebuggerInvocationUtil.invokeAndWait(project, runnable, ModalityState.defaultModalityState()) } - private fun createFunctionBreakpoint(breakpointManager: XBreakpointManager, file: PsiFile, lineIndex: Int) { + private fun createFunctionBreakpoint(breakpointManager: XBreakpointManager, file: PsiFile, lineIndex: Int, fromLibrary: Boolean) { val breakpointType = findBreakpointType(KotlinFunctionBreakpointType::class.java) val breakpoint = createBreakpointOfType(breakpointManager, breakpointType, lineIndex, file.virtualFile) if (breakpoint is KotlinFunctionBreakpoint) { - logger("FunctionBreakpoint created at ${file.virtualFile.name}:${lineIndex + 1}") + val lineNumberSuffix = if (fromLibrary) "" else ":${lineIndex + 1}" + logger("FunctionBreakpoint created at ${file.virtualFile.name}$lineNumberSuffix") } } diff --git a/idea/jvm-debugger/jvm-debugger-test/testData/evaluation/multipleBreakpoints/isInsideInlineLambda.kt b/idea/jvm-debugger/jvm-debugger-test/testData/evaluation/multipleBreakpoints/isInsideInlineLambda.kt index 6d115df1d19..5d1c4f027eb 100644 --- a/idea/jvm-debugger/jvm-debugger-test/testData/evaluation/multipleBreakpoints/isInsideInlineLambda.kt +++ b/idea/jvm-debugger/jvm-debugger-test/testData/evaluation/multipleBreakpoints/isInsideInlineLambda.kt @@ -55,23 +55,23 @@ class A { } } -// ADDITIONAL_BREAKPOINT: isInsideInlineLambdaInLibrary.kt:Breakpoint1:(1) +// ADDITIONAL_BREAKPOINT: isInsideInlineLambdaInLibrary.kt / Breakpoint1 / line / 1 // EXPRESSION: it + 11 // RESULT: 12: I -// ADDITIONAL_BREAKPOINT: isInsideInlineLambdaInLibrary.kt:Breakpoint2:(1) +// ADDITIONAL_BREAKPOINT: isInsideInlineLambdaInLibrary.kt / Breakpoint2 / line / 1 // EXPRESSION: it + 12 // RESULT: 14: I -// ADDITIONAL_BREAKPOINT: isInsideInlineLambdaInLibrary.kt:Breakpoint3:(1) +// ADDITIONAL_BREAKPOINT: isInsideInlineLambdaInLibrary.kt / Breakpoint3 / line / 1 // EXPRESSION: it + 13 // RESULT: 16: I -// ADDITIONAL_BREAKPOINT: isInsideInlineLambdaInLibrary.kt:Breakpoint4:(1) +// ADDITIONAL_BREAKPOINT: isInsideInlineLambdaInLibrary.kt / Breakpoint4 / line / 1 // EXPRESSION: it + 14 // RESULT: 18: I -// ADDITIONAL_BREAKPOINT: isInsideInlineLambdaInLibrary.kt:Breakpoint5:(1) +// ADDITIONAL_BREAKPOINT: isInsideInlineLambdaInLibrary.kt / Breakpoint5 / line / 1 // EXPRESSION: it + 15 // RESULT: 20: I diff --git a/idea/jvm-debugger/jvm-debugger-test/testData/evaluation/multipleBreakpoints/library/customLibClassName.kt b/idea/jvm-debugger/jvm-debugger-test/testData/evaluation/multipleBreakpoints/library/customLibClassName.kt index f3c9cd80377..ad63caf6d71 100644 --- a/idea/jvm-debugger/jvm-debugger-test/testData/evaluation/multipleBreakpoints/library/customLibClassName.kt +++ b/idea/jvm-debugger/jvm-debugger-test/testData/evaluation/multipleBreakpoints/library/customLibClassName.kt @@ -9,23 +9,23 @@ fun main(args: Array) { customLib.simpleLibFile.foo() } -// ADDITIONAL_BREAKPOINT: 1.kt:public fun oneFunSameFileNameFun(): Int { +// ADDITIONAL_BREAKPOINT: a1.kt / public fun oneFunSameFileNameFun(): Int { // EXPRESSION: 1 + 1 // RESULT: 2: I -// ADDITIONAL_BREAKPOINT: 1.kt:public fun twoFunDifferentSignatureFun(): Int { +// ADDITIONAL_BREAKPOINT: a1.kt / public fun twoFunDifferentSignatureFun(): Int { // EXPRESSION: 1 + 2 // RESULT: 3: I -// ADDITIONAL_BREAKPOINT: 1.kt:public val foo: Int = +// ADDITIONAL_BREAKPOINT: a1.kt / public val foo: Int = // EXPRESSION: 1 + 3 // RESULT: 4: I -// ADDITIONAL_BREAKPOINT: 1.kt:public fun breakpointOnLocalPropertyFun(): Int { +// ADDITIONAL_BREAKPOINT: a1.kt / public fun breakpointOnLocalPropertyFun(): Int { // EXPRESSION: 1 + 4 // RESULT: 5: I -// ADDITIONAL_BREAKPOINT: simpleLibFile.kt:public fun foo() { +// ADDITIONAL_BREAKPOINT: simpleLibFile.kt / public fun foo() { // EXPRESSION: 1 + 5 // RESULT: 6: I diff --git a/idea/jvm-debugger/jvm-debugger-test/testData/evaluation/multipleBreakpoints/library/localFunInLibrary.kt b/idea/jvm-debugger/jvm-debugger-test/testData/evaluation/multipleBreakpoints/library/localFunInLibrary.kt index 50162588180..b3f516045a4 100644 --- a/idea/jvm-debugger/jvm-debugger-test/testData/evaluation/multipleBreakpoints/library/localFunInLibrary.kt +++ b/idea/jvm-debugger/jvm-debugger-test/testData/evaluation/multipleBreakpoints/library/localFunInLibrary.kt @@ -5,7 +5,7 @@ fun main(args: Array) { customLib.localFunInLibraryCustomLib.localFunInLibraryCustomLibMainFun() } -// ADDITIONAL_BREAKPOINT: localFunCustomLib.kt:localFunInLibraryCustomLibProperty +// ADDITIONAL_BREAKPOINT: localFunCustomLib.kt / localFunInLibraryCustomLibProperty // EXPRESSION: localFun() // RESULT: 1: I diff --git a/idea/jvm-debugger/jvm-debugger-test/testData/evaluation/singleBreakpoint/breakpointInInlineFun.kt b/idea/jvm-debugger/jvm-debugger-test/testData/evaluation/singleBreakpoint/breakpointInInlineFun.kt index f253ed1f376..4af9e8c54fe 100644 --- a/idea/jvm-debugger/jvm-debugger-test/testData/evaluation/singleBreakpoint/breakpointInInlineFun.kt +++ b/idea/jvm-debugger/jvm-debugger-test/testData/evaluation/singleBreakpoint/breakpointInInlineFun.kt @@ -9,8 +9,8 @@ fun main(args: Array) { // RESUME: 2 -// ADDITIONAL_BREAKPOINT: inlineFunInLibrary.kt:public inline fun inlineFun -// ADDITIONAL_BREAKPOINT: inlineFunInLibrary.kt: Breakpoint 2 +// ADDITIONAL_BREAKPOINT: inlineFunInLibrary.kt / public inline fun inlineFun +// ADDITIONAL_BREAKPOINT: inlineFunInLibrary.kt / Breakpoint 2 // FILE: customLib/inlineFunInLibrary/inlineFunInLibrary.kt package customLib.inlineFunInLibrary diff --git a/idea/jvm-debugger/jvm-debugger-test/testData/evaluation/singleBreakpoint/fileWithError.kt b/idea/jvm-debugger/jvm-debugger-test/testData/evaluation/singleBreakpoint/fileWithError.kt index 63fe56a2855..304b188fa4b 100644 --- a/idea/jvm-debugger/jvm-debugger-test/testData/evaluation/singleBreakpoint/fileWithError.kt +++ b/idea/jvm-debugger/jvm-debugger-test/testData/evaluation/singleBreakpoint/fileWithError.kt @@ -6,7 +6,7 @@ fun main(args: Array) { fileWithInternal.test() } -// ADDITIONAL_BREAKPOINT: fileWithInternal.kt:Breakpoint +// ADDITIONAL_BREAKPOINT: fileWithInternal.kt / Breakpoint // EXPRESSION: 1 // RESULT: 1: I diff --git a/idea/jvm-debugger/jvm-debugger-test/testData/evaluation/singleBreakpoint/inlineFunctionBreakpointAnotherFile.kt b/idea/jvm-debugger/jvm-debugger-test/testData/evaluation/singleBreakpoint/inlineFunctionBreakpointAnotherFile.kt index 3736f84a0bf..923c7ceeb83 100644 --- a/idea/jvm-debugger/jvm-debugger-test/testData/evaluation/singleBreakpoint/inlineFunctionBreakpointAnotherFile.kt +++ b/idea/jvm-debugger/jvm-debugger-test/testData/evaluation/singleBreakpoint/inlineFunctionBreakpointAnotherFile.kt @@ -11,7 +11,7 @@ fun main(args: Array) { } } -// ADDITIONAL_BREAKPOINT: inlineFunctionWithBreakpoint.kt:inline fun myFun +// ADDITIONAL_BREAKPOINT: inlineFunctionWithBreakpoint.kt / inline fun myFun // FILE: inlineFunctionWithBreakpoint.kt package inlineFunctionWithBreakpoint diff --git a/idea/jvm-debugger/jvm-debugger-test/testData/stepping/custom/manyFilesWithInlineCalls1.kt b/idea/jvm-debugger/jvm-debugger-test/testData/stepping/custom/manyFilesWithInlineCalls1.kt index 1e9f8907327..c328381440a 100644 --- a/idea/jvm-debugger/jvm-debugger-test/testData/stepping/custom/manyFilesWithInlineCalls1.kt +++ b/idea/jvm-debugger/jvm-debugger-test/testData/stepping/custom/manyFilesWithInlineCalls1.kt @@ -12,7 +12,7 @@ fun unused() { secondInline() } -// ADDITIONAL_BREAKPOINT: manyFilesWithInlineCalls1.First.kt: Breakpoint 1 +// ADDITIONAL_BREAKPOINT: manyFilesWithInlineCalls1.First.kt / Breakpoint 1 // FILE: manyFilesWithInlineCalls1.First.kt package manyFilesWithInlineCalls1.first diff --git a/idea/jvm-debugger/jvm-debugger-test/testData/stepping/custom/manyFilesWithInlineCalls2.kt b/idea/jvm-debugger/jvm-debugger-test/testData/stepping/custom/manyFilesWithInlineCalls2.kt index 2a703b435f9..74852880a04 100644 --- a/idea/jvm-debugger/jvm-debugger-test/testData/stepping/custom/manyFilesWithInlineCalls2.kt +++ b/idea/jvm-debugger/jvm-debugger-test/testData/stepping/custom/manyFilesWithInlineCalls2.kt @@ -12,7 +12,7 @@ fun unused() { firstInline() } -// ADDITIONAL_BREAKPOINT: manyFilesWithInlineCalls2.Second.kt: Breakpoint 1 +// ADDITIONAL_BREAKPOINT: manyFilesWithInlineCalls2.Second.kt / Breakpoint 1 // FILE: manyFilesWithInlineCalls2.First.kt package manyFilesWithInlineCalls2.first diff --git a/idea/jvm-debugger/jvm-debugger-test/testData/stepping/custom/severalInlineCallsFromOtherFile.kt b/idea/jvm-debugger/jvm-debugger-test/testData/stepping/custom/severalInlineCallsFromOtherFile.kt index 777c6ac33a4..587d967bd6a 100644 --- a/idea/jvm-debugger/jvm-debugger-test/testData/stepping/custom/severalInlineCallsFromOtherFile.kt +++ b/idea/jvm-debugger/jvm-debugger-test/testData/stepping/custom/severalInlineCallsFromOtherFile.kt @@ -16,7 +16,7 @@ fun secondCall() { } // RESUME: 2 -// ADDITIONAL_BREAKPOINT: severalInlineCallsFromOtherFile.Other.kt: Breakpoint 1 +// ADDITIONAL_BREAKPOINT: severalInlineCallsFromOtherFile.Other.kt / Breakpoint 1 // FILE: severalInlineCallsFromOtherFile.Other.kt package severalInlineCallsFromOtherFile diff --git a/idea/jvm-debugger/jvm-debugger-test/testData/stepping/custom/stepIntoStdlibInlineFun2step.kt b/idea/jvm-debugger/jvm-debugger-test/testData/stepping/custom/stepIntoStdlibInlineFun2step.kt index 6c7ea7e122e..150419d5603 100644 --- a/idea/jvm-debugger/jvm-debugger-test/testData/stepping/custom/stepIntoStdlibInlineFun2step.kt +++ b/idea/jvm-debugger/jvm-debugger-test/testData/stepping/custom/stepIntoStdlibInlineFun2step.kt @@ -5,7 +5,7 @@ fun main(args: Array) { customLib.functionInLibrary.simpleFun() } -// ADDITIONAL_BREAKPOINT: functionInLibrary.kt:public inline fun simpleFun() +// ADDITIONAL_BREAKPOINT: functionInLibrary.kt / public inline fun simpleFun() // STEP_INTO: 5 // FILE: customLib/functionInLibrary/functionInLibrary.kt diff --git a/idea/jvm-debugger/jvm-debugger-test/testData/stepping/stepOver/inlineInObject.kt b/idea/jvm-debugger/jvm-debugger-test/testData/stepping/stepOver/inlineInObject.kt index 80d3f1f022a..61f075a66c3 100644 --- a/idea/jvm-debugger/jvm-debugger-test/testData/stepping/stepOver/inlineInObject.kt +++ b/idea/jvm-debugger/jvm-debugger-test/testData/stepping/stepOver/inlineInObject.kt @@ -5,7 +5,7 @@ fun main(args: Array) { inlineInObject.other.TestInlineInObject.inlineFun() } -// ADDITIONAL_BREAKPOINT: inlineInObject.Other.kt: Breakpoint 1 +// ADDITIONAL_BREAKPOINT: inlineInObject.Other.kt / Breakpoint 1 // FILE: inlineInObject.Other.kt package inlineInObject.other diff --git a/idea/jvm-debugger/jvm-debugger-test/testData/stepping/stepOver/stopInInlineInOtherFile.kt b/idea/jvm-debugger/jvm-debugger-test/testData/stepping/stepOver/stopInInlineInOtherFile.kt index a3db59770d0..e9f1d6903bf 100644 --- a/idea/jvm-debugger/jvm-debugger-test/testData/stepping/stepOver/stopInInlineInOtherFile.kt +++ b/idea/jvm-debugger/jvm-debugger-test/testData/stepping/stepOver/stopInInlineInOtherFile.kt @@ -5,7 +5,7 @@ fun main(args: Array) { inlineFun() } -// ADDITIONAL_BREAKPOINT: stopInInlineInOtherFile.Other.kt: Breakpoint 1 +// ADDITIONAL_BREAKPOINT: stopInInlineInOtherFile.Other.kt / Breakpoint 1 // FILE: stopInInlineInOtherFile.Other.kt package stopInInlineInOtherFile diff --git a/idea/jvm-debugger/jvm-debugger-test/testData/stepping/stepOver/stopInInlineInOtherFileWithLambdaArgument.kt b/idea/jvm-debugger/jvm-debugger-test/testData/stepping/stepOver/stopInInlineInOtherFileWithLambdaArgument.kt index 6dd259e2acc..38dee5c4c59 100644 --- a/idea/jvm-debugger/jvm-debugger-test/testData/stepping/stepOver/stopInInlineInOtherFileWithLambdaArgument.kt +++ b/idea/jvm-debugger/jvm-debugger-test/testData/stepping/stepOver/stopInInlineInOtherFileWithLambdaArgument.kt @@ -6,7 +6,7 @@ fun main(args: Array) { val i = 1 } -// ADDITIONAL_BREAKPOINT: stopInInlineInOtherFileWithLambdaArgument.Other.kt: Breakpoint 1 +// ADDITIONAL_BREAKPOINT: stopInInlineInOtherFileWithLambdaArgument.Other.kt / Breakpoint 1 // FILE: stopInInlineInOtherFileWithLambdaArgument.Other.kt package stopInInlineInOtherFileWithLambdaArgument diff --git a/idea/jvm-debugger/jvm-debugger-test/testData/stepping/stepOver/stopInWrongClass.kt b/idea/jvm-debugger/jvm-debugger-test/testData/stepping/stepOver/stopInWrongClass.kt index cb5ff285c18..6ad6886ddef 100644 --- a/idea/jvm-debugger/jvm-debugger-test/testData/stepping/stepOver/stopInWrongClass.kt +++ b/idea/jvm-debugger/jvm-debugger-test/testData/stepping/stepOver/stopInWrongClass.kt @@ -19,7 +19,7 @@ fun main(args: Array) { AA().other() } -// ADDITIONAL_BREAKPOINT: stopInWrongClass.Other.kt: Breakpoint 1 +// ADDITIONAL_BREAKPOINT: stopInWrongClass.Other.kt / Breakpoint 1 // FILE: stopInWrongClass.Other.kt package stopInWrongClass