From a1e586cf7cb55f12f77465b1f6602efdf7351a9b Mon Sep 17 00:00:00 2001 From: Natalia Ukhorskaya Date: Thu, 11 Sep 2014 14:15:15 +0400 Subject: [PATCH] Tests: extract base class --- .../debugger/AbstractKotlinSteppingTest.kt | 36 ++----------- .../plugin/debugger/KotlinDebuggerTestBase.kt | 52 +++++++++++++++++++ 2 files changed, 55 insertions(+), 33 deletions(-) create mode 100644 idea/tests/org/jetbrains/jet/plugin/debugger/KotlinDebuggerTestBase.kt diff --git a/idea/tests/org/jetbrains/jet/plugin/debugger/AbstractKotlinSteppingTest.kt b/idea/tests/org/jetbrains/jet/plugin/debugger/AbstractKotlinSteppingTest.kt index d766564890a..0d8732a8f9b 100644 --- a/idea/tests/org/jetbrains/jet/plugin/debugger/AbstractKotlinSteppingTest.kt +++ b/idea/tests/org/jetbrains/jet/plugin/debugger/AbstractKotlinSteppingTest.kt @@ -17,8 +17,6 @@ package org.jetbrains.jet.plugin.debugger import com.intellij.debugger.engine.SuspendContextImpl -import com.intellij.debugger.engine.MethodFilter -import com.intellij.debugger.engine.DebugProcessImpl import org.jetbrains.jet.plugin.debugger.KotlinSmartStepIntoHandler.KotlinMethodSmartStepTarget import org.jetbrains.jet.plugin.debugger.KotlinSmartStepIntoHandler.KotlinBasicStepMethodFilter import com.intellij.debugger.DebuggerManagerEx @@ -32,18 +30,18 @@ import java.io.File import kotlin.properties.Delegates import com.intellij.debugger.settings.DebuggerSettings -public abstract class AbstractKotlinSteppingTest : KotlinDebuggerTestCase() { +public abstract class AbstractKotlinSteppingTest : KotlinDebuggerTestBase() { private var oldSettings: DebuggerSettings by Delegates.notNull() private var oldIsFilterForStdlibAlreadyAdded: Boolean by Delegates.notNull() private var oldDisableKoltinInternalClasses: Boolean by Delegates.notNull() override fun initApplication() { - super.initApplication() + super.initApplication() saveDefaultSettings() } override fun tearDown() { - super.tearDown() + super.tearDown() restoreDefaultSettings() } @@ -99,44 +97,16 @@ public abstract class AbstractKotlinSteppingTest : KotlinDebuggerTestCase() { debuggerSettings.TRACING_FILTERS_ENABLED = oldSettings.TRACING_FILTERS_ENABLED } - private val dp: DebugProcessImpl - get() = getDebugProcess() ?: throw AssertionError("createLocalProcess() should be called before getDebugProcess()") - - private fun onBreakpoint(doOnBreakpoint: SuspendContextImpl.() -> Unit) { - super.onBreakpoint { - it.printContext() - it.doOnBreakpoint() - } - } - private fun SuspendContextImpl.smartStepInto() { this.smartStepInto(false) } - private fun SuspendContextImpl.stepInto() { - this.stepInto(false, null) - } - - private fun SuspendContextImpl.stepInto(ignoreFilters: Boolean, smartStepFilter: MethodFilter?) { - dp.getManagerThread()!!.schedule(dp.createStepIntoCommand(this, ignoreFilters, smartStepFilter)) - } - private fun SuspendContextImpl.smartStepInto(ignoreFilters: Boolean) { createSmartStepIntoFilters().forEach { dp.getManagerThread()!!.schedule(dp.createStepIntoCommand(this, ignoreFilters, it)) } } - private fun SuspendContextImpl.printContext() { - printContext(this) - } - - private fun finish() { - onBreakpoint { - resume(this) - } - } - private fun createSmartStepIntoFilters(): List { val breakpointManager = DebuggerManagerEx.getInstanceEx(getProject())?.getBreakpointManager() val breakpoint = breakpointManager?.getBreakpoints()?.first { it is LineBreakpoint } diff --git a/idea/tests/org/jetbrains/jet/plugin/debugger/KotlinDebuggerTestBase.kt b/idea/tests/org/jetbrains/jet/plugin/debugger/KotlinDebuggerTestBase.kt new file mode 100644 index 00000000000..943c37b5299 --- /dev/null +++ b/idea/tests/org/jetbrains/jet/plugin/debugger/KotlinDebuggerTestBase.kt @@ -0,0 +1,52 @@ +/* + * Copyright 2010-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.plugin.debugger + +import com.intellij.debugger.engine.DebugProcessImpl +import com.intellij.debugger.engine.SuspendContextImpl +import com.intellij.debugger.engine.MethodFilter + +abstract class KotlinDebuggerTestBase : KotlinDebuggerTestCase() { + + protected val dp: DebugProcessImpl + get() = getDebugProcess() ?: throw AssertionError("createLocalProcess() should be called before getDebugProcess()") + + protected fun onBreakpoint(doOnBreakpoint: SuspendContextImpl.() -> Unit) { + super.onBreakpoint { + it.printContext() + it.doOnBreakpoint() + } + } + + protected fun SuspendContextImpl.stepInto() { + this.stepInto(false, null) + } + + protected fun SuspendContextImpl.stepInto(ignoreFilters: Boolean, smartStepFilter: MethodFilter?) { + dp.getManagerThread()!!.schedule(dp.createStepIntoCommand(this, ignoreFilters, smartStepFilter)) + } + + protected fun SuspendContextImpl.printContext() { + printContext(this) + } + + protected fun finish() { + onBreakpoint { + resume(this) + } + } +} \ No newline at end of file