Tests: extract base class

This commit is contained in:
Natalia Ukhorskaya
2014-09-11 14:15:15 +04:00
parent b6abd6442a
commit a1e586cf7c
2 changed files with 55 additions and 33 deletions
@@ -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<KotlinDebuggerTestCase>.initApplication()
super.initApplication()
saveDefaultSettings()
}
override fun tearDown() {
super<KotlinDebuggerTestCase>.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<BasicStepMethodFilter> {
val breakpointManager = DebuggerManagerEx.getInstanceEx(getProject())?.getBreakpointManager()
val breakpoint = breakpointManager?.getBreakpoints()?.first { it is LineBreakpoint }
@@ -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)
}
}
}