From 12b348ae4819d50a28af2f2edbaaa75ce842ef53 Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Tue, 29 Aug 2017 12:27:17 +0300 Subject: [PATCH] Fix incorrectly configured IDE tests The important changes are in ideaTestUtils.kt: `configureByFiles` must be called on the relative to testData dir path, otherwise java files in the project belong to src/idea/testData/.../A.java instead of src/A.java and can't be found in the root package New updates in resolution when resolving A() call is now asking whether .A exists in PsiPackage::getClasses instead of PsiPackage::findClassByShortName that can find a class even if it's located in the wrong directory --- .../handlers/AbstractCompletionHandlerTests.kt | 2 +- .../test/handlers/CompletionHandlerTestBase.kt | 3 --- .../kotlin/idea/completion/test/ideaTestUtils.kt | 16 ++++++---------- .../weighers/AbstractCompletionWeigherTest.kt | 8 ++------ ...linLightPlatformCodeInsightFixtureTestCase.kt | 6 +++++- .../quickDoc/AbstractQuickDocProviderTest.java | 4 +--- .../idea/resolve/AbstractReferenceResolveTest.kt | 2 -- 7 files changed, 15 insertions(+), 26 deletions(-) diff --git a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/handlers/AbstractCompletionHandlerTests.kt b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/handlers/AbstractCompletionHandlerTests.kt index be5d7fa6bde..65c99a6c155 100644 --- a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/handlers/AbstractCompletionHandlerTests.kt +++ b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/handlers/AbstractCompletionHandlerTests.kt @@ -78,7 +78,7 @@ abstract class AbstractCompletionHandlerTest(private val defaultCompletionType: } } - doTestWithTextLoaded(completionType, invocationCount, lookupString, itemText, tailText, completionChar, testPath + ".after") + doTestWithTextLoaded(completionType, invocationCount, lookupString, itemText, tailText, completionChar, File(testPath).name + ".after") } finally { settingManager.dropTemporarySettings() diff --git a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/handlers/CompletionHandlerTestBase.kt b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/handlers/CompletionHandlerTestBase.kt index 9dac4d6a713..776fbefc5da 100644 --- a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/handlers/CompletionHandlerTestBase.kt +++ b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/handlers/CompletionHandlerTestBase.kt @@ -25,7 +25,6 @@ import com.intellij.codeInsight.lookup.impl.LookupImpl import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture import org.jetbrains.kotlin.idea.completion.test.ExpectedCompletionUtils import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase -import org.jetbrains.kotlin.test.KotlinTestUtils abstract class CompletionHandlerTestBase() : KotlinLightCodeInsightFixtureTestCase() { protected val fixture: JavaCodeInsightTestFixture @@ -106,8 +105,6 @@ abstract class CompletionHandlerTestBase() : KotlinLightCodeInsightFixtureTestCa return foundElement } - override fun getTestDataPath() = KotlinTestUtils.getHomeDirectory() - protected fun selectItem(item: LookupElement?, completionChar: Char) { val lookup = (fixture.lookup as LookupImpl) if (lookup.currentItem != item) { // do not touch selection if not changed - important for char filter tests diff --git a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/ideaTestUtils.kt b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/ideaTestUtils.kt index 2f10667b367..06022ac896c 100644 --- a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/ideaTestUtils.kt +++ b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/ideaTestUtils.kt @@ -21,21 +21,17 @@ import com.intellij.testFramework.UsefulTestCase import com.intellij.testFramework.fixtures.CodeInsightTestFixture import java.io.File -fun CodeInsightTestFixture.configureWithExtraFileAbs(path: String, vararg extraNameParts: String) { - configureWithExtraFile(path, *extraNameParts, relativePaths = false) -} +fun CodeInsightTestFixture.configureWithExtraFile(path: String, vararg extraNameParts: String = arrayOf(".Data")) { + val fileName = File(path).name -fun CodeInsightTestFixture.configureWithExtraFile(path: String, vararg extraNameParts: String = arrayOf(".Data"), relativePaths: Boolean = false) { - fun String.toFile(): File = if (relativePaths) File(testDataPath, this) else File(this) - - val noExtensionPath = FileUtil.getNameWithoutExtension(path) + val noExtensionPath = FileUtil.getNameWithoutExtension(fileName) val extensions = arrayOf("kt", "java") val extraPaths: List = extraNameParts .flatMap { extensions.map { ext -> "$noExtensionPath$it.$ext" } } - .filter { it.toFile().exists() } + .mapNotNull { File(testDataPath, it).takeIf { it.exists() }?.name } - configureByFiles(*(listOf(path) + extraPaths).toTypedArray()) + configureByFiles(*(listOf(fileName) + extraPaths).toTypedArray()) } @Suppress("unused") // Used in kotlin-ultimate -inline fun Any?.assertInstanceOf() = UsefulTestCase.assertInstanceOf(this, T::class.java) \ No newline at end of file +inline fun Any?.assertInstanceOf() = UsefulTestCase.assertInstanceOf(this, T::class.java) diff --git a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/weighers/AbstractCompletionWeigherTest.kt b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/weighers/AbstractCompletionWeigherTest.kt index 199486c3686..8d7f5eaf003 100644 --- a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/weighers/AbstractCompletionWeigherTest.kt +++ b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/weighers/AbstractCompletionWeigherTest.kt @@ -17,15 +17,13 @@ package org.jetbrains.kotlin.idea.completion.test.weighers import com.intellij.codeInsight.completion.CompletionType -import org.jetbrains.kotlin.idea.completion.test.configureWithExtraFile -import org.jetbrains.kotlin.idea.completion.test.COMPLETION_TEST_DATA_BASE_PATH import org.jetbrains.kotlin.idea.completion.test.RELATIVE_COMPLETION_TEST_DATA_BASE_PATH +import org.jetbrains.kotlin.idea.completion.test.configureWithExtraFile 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.test.InTextDirectivesUtils import org.junit.Assert -import java.io.File abstract class AbstractCompletionWeigherTest(val completionType: CompletionType, val relativeTestDataPath: String) : KotlinLightCodeInsightFixtureTestCase() { fun doTest(path: String) { @@ -33,7 +31,7 @@ abstract class AbstractCompletionWeigherTest(val completionType: CompletionType, assert(path.startsWith(pathPrefix)) val relativePath = path.removePrefix(pathPrefix) - myFixture.configureWithExtraFile(relativePath, ".Data", ".Data1", ".Data2", ".Data3", ".Data4", ".Data5", ".Data6", relativePaths = true) + myFixture.configureWithExtraFile(relativePath, ".Data", ".Data1", ".Data2", ".Data3", ".Data4", ".Data5", ".Data6") val text = myFixture.editor.document.text @@ -43,8 +41,6 @@ abstract class AbstractCompletionWeigherTest(val completionType: CompletionType, myFixture.complete(completionType, InTextDirectivesUtils.getPrefixedInt(text, "// INVOCATION_COUNT:") ?: 1) myFixture.assertPreferredCompletionItems(InTextDirectivesUtils.getPrefixedInt(text, "// SELECTED:") ?: 0, *items) } - - override fun getTestDataPath() = File(COMPLETION_TEST_DATA_BASE_PATH, relativeTestDataPath).path + File.separator } abstract class AbstractBasicCompletionWeigherTest() : AbstractCompletionWeigherTest(CompletionType.BASIC, "weighers/basic") { diff --git a/idea/idea-test-framework/src/org/jetbrains/kotlin/idea/test/KotlinLightPlatformCodeInsightFixtureTestCase.kt b/idea/idea-test-framework/src/org/jetbrains/kotlin/idea/test/KotlinLightPlatformCodeInsightFixtureTestCase.kt index fc2ca98d60f..23819654002 100644 --- a/idea/idea-test-framework/src/org/jetbrains/kotlin/idea/test/KotlinLightPlatformCodeInsightFixtureTestCase.kt +++ b/idea/idea-test-framework/src/org/jetbrains/kotlin/idea/test/KotlinLightPlatformCodeInsightFixtureTestCase.kt @@ -22,6 +22,8 @@ import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase import org.jetbrains.kotlin.idea.actions.internal.KotlinInternalMode import org.jetbrains.kotlin.test.KotlinTestUtils +import org.jetbrains.kotlin.test.TestMetadata +import kotlin.reflect.full.findAnnotation abstract class KotlinLightPlatformCodeInsightFixtureTestCase: LightPlatformCodeInsightFixtureTestCase() { private var kotlinInternalModeOriginalValue: Boolean = false @@ -44,4 +46,6 @@ abstract class KotlinLightPlatformCodeInsightFixtureTestCase: LightPlatformCodeI super.tearDown() } } -} \ No newline at end of file + + override fun getTestDataPath(): String = this::class.findAnnotation()?.value ?: super.getTestDataPath() +} diff --git a/idea/tests/org/jetbrains/kotlin/idea/editor/quickDoc/AbstractQuickDocProviderTest.java b/idea/tests/org/jetbrains/kotlin/idea/editor/quickDoc/AbstractQuickDocProviderTest.java index 68f09aefa32..fb39bf2319b 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/editor/quickDoc/AbstractQuickDocProviderTest.java +++ b/idea/tests/org/jetbrains/kotlin/idea/editor/quickDoc/AbstractQuickDocProviderTest.java @@ -16,9 +16,7 @@ package org.jetbrains.kotlin.idea.editor.quickDoc; -import com.intellij.codeInsight.documentation.DocumentationComponent; import com.intellij.codeInsight.documentation.DocumentationManager; -import com.intellij.codeInsight.navigation.CtrlMouseHandler; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiElement; @@ -35,7 +33,7 @@ import java.util.List; public abstract class AbstractQuickDocProviderTest extends KotlinLightCodeInsightFixtureTestCase { public void doTest(@NotNull String path) throws Exception { - IdeaTestUtilsKt.configureWithExtraFileAbs(myFixture, path, "_Data"); + IdeaTestUtilsKt.configureWithExtraFile(myFixture, path, "_Data"); PsiElement element = myFixture.getFile().findElementAt(myFixture.getEditor().getCaretModel().getOffset()); assertNotNull("Can't find element at caret in file: " + path, element); diff --git a/idea/tests/org/jetbrains/kotlin/idea/resolve/AbstractReferenceResolveTest.kt b/idea/tests/org/jetbrains/kotlin/idea/resolve/AbstractReferenceResolveTest.kt index a295326d041..72a1bb4fbf1 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/resolve/AbstractReferenceResolveTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/resolve/AbstractReferenceResolveTest.kt @@ -99,8 +99,6 @@ abstract class AbstractReferenceResolveTest : KotlinLightPlatformCodeInsightFixt override fun getProjectDescriptor(): LightProjectDescriptor? = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE - override fun getTestDataPath() = "./" - open val refMarkerText: String = "REF" companion object {