diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/DebugRunner.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/DebugRunner.kt index ceb5e5661a8..ae3d1ce0282 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/DebugRunner.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/DebugRunner.kt @@ -16,9 +16,7 @@ import org.jetbrains.kotlin.test.model.FrontendKinds import org.jetbrains.kotlin.test.model.TestModule import org.jetbrains.kotlin.test.services.TestServices import org.jetbrains.kotlin.test.services.sourceProviders.MainFunctionForBlackBoxTestsSourceProvider.Companion.BOX_MAIN_FILE_NAME -import org.jetbrains.kotlin.test.utils.SteppingTestLoggedData -import org.jetbrains.kotlin.test.utils.checkSteppingTestResult -import org.jetbrains.kotlin.test.utils.formatAsSteppingTestExpectation +import org.jetbrains.kotlin.test.utils.* import java.io.File import java.net.URL @@ -161,8 +159,8 @@ abstract class DebugRunner(testServices: TestServices) : JvmBoxRunner(testServic virtualMachine.resume() } - fun Location.formatAsExpectation() = - formatAsSteppingTestExpectation(sourceName(), lineNumber(), method().name(), method().isSynthetic) + fun Location.formatAsExpectation(visibleVars: List? = null) = + formatAsSteppingTestExpectation(sourceName(), lineNumber(), method().name(), method().isSynthetic, visibleVars) fun setupMethodEntryAndExitRequests(virtualMachine: VirtualMachine) { val manager = virtualMachine.eventRequestManager() @@ -204,40 +202,11 @@ class SteppingDebugRunner(testServices: TestServices) : DebugRunner(testServices } class LocalVariableDebugRunner(testServices: TestServices) : DebugRunner(testServices) { - interface LocalValue - - class LocalPrimitive(val value: String, val valueType: String) : LocalValue { - override fun toString(): String { - return "$value:$valueType" - } - } - - class LocalReference(val id: String, val referenceType: String) : LocalValue { - override fun toString(): String { - return referenceType - } - } - - class LocalNullValue : LocalValue { - override fun toString(): String { - return "null" - } - } - - class LocalVariableRecord( - val variable: String, - val variableType: String, - val value: LocalValue - ) { - override fun toString(): String { - return "$variable:$variableType=$value" - } - } private fun toRecord(frame: StackFrame, variable: LocalVariable): LocalVariableRecord { val value = frame.getValue(variable) val valueRecord = if (value == null) { - LocalNullValue() + LocalNullValue } else if (value is ObjectReference && value.referenceType().name() != "java.lang.String") { LocalReference(value.uniqueID().toString(), value.referenceType().name()) } else { @@ -269,7 +238,7 @@ class LocalVariableDebugRunner(testServices: TestServices) : DebugRunner(testSer SteppingTestLoggedData( location.lineNumber(), false, - "${location.formatAsExpectation()}: ${visibleVars.joinToString(", ")}".trim() + location.formatAsExpectation(visibleVars) ) ) } diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/utils/SteppingTestUtils.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/utils/SteppingTestUtils.kt index c4b6145b79b..e39038b655c 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/utils/SteppingTestUtils.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/utils/SteppingTestUtils.kt @@ -14,6 +14,42 @@ import java.io.File data class SteppingTestLoggedData(val line: Int, val isSynthetic: Boolean, val expectation: String) +sealed interface LocalValue + +class LocalPrimitive(val value: String, val valueType: String) : LocalValue { + override fun toString(): String { + return "$value:$valueType" + } +} + +class LocalReference(val id: String, val referenceType: String) : LocalValue { + override fun toString(): String { + return referenceType + } +} + +object LocalNullValue : LocalValue { + override fun toString(): String { + return "null" + } +} + +class LocalVariableRecord( + val variable: String, + val variableType: String?, + val value: LocalValue +) { + override fun toString(): String = buildString { + append(variable) + if (variableType != null) { + append(":") + append(variableType) + } + append("=") + append(value) + } +} + private const val EXPECTATIONS_MARKER = "// EXPECTATIONS" private const val FORCE_STEP_INTO_MARKER = "// FORCE_STEP_INTO" @@ -27,7 +63,7 @@ fun checkSteppingTestResult( val lines = wholeFile.readLines() val forceStepInto = lines.any { it.startsWith(FORCE_STEP_INTO_MARKER) } - val actualLineNumbers = compressSequencesWithoutLinenumber(loggedItems) + val actualLineNumbers = compressSequencesWithoutLineNumber(loggedItems) .filter { // Ignore synthetic code with no line number information unless force step into behavior is requested. forceStepInto || !it.isSynthetic @@ -88,7 +124,7 @@ fun checkSteppingTestResult( * print as byte offsets. This avoids overspecifying code generation * strategy in debug tests. */ -private fun compressSequencesWithoutLinenumber(loggedItems: List): List { +private fun compressSequencesWithoutLineNumber(loggedItems: List): List { if (loggedItems.isEmpty()) return listOf() val logIterator = loggedItems.iterator() @@ -105,7 +141,22 @@ private fun compressSequencesWithoutLinenumber(loggedItems: List? = null +) = buildString { + append(sourceName) + append(':') + append(lineNumber) + append(' ') + append(functionName) + if (isSynthetic) + append(" (synthetic)") + if (visibleVars != null) { + append(": ") + visibleVars.joinTo(this) + } +}.trim()