Debugger Tests: create context in onBreakpoint method

This commit is contained in:
Natalia Ukhorskaya
2015-01-21 15:34:24 +03:00
parent 03e076aba3
commit 3a03cb48df
2 changed files with 15 additions and 4 deletions
@@ -27,6 +27,9 @@ import org.jetbrains.kotlin.idea.JetJdkAndLibraryProjectDescriptor
import com.intellij.openapi.roots.JdkOrderEntry import com.intellij.openapi.roots.JdkOrderEntry
import com.intellij.openapi.util.io.FileUtil import com.intellij.openapi.util.io.FileUtil
import com.intellij.debugger.SourcePosition 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() { abstract class KotlinDebuggerTestBase : KotlinDebuggerTestCase() {
@@ -35,6 +38,7 @@ abstract class KotlinDebuggerTestBase : KotlinDebuggerTestCase() {
protected fun onBreakpoint(doOnBreakpoint: SuspendContextImpl.() -> Unit) { protected fun onBreakpoint(doOnBreakpoint: SuspendContextImpl.() -> Unit) {
super.onBreakpoint { super.onBreakpoint {
initContexts(it)
it.printContext() it.printContext()
it.doOnBreakpoint() it.doOnBreakpoint()
} }
@@ -44,6 +48,14 @@ abstract class KotlinDebuggerTestBase : KotlinDebuggerTestCase() {
this.stepInto(false, null) 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?) { protected fun SuspendContextImpl.stepInto(ignoreFilters: Boolean, smartStepFilter: MethodFilter?) {
dp.getManagerThread()!!.schedule(dp.createStepIntoCommand(this, ignoreFilters, smartStepFilter)) dp.getManagerThread()!!.schedule(dp.createStepIntoCommand(this, ignoreFilters, smartStepFilter))
} }
@@ -219,12 +219,11 @@ public abstract class AbstractKotlinEvaluateExpressionTest : KotlinDebuggerTestB
val tree = FrameVariablesTree(getProject()!!) val tree = FrameVariablesTree(getProject()!!)
Disposer.register(getTestRootDisposable()!!, tree); Disposer.register(getTestRootDisposable()!!, tree);
val debuggerContext = createDebuggerContext(this)
invokeRatherLater(this) { invokeRatherLater(this) {
tree.rebuild(debuggerContext) tree.rebuild(debuggerContext)
expandAll(tree, Runnable { expandAll(tree, Runnable {
try { try {
Printer(debuggerContext).printTree(tree) Printer().printTree(tree)
} }
finally { finally {
resume(this@printFrame) 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) { fun printTree(tree: DebuggerTree) {
val root = tree.getMutableModel()!!.getRoot() as DebuggerTreeNodeImpl val root = tree.getMutableModel()!!.getRoot() as DebuggerTreeNodeImpl
printNode(root, 0) printNode(root, 0)
@@ -324,7 +323,7 @@ public abstract class AbstractKotlinEvaluateExpressionTest : KotlinDebuggerTestB
if (evaluator == null) throw AssertionError("Cannot create an Evaluator for Evaluate Expression") 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() val actualResult = value.asValue().asString()
Assert.assertTrue("Evaluate expression returns wrong result for $text:\nexpected = $expectedResult\nactual = $actualResult\n", expectedResult == actualResult) Assert.assertTrue("Evaluate expression returns wrong result for $text:\nexpected = $expectedResult\nactual = $actualResult\n", expectedResult == actualResult)