From 3a03cb48df8914fec6ca079a9ae52a2da7d12afa Mon Sep 17 00:00:00 2001 From: Natalia Ukhorskaya Date: Wed, 21 Jan 2015 15:34:24 +0300 Subject: [PATCH] Debugger Tests: create context in onBreakpoint method --- .../kotlin/idea/debugger/KotlinDebuggerTestBase.kt | 12 ++++++++++++ .../evaluate/AbstractKotlinEvaluateExpressionTest.kt | 7 +++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinDebuggerTestBase.kt b/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinDebuggerTestBase.kt index 82294481568..c20e5e7c040 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinDebuggerTestBase.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinDebuggerTestBase.kt @@ -27,6 +27,9 @@ import org.jetbrains.kotlin.idea.JetJdkAndLibraryProjectDescriptor import com.intellij.openapi.roots.JdkOrderEntry import com.intellij.openapi.util.io.FileUtil import com.intellij.debugger.SourcePosition +import kotlin.properties.Delegates +import com.intellij.debugger.engine.evaluation.EvaluationContextImpl +import com.intellij.debugger.impl.DebuggerContextImpl abstract class KotlinDebuggerTestBase : KotlinDebuggerTestCase() { @@ -35,6 +38,7 @@ abstract class KotlinDebuggerTestBase : KotlinDebuggerTestCase() { protected fun onBreakpoint(doOnBreakpoint: SuspendContextImpl.() -> Unit) { super.onBreakpoint { + initContexts(it) it.printContext() it.doOnBreakpoint() } @@ -44,6 +48,14 @@ abstract class KotlinDebuggerTestBase : KotlinDebuggerTestCase() { this.stepInto(false, null) } + protected var evaluationContext: EvaluationContextImpl by Delegates.notNull() + protected var debuggerContext: DebuggerContextImpl by Delegates.notNull() + + protected fun initContexts(suspendContext: SuspendContextImpl) { + evaluationContext = createEvaluationContext(suspendContext) + debuggerContext = createDebuggerContext(suspendContext) + } + protected fun SuspendContextImpl.stepInto(ignoreFilters: Boolean, smartStepFilter: MethodFilter?) { dp.getManagerThread()!!.schedule(dp.createStepIntoCommand(this, ignoreFilters, smartStepFilter)) } 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 e326cdc2def..fc707b871d3 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/AbstractKotlinEvaluateExpressionTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/AbstractKotlinEvaluateExpressionTest.kt @@ -219,12 +219,11 @@ public abstract class AbstractKotlinEvaluateExpressionTest : KotlinDebuggerTestB val tree = FrameVariablesTree(getProject()!!) Disposer.register(getTestRootDisposable()!!, tree); - val debuggerContext = createDebuggerContext(this) invokeRatherLater(this) { tree.rebuild(debuggerContext) expandAll(tree, Runnable { try { - Printer(debuggerContext).printTree(tree) + Printer().printTree(tree) } finally { resume(this@printFrame) @@ -233,7 +232,7 @@ public abstract class AbstractKotlinEvaluateExpressionTest : KotlinDebuggerTestB } } - private inner class Printer(val debuggerContext: DebuggerContextImpl) { + private inner class Printer() { fun printTree(tree: DebuggerTree) { val root = tree.getMutableModel()!!.getRoot() as DebuggerTreeNodeImpl printNode(root, 0) @@ -324,7 +323,7 @@ public abstract class AbstractKotlinEvaluateExpressionTest : KotlinDebuggerTestB if (evaluator == null) throw AssertionError("Cannot create an Evaluator for Evaluate Expression") - val value = evaluator.evaluate(createEvaluationContext(this)) + val value = evaluator.evaluate(evaluationContext) val actualResult = value.asValue().asString() Assert.assertTrue("Evaluate expression returns wrong result for $text:\nexpected = $expectedResult\nactual = $actualResult\n", expectedResult == actualResult)