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 <root>.A exists in PsiPackage::getClasses instead of PsiPackage::findClassByShortName that can find a class even if it's located in the wrong directory
This commit is contained in:
+1
-1
@@ -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 {
|
finally {
|
||||||
settingManager.dropTemporarySettings()
|
settingManager.dropTemporarySettings()
|
||||||
|
|||||||
-3
@@ -25,7 +25,6 @@ import com.intellij.codeInsight.lookup.impl.LookupImpl
|
|||||||
import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture
|
import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture
|
||||||
import org.jetbrains.kotlin.idea.completion.test.ExpectedCompletionUtils
|
import org.jetbrains.kotlin.idea.completion.test.ExpectedCompletionUtils
|
||||||
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
||||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
|
||||||
|
|
||||||
abstract class CompletionHandlerTestBase() : KotlinLightCodeInsightFixtureTestCase() {
|
abstract class CompletionHandlerTestBase() : KotlinLightCodeInsightFixtureTestCase() {
|
||||||
protected val fixture: JavaCodeInsightTestFixture
|
protected val fixture: JavaCodeInsightTestFixture
|
||||||
@@ -106,8 +105,6 @@ abstract class CompletionHandlerTestBase() : KotlinLightCodeInsightFixtureTestCa
|
|||||||
return foundElement
|
return foundElement
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getTestDataPath() = KotlinTestUtils.getHomeDirectory()
|
|
||||||
|
|
||||||
protected fun selectItem(item: LookupElement?, completionChar: Char) {
|
protected fun selectItem(item: LookupElement?, completionChar: Char) {
|
||||||
val lookup = (fixture.lookup as LookupImpl)
|
val lookup = (fixture.lookup as LookupImpl)
|
||||||
if (lookup.currentItem != item) { // do not touch selection if not changed - important for char filter tests
|
if (lookup.currentItem != item) { // do not touch selection if not changed - important for char filter tests
|
||||||
|
|||||||
+5
-9
@@ -21,20 +21,16 @@ import com.intellij.testFramework.UsefulTestCase
|
|||||||
import com.intellij.testFramework.fixtures.CodeInsightTestFixture
|
import com.intellij.testFramework.fixtures.CodeInsightTestFixture
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
fun CodeInsightTestFixture.configureWithExtraFileAbs(path: String, vararg extraNameParts: String) {
|
fun CodeInsightTestFixture.configureWithExtraFile(path: String, vararg extraNameParts: String = arrayOf(".Data")) {
|
||||||
configureWithExtraFile(path, *extraNameParts, relativePaths = false)
|
val fileName = File(path).name
|
||||||
}
|
|
||||||
|
|
||||||
fun CodeInsightTestFixture.configureWithExtraFile(path: String, vararg extraNameParts: String = arrayOf(".Data"), relativePaths: Boolean = false) {
|
val noExtensionPath = FileUtil.getNameWithoutExtension(fileName)
|
||||||
fun String.toFile(): File = if (relativePaths) File(testDataPath, this) else File(this)
|
|
||||||
|
|
||||||
val noExtensionPath = FileUtil.getNameWithoutExtension(path)
|
|
||||||
val extensions = arrayOf("kt", "java")
|
val extensions = arrayOf("kt", "java")
|
||||||
val extraPaths: List<String> = extraNameParts
|
val extraPaths: List<String> = extraNameParts
|
||||||
.flatMap { extensions.map { ext -> "$noExtensionPath$it.$ext" } }
|
.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
|
@Suppress("unused") // Used in kotlin-ultimate
|
||||||
|
|||||||
+2
-6
@@ -17,15 +17,13 @@
|
|||||||
package org.jetbrains.kotlin.idea.completion.test.weighers
|
package org.jetbrains.kotlin.idea.completion.test.weighers
|
||||||
|
|
||||||
import com.intellij.codeInsight.completion.CompletionType
|
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.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.KotlinLightCodeInsightFixtureTestCase
|
||||||
import org.jetbrains.kotlin.idea.test.KotlinLightProjectDescriptor
|
import org.jetbrains.kotlin.idea.test.KotlinLightProjectDescriptor
|
||||||
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
|
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
|
||||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||||
import org.junit.Assert
|
import org.junit.Assert
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
abstract class AbstractCompletionWeigherTest(val completionType: CompletionType, val relativeTestDataPath: String) : KotlinLightCodeInsightFixtureTestCase() {
|
abstract class AbstractCompletionWeigherTest(val completionType: CompletionType, val relativeTestDataPath: String) : KotlinLightCodeInsightFixtureTestCase() {
|
||||||
fun doTest(path: String) {
|
fun doTest(path: String) {
|
||||||
@@ -33,7 +31,7 @@ abstract class AbstractCompletionWeigherTest(val completionType: CompletionType,
|
|||||||
assert(path.startsWith(pathPrefix))
|
assert(path.startsWith(pathPrefix))
|
||||||
val relativePath = path.removePrefix(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
|
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.complete(completionType, InTextDirectivesUtils.getPrefixedInt(text, "// INVOCATION_COUNT:") ?: 1)
|
||||||
myFixture.assertPreferredCompletionItems(InTextDirectivesUtils.getPrefixedInt(text, "// SELECTED:") ?: 0, *items)
|
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") {
|
abstract class AbstractBasicCompletionWeigherTest() : AbstractCompletionWeigherTest(CompletionType.BASIC, "weighers/basic") {
|
||||||
|
|||||||
+4
@@ -22,6 +22,8 @@ import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess
|
|||||||
import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase
|
import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase
|
||||||
import org.jetbrains.kotlin.idea.actions.internal.KotlinInternalMode
|
import org.jetbrains.kotlin.idea.actions.internal.KotlinInternalMode
|
||||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||||
|
import org.jetbrains.kotlin.test.TestMetadata
|
||||||
|
import kotlin.reflect.full.findAnnotation
|
||||||
|
|
||||||
abstract class KotlinLightPlatformCodeInsightFixtureTestCase: LightPlatformCodeInsightFixtureTestCase() {
|
abstract class KotlinLightPlatformCodeInsightFixtureTestCase: LightPlatformCodeInsightFixtureTestCase() {
|
||||||
private var kotlinInternalModeOriginalValue: Boolean = false
|
private var kotlinInternalModeOriginalValue: Boolean = false
|
||||||
@@ -44,4 +46,6 @@ abstract class KotlinLightPlatformCodeInsightFixtureTestCase: LightPlatformCodeI
|
|||||||
super.tearDown()
|
super.tearDown()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getTestDataPath(): String = this::class.findAnnotation<TestMetadata>()?.value ?: super.getTestDataPath()
|
||||||
}
|
}
|
||||||
+1
-3
@@ -16,9 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.editor.quickDoc;
|
package org.jetbrains.kotlin.idea.editor.quickDoc;
|
||||||
|
|
||||||
import com.intellij.codeInsight.documentation.DocumentationComponent;
|
|
||||||
import com.intellij.codeInsight.documentation.DocumentationManager;
|
import com.intellij.codeInsight.documentation.DocumentationManager;
|
||||||
import com.intellij.codeInsight.navigation.CtrlMouseHandler;
|
|
||||||
import com.intellij.openapi.util.io.FileUtil;
|
import com.intellij.openapi.util.io.FileUtil;
|
||||||
import com.intellij.openapi.util.text.StringUtil;
|
import com.intellij.openapi.util.text.StringUtil;
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
@@ -35,7 +33,7 @@ import java.util.List;
|
|||||||
|
|
||||||
public abstract class AbstractQuickDocProviderTest extends KotlinLightCodeInsightFixtureTestCase {
|
public abstract class AbstractQuickDocProviderTest extends KotlinLightCodeInsightFixtureTestCase {
|
||||||
public void doTest(@NotNull String path) throws Exception {
|
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());
|
PsiElement element = myFixture.getFile().findElementAt(myFixture.getEditor().getCaretModel().getOffset());
|
||||||
assertNotNull("Can't find element at caret in file: " + path, element);
|
assertNotNull("Can't find element at caret in file: " + path, element);
|
||||||
|
|||||||
@@ -99,8 +99,6 @@ abstract class AbstractReferenceResolveTest : KotlinLightPlatformCodeInsightFixt
|
|||||||
|
|
||||||
override fun getProjectDescriptor(): LightProjectDescriptor? = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE
|
override fun getProjectDescriptor(): LightProjectDescriptor? = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE
|
||||||
|
|
||||||
override fun getTestDataPath() = "./"
|
|
||||||
|
|
||||||
open val refMarkerText: String = "REF"
|
open val refMarkerText: String = "REF"
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|||||||
Reference in New Issue
Block a user