From 6095faed14621f28c92c2c61fa032aca8406fae4 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Fri, 27 Jun 2014 04:20:58 +0400 Subject: [PATCH] Make debugger tests work with Idea 14 --- .../debugger/AbstractKotlinSteppingTest.kt | 32 ++++++------- .../debugger/AbstractSmartStepIntoTest.kt | 5 +- .../debugger/KotlinDebuggerTestCase.java | 9 ++++ .../AbstractKotlinEvaluateExpressionTest.kt | 48 +++++++++++-------- 4 files changed, 54 insertions(+), 40 deletions(-) diff --git a/idea/tests/org/jetbrains/jet/plugin/debugger/AbstractKotlinSteppingTest.kt b/idea/tests/org/jetbrains/jet/plugin/debugger/AbstractKotlinSteppingTest.kt index c475b718c03..0b04ddce78d 100644 --- a/idea/tests/org/jetbrains/jet/plugin/debugger/AbstractKotlinSteppingTest.kt +++ b/idea/tests/org/jetbrains/jet/plugin/debugger/AbstractKotlinSteppingTest.kt @@ -18,21 +18,15 @@ package org.jetbrains.jet.plugin.debugger import com.intellij.debugger.engine.SuspendContextImpl import com.intellij.debugger.engine.MethodFilter -import com.intellij.debugger.engine.StackFrameContext 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.jdi.StackFrameProxyImpl -import com.intellij.debugger.SourcePosition -import com.intellij.psi.PsiElement import com.intellij.debugger.DebuggerManagerEx import com.intellij.debugger.ui.breakpoints.LineBreakpoint -import com.intellij.psi.PsiFile -import org.jetbrains.jet.lang.resolve.java.PackageClassUtils -import org.jetbrains.jet.lang.resolve.name.FqName -import java.io.File import com.intellij.debugger.actions.MethodSmartStepTarget import com.intellij.debugger.engine.BasicStepMethodFilter +import com.intellij.openapi.application.ApplicationManager +import com.intellij.openapi.util.Computable abstract class AbstractKotlinSteppingTest : KotlinDebuggerTestCase() { @@ -92,19 +86,21 @@ abstract class AbstractKotlinSteppingTest : KotlinDebuggerTestCase() { val line = (breakpoint as LineBreakpoint).getLineIndex() - val containingFile = breakpoint.getPsiFile() - if (containingFile == null) throw AssertionError("Couldn't find file for breakpoint at the line $line") + return ApplicationManager.getApplication()?.runReadAction(Computable { + val containingFile = breakpoint.getPsiFile() + if (containingFile == null) throw AssertionError("Couldn't find file for breakpoint at the line $line") - val position = MockSourcePosition(_file = containingFile, _line = line) + val position = MockSourcePosition(_file = containingFile, _line = line) - val stepTargets = KotlinSmartStepIntoHandler().findSmartStepTargets(position) + val stepTargets = KotlinSmartStepIntoHandler().findSmartStepTargets(position) - return stepTargets.filterIsInstance(javaClass()).map { - stepTarget -> - when (stepTarget) { - is KotlinMethodSmartStepTarget -> KotlinBasicStepMethodFilter(stepTarget as KotlinMethodSmartStepTarget) - else -> BasicStepMethodFilter(stepTarget.getMethod(), stepTarget.getCallingExpressionLines()) + stepTargets.filterIsInstance(javaClass()).map { + stepTarget -> + when (stepTarget) { + is KotlinMethodSmartStepTarget -> KotlinBasicStepMethodFilter(stepTarget as KotlinMethodSmartStepTarget) + else -> BasicStepMethodFilter(stepTarget.getMethod(), stepTarget.getCallingExpressionLines()) + } } - } + })!! } } diff --git a/idea/tests/org/jetbrains/jet/plugin/debugger/AbstractSmartStepIntoTest.kt b/idea/tests/org/jetbrains/jet/plugin/debugger/AbstractSmartStepIntoTest.kt index 9b70b5b983d..7c6d1d558f7 100644 --- a/idea/tests/org/jetbrains/jet/plugin/debugger/AbstractSmartStepIntoTest.kt +++ b/idea/tests/org/jetbrains/jet/plugin/debugger/AbstractSmartStepIntoTest.kt @@ -25,10 +25,11 @@ import org.jetbrains.jet.InTextDirectivesUtils import com.intellij.psi.util.PsiFormatUtil import com.intellij.psi.PsiSubstitutor import com.intellij.psi.util.PsiFormatUtilBase +import org.jetbrains.jet.plugin.JetLightCodeInsightFixtureTestCase -abstract class AbstractSmartStepIntoTest : LightCodeInsightFixtureTestCase() { +abstract class AbstractSmartStepIntoTest : JetLightCodeInsightFixtureTestCase() { private val fixture: JavaCodeInsightTestFixture - get() = myFixture!! + get() = myFixture protected fun doTest(path: String) { fixture.configureByFile(path) diff --git a/idea/tests/org/jetbrains/jet/plugin/debugger/KotlinDebuggerTestCase.java b/idea/tests/org/jetbrains/jet/plugin/debugger/KotlinDebuggerTestCase.java index 149492f7b15..ffc12489b25 100644 --- a/idea/tests/org/jetbrains/jet/plugin/debugger/KotlinDebuggerTestCase.java +++ b/idea/tests/org/jetbrains/jet/plugin/debugger/KotlinDebuggerTestCase.java @@ -26,12 +26,14 @@ import com.intellij.openapi.roots.OrderRootType; import com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor; import com.intellij.openapi.util.Computable; import com.intellij.openapi.vfs.VfsUtil; +import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess; import com.intellij.psi.JavaPsiFacade; import com.intellij.psi.PsiClass; import com.intellij.psi.PsiElement; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.testFramework.UsefulTestCase; import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.JetTestCaseBuilder; import org.jetbrains.jet.JetTestUtils; import org.jetbrains.jet.MockLibraryUtil; import org.jetbrains.jet.asJava.KotlinLightClassForPackage; @@ -66,6 +68,7 @@ public abstract class KotlinDebuggerTestCase extends DebuggerTestCase { @Override protected void setUp() throws Exception { super.setUp(); + VfsRootAccess.allowRootAccess(JetTestCaseBuilder.getHomeDirectory()); UsefulTestCase.edt(new Runnable() { @Override @@ -89,6 +92,12 @@ public abstract class KotlinDebuggerTestCase extends DebuggerTestCase { } + @Override + protected void tearDown() throws Exception { + VfsRootAccess.allowRootAccess(JetTestCaseBuilder.getHomeDirectory()); + super.tearDown(); + } + @Override protected void ensureCompiledAppExists() throws Exception { if (!IS_TINY_APP_COMPILED) { diff --git a/idea/tests/org/jetbrains/jet/plugin/debugger/evaluate/AbstractKotlinEvaluateExpressionTest.kt b/idea/tests/org/jetbrains/jet/plugin/debugger/evaluate/AbstractKotlinEvaluateExpressionTest.kt index d05f7197025..a7570681296 100644 --- a/idea/tests/org/jetbrains/jet/plugin/debugger/evaluate/AbstractKotlinEvaluateExpressionTest.kt +++ b/idea/tests/org/jetbrains/jet/plugin/debugger/evaluate/AbstractKotlinEvaluateExpressionTest.kt @@ -40,6 +40,9 @@ import org.apache.log4j.AppenderSkeleton import org.apache.log4j.spi.LoggingEvent import org.apache.log4j.Level import org.apache.log4j.Logger +import com.intellij.openapi.application.ApplicationManager +import com.intellij.openapi.util.Computable +import com.intellij.psi.PsiDocumentManager public abstract class AbstractKotlinEvaluateExpressionTest : KotlinDebuggerTestCase() { private val logger = Logger.getLogger(javaClass())!! @@ -163,32 +166,37 @@ public abstract class AbstractKotlinEvaluateExpressionTest : KotlinDebuggerTestC } private fun SuspendContextImpl.evaluate(text: String, codeFragmentKind: CodeFragmentKind, expectedResult: String) { - try { + ApplicationManager.getApplication()?.runReadAction { val sourcePosition = ContextUtil.getSourcePosition(this) val contextElement = ContextUtil.getContextElement(sourcePosition)!! Assert.assertTrue("KotlinCodeFragmentFactory should be accepted for context element otherwise default evaluator will be called. ContextElement = ${contextElement.getText()}", KotlinCodeFragmentFactory().isContextAccepted(contextElement)) - val evaluator = DebuggerInvocationUtil.commitAndRunReadAction(getProject()) { - EvaluatorBuilderImpl.build(TextWithImportsImpl( - codeFragmentKind, - text, - JetCodeFragment.getImportsForElement(contextElement), - JetFileType.INSTANCE), - contextElement, - sourcePosition) - } - if (evaluator == null) throw AssertionError("Cannot create an Evaluator for Evaluate Expression") + try { - val value = evaluator.evaluate(createEvaluationContext(this)) - val actualResult = value.asValue().asString() - Assert.assertTrue("Evaluate expression returns wrong result for $text:\nexpected = $expectedResult\nactual = $actualResult\n", expectedResult == actualResult) - } - catch (e: EvaluateException) { - Assert.assertTrue("Evaluate expression throws wrong exception for $text:\nexpected = $expectedResult\nactual = ${e.getMessage()}\n", expectedResult == e.getMessage()?.replaceFirst("id=[0-9]*", "id=ID")) - } - finally { - resume(this) + val evaluator = + EvaluatorBuilderImpl.build(TextWithImportsImpl( + codeFragmentKind, + text, + JetCodeFragment.getImportsForElement(contextElement), + JetFileType.INSTANCE), + contextElement, + sourcePosition) + + + if (evaluator == null) throw AssertionError("Cannot create an Evaluator for Evaluate Expression") + + val value = evaluator.evaluate(createEvaluationContext(this)) + val actualResult = value.asValue().asString() + + Assert.assertTrue("Evaluate expression returns wrong result for $text:\nexpected = $expectedResult\nactual = $actualResult\n", expectedResult == actualResult) + } + catch (e: EvaluateException) { + Assert.assertTrue("Evaluate expression throws wrong exception for $text:\nexpected = $expectedResult\nactual = ${e.getMessage()}\n", expectedResult == e.getMessage()?.replaceFirst("id=[0-9]*", "id=ID")) + } + finally { + resume(this) + } } }