From a046ab514840803370ee4fa90b982fc8d6ecf1b6 Mon Sep 17 00:00:00 2001 From: Roman Efremov Date: Thu, 7 Mar 2024 15:09:08 +0100 Subject: [PATCH] IJPL-578 [Kotlin] Fix Kotlin debugger evaluation tests with .kts after changes in previous commits The problem was that the first evaluation triggers script configuration initialization, which in turn calls `ScriptClassRootsUpdater#applyDiffToModel`, and test doesn't wait until the end of this update, which leads to an exception. GitOrigin-RevId: 17c1e25f8df843670be1d4c77e5eb24d72b02a6b --- .../jvm-debugger/test/kotlin.jvm-debugger.test.iml | 1 + .../AbstractIrKotlinScriptEvaluateExpressionTest.kt | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/plugins/kotlin/jvm-debugger/test/kotlin.jvm-debugger.test.iml b/plugins/kotlin/jvm-debugger/test/kotlin.jvm-debugger.test.iml index 61064e451ddc..2961943c7a23 100644 --- a/plugins/kotlin/jvm-debugger/test/kotlin.jvm-debugger.test.iml +++ b/plugins/kotlin/jvm-debugger/test/kotlin.jvm-debugger.test.iml @@ -32,6 +32,7 @@ + diff --git a/plugins/kotlin/jvm-debugger/test/test/org/jetbrains/kotlin/idea/debugger/test/AbstractIrKotlinScriptEvaluateExpressionTest.kt b/plugins/kotlin/jvm-debugger/test/test/org/jetbrains/kotlin/idea/debugger/test/AbstractIrKotlinScriptEvaluateExpressionTest.kt index 8d9be59b100f..7a60cc37b7e2 100644 --- a/plugins/kotlin/jvm-debugger/test/test/org/jetbrains/kotlin/idea/debugger/test/AbstractIrKotlinScriptEvaluateExpressionTest.kt +++ b/plugins/kotlin/jvm-debugger/test/test/org/jetbrains/kotlin/idea/debugger/test/AbstractIrKotlinScriptEvaluateExpressionTest.kt @@ -4,9 +4,12 @@ package org.jetbrains.kotlin.idea.debugger.test import com.intellij.execution.configurations.JavaParameters import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil.doWriteAction import com.intellij.testFramework.PsiTestUtil +import com.intellij.testFramework.runInEdtAndWait import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler import org.jetbrains.kotlin.config.JvmClosureGenerationScheme import org.jetbrains.kotlin.idea.base.plugin.artifacts.TestKotlinArtifacts +import org.jetbrains.kotlin.idea.core.script.ScriptConfigurationManager +import org.jetbrains.kotlin.idea.debugger.test.preference.DebuggerPreferences import org.jetbrains.kotlin.idea.test.KotlinCliCompilerFacade import org.jetbrains.kotlin.psi.KtFile import java.io.File @@ -22,6 +25,13 @@ abstract class AbstractIrKotlinScriptEvaluateExpressionTest : AbstractIrKotlinEv } } + override fun doMultiFileTest(files: TestFiles, preferences: DebuggerPreferences) { + // Warm up the script configuration, otherwise it will be initialized during evaluation + // which leads to "Evaluation is not possible during indexing" exception + runInEdtAndWait { ScriptConfigurationManager.updateScriptDependenciesSynchronously(getScriptKtFile()) } + super.doMultiFileTest(files, preferences) + } + override fun createBreakpoints(className: String?) = super.createBreakpoints(getScriptKtFile()) override fun getMainClassName(compilerFacility: DebuggerTestCompilerFacility) = K2JVMCompiler::class.qualifiedName!!