From 18195b3296d8321d1fdaccc1b4785cd0cf268c70 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Sat, 22 Aug 2020 19:34:19 +0300 Subject: [PATCH] Rewrite SmartCompletionMultifileHandlerTest to KotlinFixtureCompletionBaseTestCase Use light projects as an attempt to fight leaking project errors --- .../SmartCompletionMultifileHandlerTest.kt | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/handlers/SmartCompletionMultifileHandlerTest.kt b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/handlers/SmartCompletionMultifileHandlerTest.kt index 9d42e99626f..7b622170197 100644 --- a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/handlers/SmartCompletionMultifileHandlerTest.kt +++ b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/handlers/SmartCompletionMultifileHandlerTest.kt @@ -6,16 +6,20 @@ package org.jetbrains.kotlin.idea.completion.test.handlers import com.intellij.codeInsight.completion.CompletionType +import com.intellij.codeInsight.lookup.Lookup import com.intellij.codeInsight.lookup.LookupElement import com.intellij.codeInsight.lookup.LookupElementPresentation +import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase import org.jetbrains.kotlin.idea.completion.test.COMPLETION_TEST_DATA_BASE_PATH -import org.jetbrains.kotlin.idea.completion.test.KotlinCompletionTestCase +import org.jetbrains.kotlin.idea.completion.test.KotlinFixtureCompletionBaseTestCase +import org.jetbrains.kotlin.platform.TargetPlatform +import org.jetbrains.kotlin.platform.jvm.JvmPlatforms import org.jetbrains.kotlin.test.JUnit3WithIdeaConfigurationRunner import org.junit.runner.RunWith import java.io.File @RunWith(JUnit3WithIdeaConfigurationRunner::class) -class SmartCompletionMultifileHandlerTest : KotlinCompletionTestCase() { +class SmartCompletionMultifileHandlerTest : KotlinFixtureCompletionBaseTestCase() { fun testImportExtensionFunction() { doTest() } @@ -36,20 +40,15 @@ class SmartCompletionMultifileHandlerTest : KotlinCompletionTestCase() { doTest(lookupString = "Nested") } - override fun setUp() { - setType(CompletionType.SMART) - super.setUp() - } - private fun doTest(lookupString: String? = null, itemText: String? = null) { val fileName = getTestName(false) val fileNames = listOf("$fileName-1.kt", "$fileName-2.kt", "$fileName.java") - configureByFiles(null, *fileNames.filter { File(testDataPath + it).exists() }.toTypedArray()) + myFixture.configureByFiles(*fileNames.filter { File(testDataPath + it).exists() }.toTypedArray()) - complete(1) - if (myItems != null) { + val items = complete(CompletionType.SMART, 1) + if (items != null) { fun isMatching(lookupElement: LookupElement): Boolean { if (lookupString != null && lookupElement.lookupString != lookupString) return false @@ -60,16 +59,20 @@ class SmartCompletionMultifileHandlerTest : KotlinCompletionTestCase() { return true } - val items = myItems.filter(::isMatching) - when (items.size) { + val matchedItems = items.filter(::isMatching) + when (matchedItems.size) { 0 -> fail("No matching items found") - 1 -> selectItem(myItems[0]) + 1 -> CompletionHandlerTestBase.selectItem(myFixture, items[0], Lookup.NORMAL_SELECT_CHAR) else -> fail("Multiple matching items found") } } - checkResultByFile("$fileName.kt.after") + myFixture.checkResultByFile("$fileName.kt.after") } override fun getTestDataPath() = File(COMPLETION_TEST_DATA_BASE_PATH, "/handlers/multifile/smart/").path + File.separator + + override fun defaultCompletionType(): CompletionType = CompletionType.BASIC + override fun getPlatform(): TargetPlatform = JvmPlatforms.unspecifiedJvmPlatform + override fun getProjectDescriptor() = LightJavaCodeInsightFixtureTestCase.JAVA_LATEST }