From c6ae916b24b77e377f6a9267453308e216cd31ef Mon Sep 17 00:00:00 2001 From: Ilya Kirillov Date: Tue, 26 May 2020 12:39:13 +0300 Subject: [PATCH] FIR IDE: Fix tests in idea-fir --- .../checkers/AbstractFirPsiCheckerTest.kt | 2 ++ .../idea/fir/AbstractFirLazyResolveTest.kt | 3 ++- .../fir/AbstractFirMultiModuleResolveTest.kt | 6 ++++-- .../kotlin/idea/fir/FirResolveStateTest.kt | 4 +++- .../jetbrains/kotlin/idea/fir/firTestUtils.kt | 11 +++++++++++ .../AbstractFirHighlightingTest.kt | 2 ++ .../AbstractFirReferenceResolveTest.kt | 9 +++++++++ .../KotlinLightCodeInsightFixtureTestCase.kt | 19 ++++++++++++------- ...inLightCodeInsightFixtureTestCaseBase.java | 19 ++++++------------- ...LightPlatformCodeInsightFixtureTestCase.kt | 5 ++++- 10 files changed, 55 insertions(+), 25 deletions(-) create mode 100644 idea/idea-fir/tests/org/jetbrains/kotlin/idea/fir/firTestUtils.kt diff --git a/idea/idea-fir/tests/org/jetbrains/kotlin/checkers/AbstractFirPsiCheckerTest.kt b/idea/idea-fir/tests/org/jetbrains/kotlin/checkers/AbstractFirPsiCheckerTest.kt index 656c7e85ab4..e4bc9bcd7bf 100644 --- a/idea/idea-fir/tests/org/jetbrains/kotlin/checkers/AbstractFirPsiCheckerTest.kt +++ b/idea/idea-fir/tests/org/jetbrains/kotlin/checkers/AbstractFirPsiCheckerTest.kt @@ -12,6 +12,8 @@ import org.jetbrains.kotlin.test.InTextDirectivesUtils import java.io.File abstract class AbstractFirPsiCheckerTest : AbstractPsiCheckerTest() { + override fun isFirPlugin(): Boolean = true + override fun setUp() { super.setUp() FirResolution.enabled = true diff --git a/idea/idea-fir/tests/org/jetbrains/kotlin/idea/fir/AbstractFirLazyResolveTest.kt b/idea/idea-fir/tests/org/jetbrains/kotlin/idea/fir/AbstractFirLazyResolveTest.kt index 252f78c9a20..5791a67c87f 100644 --- a/idea/idea-fir/tests/org/jetbrains/kotlin/idea/fir/AbstractFirLazyResolveTest.kt +++ b/idea/idea-fir/tests/org/jetbrains/kotlin/idea/fir/AbstractFirLazyResolveTest.kt @@ -22,7 +22,6 @@ import org.jetbrains.kotlin.idea.jsonUtils.getString import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase import org.jetbrains.kotlin.idea.test.KotlinLightProjectDescriptor import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor -import org.jetbrains.kotlin.idea.util.projectStructure.allModules import org.jetbrains.kotlin.psi.KtCallExpression import org.jetbrains.kotlin.psi.KtExpression import org.jetbrains.kotlin.psi.KtFile @@ -30,6 +29,8 @@ import org.jetbrains.kotlin.test.KotlinTestUtils import java.io.File abstract class AbstractFirLazyResolveTest : KotlinLightCodeInsightFixtureTestCase() { + override fun isFirPlugin(): Boolean = true + override fun getProjectDescriptor(): LightProjectDescriptor { if (KotlinTestUtils.isAllFilesPresentTest(getTestName(false))) return super.getProjectDescriptor() val testFile = File(testDataPath, fileName()) diff --git a/idea/idea-fir/tests/org/jetbrains/kotlin/idea/fir/AbstractFirMultiModuleResolveTest.kt b/idea/idea-fir/tests/org/jetbrains/kotlin/idea/fir/AbstractFirMultiModuleResolveTest.kt index eec41b2a0ea..66630e7c76a 100644 --- a/idea/idea-fir/tests/org/jetbrains/kotlin/idea/fir/AbstractFirMultiModuleResolveTest.kt +++ b/idea/idea-fir/tests/org/jetbrains/kotlin/idea/fir/AbstractFirMultiModuleResolveTest.kt @@ -1,11 +1,13 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.idea.fir import com.intellij.openapi.module.Module +import com.intellij.openapi.module.ModuleManager +import com.intellij.openapi.project.Project import com.intellij.openapi.vfs.VirtualFile import com.intellij.psi.PsiFile import com.intellij.psi.PsiManager @@ -45,7 +47,6 @@ import org.jetbrains.kotlin.idea.multiplatform.setupMppProjectFromDirStructure import org.jetbrains.kotlin.idea.stubs.AbstractMultiModuleTest import org.jetbrains.kotlin.idea.test.ConfigLibraryUtil import org.jetbrains.kotlin.idea.test.PluginTestCaseBase -import org.jetbrains.kotlin.idea.util.projectStructure.allModules import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.test.KotlinTestUtils import org.jetbrains.kotlin.test.TestJdkKind @@ -200,3 +201,4 @@ abstract class AbstractFirMultiModuleResolveTest : AbstractMultiModuleTest() { } } } + diff --git a/idea/idea-fir/tests/org/jetbrains/kotlin/idea/fir/FirResolveStateTest.kt b/idea/idea-fir/tests/org/jetbrains/kotlin/idea/fir/FirResolveStateTest.kt index 669c1504aef..e1194d6326b 100644 --- a/idea/idea-fir/tests/org/jetbrains/kotlin/idea/fir/FirResolveStateTest.kt +++ b/idea/idea-fir/tests/org/jetbrains/kotlin/idea/fir/FirResolveStateTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -8,6 +8,8 @@ package org.jetbrains.kotlin.idea.fir import org.jetbrains.kotlin.idea.AbstractResolveElementCacheTest class FirResolveStateTest : AbstractResolveElementCacheTest() { + override fun isFirPlugin(): Boolean = true + fun testSimpleStateCaching() { doTest { val firstStatement = statements[0] diff --git a/idea/idea-fir/tests/org/jetbrains/kotlin/idea/fir/firTestUtils.kt b/idea/idea-fir/tests/org/jetbrains/kotlin/idea/fir/firTestUtils.kt new file mode 100644 index 00000000000..e14af0b4e22 --- /dev/null +++ b/idea/idea-fir/tests/org/jetbrains/kotlin/idea/fir/firTestUtils.kt @@ -0,0 +1,11 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.idea.fir + +import com.intellij.openapi.module.ModuleManager +import com.intellij.openapi.project.Project + +internal fun Project.allModules() = ModuleManager.getInstance(this).modules.toList() diff --git a/idea/idea-fir/tests/org/jetbrains/kotlin/idea/highlighter/AbstractFirHighlightingTest.kt b/idea/idea-fir/tests/org/jetbrains/kotlin/idea/highlighter/AbstractFirHighlightingTest.kt index 2f380e0018c..0f240cd73cf 100644 --- a/idea/idea-fir/tests/org/jetbrains/kotlin/idea/highlighter/AbstractFirHighlightingTest.kt +++ b/idea/idea-fir/tests/org/jetbrains/kotlin/idea/highlighter/AbstractFirHighlightingTest.kt @@ -11,6 +11,8 @@ import org.jetbrains.kotlin.test.InTextDirectivesUtils abstract class AbstractFirHighlightingTest : AbstractHighlightingTest() { override fun getDefaultProjectDescriptor() = ProjectDescriptorWithStdlibSources.INSTANCE + override fun isFirPlugin() = true + override fun checkHighlighting(fileText: String) { val checkInfos = !InTextDirectivesUtils.isDirectiveDefined(fileText, NO_CHECK_INFOS_PREFIX); diff --git a/idea/idea-fir/tests/org/jetbrains/kotlin/idea/resolve/AbstractFirReferenceResolveTest.kt b/idea/idea-fir/tests/org/jetbrains/kotlin/idea/resolve/AbstractFirReferenceResolveTest.kt index def507ffd25..96d1941d8e1 100644 --- a/idea/idea-fir/tests/org/jetbrains/kotlin/idea/resolve/AbstractFirReferenceResolveTest.kt +++ b/idea/idea-fir/tests/org/jetbrains/kotlin/idea/resolve/AbstractFirReferenceResolveTest.kt @@ -5,11 +5,20 @@ package org.jetbrains.kotlin.idea.resolve +import com.intellij.testFramework.LightProjectDescriptor import org.jetbrains.kotlin.idea.completion.test.configureWithExtraFile import org.jetbrains.kotlin.idea.fir.FirResolution +import org.jetbrains.kotlin.idea.test.KotlinLightProjectDescriptor +import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor +import org.jetbrains.kotlin.idea.test.ProjectDescriptorWithStdlibSources import org.jetbrains.kotlin.test.InTextDirectivesUtils abstract class AbstractFirReferenceResolveTest : AbstractReferenceResolveTest() { + override fun isFirPlugin(): Boolean = true + + override fun getProjectDescriptor(): KotlinLightProjectDescriptor = + KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE_FULL_JDK + override fun setUp() { super.setUp() FirResolution.enabled = true diff --git a/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinLightCodeInsightFixtureTestCase.kt b/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinLightCodeInsightFixtureTestCase.kt index bf054eda8bf..7407228d2b4 100644 --- a/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinLightCodeInsightFixtureTestCase.kt +++ b/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinLightCodeInsightFixtureTestCase.kt @@ -77,20 +77,25 @@ abstract class KotlinLightCodeInsightFixtureTestCase : KotlinLightCodeInsightFix override fun setUp() { super.setUp() - enableKotlinOfficialCodeStyle(project) - // We do it here to avoid possible initialization problems - // UnusedSymbolInspection() calls IDEA UnusedDeclarationInspection() in static initializer, - // which in turn registers some extensions provoking "modifications aren't allowed during highlighting" - // when done lazily - UnusedSymbolInspection() + + if (!isFirPlugin) { + // We do it here to avoid possible initialization problems + // UnusedSymbolInspection() calls IDEA UnusedDeclarationInspection() in static initializer, + // which in turn registers some extensions provoking "modifications aren't allowed during highlighting" + // when done lazily + UnusedSymbolInspection() + } + runPostStartupActivitiesOnce(project) VfsRootAccess.allowRootAccess(project, KotlinTestUtils.getHomeDirectory()) editorTrackerProjectOpened(project) - invalidateLibraryCache(project) + if (!isFirPlugin) { + invalidateLibraryCache(project) + } if (captureExceptions) { LoggedErrorProcessor.setNewInstance(object : LoggedErrorProcessor() { diff --git a/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinLightCodeInsightFixtureTestCaseBase.java b/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinLightCodeInsightFixtureTestCaseBase.java index fcb60071278..0b25e4f48ce 100644 --- a/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinLightCodeInsightFixtureTestCaseBase.java +++ b/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinLightCodeInsightFixtureTestCaseBase.java @@ -1,17 +1,6 @@ /* - * Copyright 2010-2016 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. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.idea.test; @@ -102,4 +91,8 @@ public abstract class KotlinLightCodeInsightFixtureTestCaseBase extends LightCod //noinspection Convert2MethodRef KotlinTestUtils.runTestWithThrowable(this, () -> super.runTest()); } + + protected boolean isFirPlugin() { + return false; + } } diff --git a/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinLightPlatformCodeInsightFixtureTestCase.kt b/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinLightPlatformCodeInsightFixtureTestCase.kt index ad0861e3ff1..ad5ec1296af 100644 --- a/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinLightPlatformCodeInsightFixtureTestCase.kt +++ b/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinLightPlatformCodeInsightFixtureTestCase.kt @@ -14,12 +14,15 @@ import java.io.File import kotlin.reflect.full.findAnnotation abstract class KotlinLightPlatformCodeInsightFixtureTestCase : LightPlatformCodeInsightFixtureTestCase() { + protected open fun isFirPlugin(): Boolean = false override fun setUp() { super.setUp() enableKotlinOfficialCodeStyle(project) runPostStartupActivitiesOnce(project) VfsRootAccess.allowRootAccess(KotlinTestUtils.getHomeDirectory()) - invalidateLibraryCache(project) + if (!isFirPlugin()) { + invalidateLibraryCache(project) + } } override fun tearDown() = runAll(