From 55548d919952ce8c03db4380c66caca95657e097 Mon Sep 17 00:00:00 2001 From: Vladimir Dolzhenko Date: Thu, 3 Oct 2019 10:39:48 +0200 Subject: [PATCH] Use test path relative to testDataPath in fixture.configureByFile to be complaint with 193, part 3 --- .../kotlin/analyzer/AnalyzerFacade.kt | 7 +- .../KotlinFixtureCompletionBaseTestCase.kt | 5 +- ...KotlinFixtureCompletionBaseTestCase.kt.193 | 67 ------- .../AbstractCompletionHandlerTests.kt | 12 +- .../handlers/CompletionHandlerTestBase.kt | 2 +- .../KotlinLightCodeInsightFixtureTestCase.kt | 9 +- ...tlinLightCodeInsightFixtureTestCase.kt.193 | 9 +- ...LightPlatformCodeInsightFixtureTestCase.kt | 11 + .../AbstractBreakpointApplicabilityTest.kt | 20 +- ...AbstractSelectExpressionForDebuggerTest.kt | 13 +- .../binaryAndSource/FileFacade.java | 2 +- .../checkers/AbstractJsCheckerTest.java | 4 +- .../checkers/AbstractJsCheckerTest.java.193 | 24 --- .../kotlin/checkers/PsiCheckerCustomTest.kt | 1 + .../kotlin/idea/AbstractCopyPasteTest.kt | 17 +- .../codeInsight/AbstractBreadcrumbsTest.kt | 18 +- .../AbstractBreadcrumbsTest.kt.193 | 35 ---- .../codeInsight/AbstractExpressionTypeTest.kt | 4 +- .../AbstractExpressionTypeTest.kt.193 | 28 --- .../AbstractInsertImportOnPasteTest.kt | 15 +- .../codeInsight/AbstractLineMarkersTest.kt | 11 +- .../AbstractLineMarkersTest.kt.193 | 189 ------------------ .../codeInsight/AbstractMoveOnCutPasteTest.kt | 31 ++- .../AbstractOutOfBlockModificationTest.java | 19 +- ...bstractOutOfBlockModificationTest.java.193 | 139 ------------- .../generate/AbstractCodeInsightActionTest.kt | 18 +- .../AbstractCodeInsightActionTest.kt.193 | 120 ----------- ...ractGenerateHashCodeAndEqualsActionTest.kt | 3 +- .../AbstractKotlinCoverageOutputFilesTest.kt | 12 +- .../AbstractCodeFragmentAutoImportTest.kt | 7 +- ...stractCodeFragmentCompletionHandlerTest.kt | 2 +- ...ractEditorForEvaluateExpressionTest.kt.193 | 154 -------------- ...ractSelectExpressionForDebuggerTest.kt.193 | 49 ----- .../evaluate/CodeFragmentTestUtils.kt | 2 +- .../stubBuilder/BuiltInDecompilerTest.kt | 2 +- .../ExternalAnnotationTest.kt | 3 + .../highlighter/AbstractDslHighlighterTest.kt | 9 +- .../AbstractUsageHighlightingTest.kt | 5 +- ...AbstractConcatenatedStringGeneratorTest.kt | 4 +- .../navigation/AbstractKotlinGotoTest.java | 4 +- .../AbstractKotlinGotoTest.java.193 | 52 ----- .../AbstractNameSuggestionProviderTest.kt | 2 +- .../AbstractNameSuggestionProviderTest.kt.193 | 41 ---- .../refactoring/inline/AbstractInlineTest.kt | 10 +- .../inline/AbstractInlineTest.kt.193 | 84 -------- .../AbstractReferenceResolveInJavaTest.kt | 21 +- ...actReferenceResolveInLibrarySourcesTest.kt | 18 +- ...renceToJavaWithWrongFileStructureTest.java | 5 +- .../idea/stubs/AbstractResolveByStubTest.kt | 7 +- .../stubs/AbstractResolveByStubTest.kt.193 | 63 ------ .../idea/stubs/AbstractStubBuilderTest.kt | 14 +- .../patternMatching/AbstractPsiUnifierTest.kt | 7 +- .../search/AbstractInheritorsSearchTest.java | 6 - .../kotlin/search/AbstractSearcherTest.java | 14 +- .../search/AnnotatedMembersSearchTest.kt | 13 +- .../search/JUnitMembersSearcherTest.java | 9 +- 56 files changed, 178 insertions(+), 1274 deletions(-) delete mode 100644 idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/KotlinFixtureCompletionBaseTestCase.kt.193 delete mode 100644 idea/tests/org/jetbrains/kotlin/checkers/AbstractJsCheckerTest.java.193 delete mode 100644 idea/tests/org/jetbrains/kotlin/idea/codeInsight/AbstractBreadcrumbsTest.kt.193 delete mode 100644 idea/tests/org/jetbrains/kotlin/idea/codeInsight/AbstractExpressionTypeTest.kt.193 delete mode 100644 idea/tests/org/jetbrains/kotlin/idea/codeInsight/AbstractLineMarkersTest.kt.193 delete mode 100644 idea/tests/org/jetbrains/kotlin/idea/codeInsight/AbstractOutOfBlockModificationTest.java.193 delete mode 100644 idea/tests/org/jetbrains/kotlin/idea/codeInsight/generate/AbstractCodeInsightActionTest.kt.193 delete mode 100644 idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/AbstractEditorForEvaluateExpressionTest.kt.193 delete mode 100644 idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/AbstractSelectExpressionForDebuggerTest.kt.193 delete mode 100644 idea/tests/org/jetbrains/kotlin/idea/navigation/AbstractKotlinGotoTest.java.193 delete mode 100644 idea/tests/org/jetbrains/kotlin/idea/refactoring/AbstractNameSuggestionProviderTest.kt.193 delete mode 100644 idea/tests/org/jetbrains/kotlin/idea/refactoring/inline/AbstractInlineTest.kt.193 delete mode 100644 idea/tests/org/jetbrains/kotlin/idea/stubs/AbstractResolveByStubTest.kt.193 diff --git a/compiler/frontend/src/org/jetbrains/kotlin/analyzer/AnalyzerFacade.kt b/compiler/frontend/src/org/jetbrains/kotlin/analyzer/AnalyzerFacade.kt index 429d9a397bc..e103f893e70 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/analyzer/AnalyzerFacade.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/analyzer/AnalyzerFacade.kt @@ -16,23 +16,18 @@ package org.jetbrains.kotlin.analyzer -import com.intellij.openapi.components.ServiceManager import com.intellij.openapi.project.Project import com.intellij.openapi.util.ModificationTracker import com.intellij.psi.search.GlobalSearchScope -import org.jetbrains.kotlin.builtins.DefaultBuiltIns -import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.config.LanguageVersionSettings import org.jetbrains.kotlin.config.LanguageVersionSettingsImpl import org.jetbrains.kotlin.container.ComponentProvider import org.jetbrains.kotlin.context.ModuleContext import org.jetbrains.kotlin.descriptors.ModuleDescriptor -import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor import org.jetbrains.kotlin.descriptors.PackageFragmentProvider import org.jetbrains.kotlin.descriptors.impl.ModuleDependencies import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl import org.jetbrains.kotlin.name.FqName -import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.platform.TargetPlatform import org.jetbrains.kotlin.platform.TargetPlatformVersion import org.jetbrains.kotlin.psi.KtFile @@ -207,7 +202,7 @@ interface ResolverForModuleComputationTracker { companion object { fun getInstance(project: Project): ResolverForModuleComputationTracker? = - ServiceManager.getService(project, ResolverForModuleComputationTracker::class.java) ?: null + project.getComponent(ResolverForModuleComputationTracker::class.java) ?: null } } diff --git a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/KotlinFixtureCompletionBaseTestCase.kt b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/KotlinFixtureCompletionBaseTestCase.kt index 0e29f575b6b..b3dc24e79c1 100644 --- a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/KotlinFixtureCompletionBaseTestCase.kt +++ b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/KotlinFixtureCompletionBaseTestCase.kt @@ -25,7 +25,8 @@ abstract class KotlinFixtureCompletionBaseTestCase : KotlinLightCodeInsightFixtu protected abstract fun defaultCompletionType(): CompletionType protected open fun defaultInvocationCount(): Int = 0 - open fun doTest(testPath: String) { + open fun doTest(unused: String) { + val testPath = testPath() setUpFixture(testPath) val fileText = FileUtil.loadFile(File(testPath), true) @@ -58,7 +59,7 @@ abstract class KotlinFixtureCompletionBaseTestCase : KotlinLightCodeInsightFixtu //TODO: this is a hacky workaround for js second completion tests failing with PsiInvalidElementAccessException LibraryModificationTracker.getInstance(project).incModificationCount() - myFixture.configureByFile(testPath) + myFixture.configureByFile(File(testPath).name) } protected open fun tearDownFixture() { diff --git a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/KotlinFixtureCompletionBaseTestCase.kt.193 b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/KotlinFixtureCompletionBaseTestCase.kt.193 deleted file mode 100644 index 095fe57b6d2..00000000000 --- a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/KotlinFixtureCompletionBaseTestCase.kt.193 +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2010-2019 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.completion.test - -import com.intellij.codeInsight.completion.CompletionType -import com.intellij.codeInsight.lookup.LookupElement -import com.intellij.openapi.util.io.FileUtil -import org.jetbrains.kotlin.idea.caches.project.LibraryModificationTracker -import org.jetbrains.kotlin.idea.test.CompilerTestDirectives -import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase -import org.jetbrains.kotlin.idea.test.configureCompilerOptions -import org.jetbrains.kotlin.idea.test.rollbackCompilerOptions -import org.jetbrains.kotlin.platform.TargetPlatform -import java.io.File - -abstract class KotlinFixtureCompletionBaseTestCase : KotlinLightCodeInsightFixtureTestCase() { - abstract fun getPlatform(): TargetPlatform - - protected open fun complete(completionType: CompletionType, invocationCount: Int): Array? = - myFixture.complete(completionType, invocationCount) - - protected abstract fun defaultCompletionType(): CompletionType - protected open fun defaultInvocationCount(): Int = 0 - - open fun doTest(testPath: String) { - setUpFixture(fileName()) - - val fileText = FileUtil.loadFile(File(testPath), true) - val configured = configureCompilerOptions(fileText, project, module) - try { - - assertTrue("\"\" is missing in file \"$testPath\"", fileText.contains("")) - - if (ExpectedCompletionUtils.shouldRunHighlightingBeforeCompletion(fileText)) { - myFixture.doHighlighting() - } - - testCompletion( - fileText, - getPlatform(), - { completionType, count -> complete(completionType, count) }, - defaultCompletionType(), - defaultInvocationCount(), - additionalValidDirectives = CompilerTestDirectives.ALL_COMPILER_TEST_DIRECTIVES - ) - } finally { - if (configured) { - rollbackCompilerOptions(project, module) - } - tearDownFixture() - } - } - - protected open fun setUpFixture(testPath: String) { - //TODO: this is a hacky workaround for js second completion tests failing with PsiInvalidElementAccessException - LibraryModificationTracker.getInstance(project).incModificationCount() - - myFixture.configureByFile(testPath) - } - - protected open fun tearDownFixture() { - - } -} 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 fe8085bcff1..0484e9d9ac3 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 @@ -28,14 +28,14 @@ abstract class AbstractCompletionHandlerTest(private val defaultCompletionType: private val CODE_STYLE_SETTING_PREFIX = "CODE_STYLE_SETTING:" protected open fun doTest(testPath: String) { - setUpFixture(testPath) + setUpFixture(fileName()) val tempSettings = CodeStyle.getSettings(project).clone() CodeStyle.setTemporarySettings(project, tempSettings) val fileText = FileUtil.loadFile(File(testPath)) val configured = configureCompilerOptions(fileText, project, module) try { - assertTrue("\"\" is missing in file \"$testPath\"", fileText.contains("")); + assertTrue("\"\" is missing in file \"$testPath\"", fileText.contains("")) val invocationCount = InTextDirectivesUtils.getPrefixedInt(fileText, INVOCATION_COUNT_PREFIX) ?: 1 @@ -98,10 +98,10 @@ abstract class AbstractCompletionHandlerTest(private val defaultCompletionType: override fun getProjectDescriptor() = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE } -abstract class AbstractBasicCompletionHandlerTest() : AbstractCompletionHandlerTest(CompletionType.BASIC) +abstract class AbstractBasicCompletionHandlerTest : AbstractCompletionHandlerTest(CompletionType.BASIC) -abstract class AbstractSmartCompletionHandlerTest() : AbstractCompletionHandlerTest(CompletionType.SMART) +abstract class AbstractSmartCompletionHandlerTest : AbstractCompletionHandlerTest(CompletionType.SMART) -abstract class AbstractCompletionCharFilterTest() : AbstractCompletionHandlerTest(CompletionType.BASIC) +abstract class AbstractCompletionCharFilterTest : AbstractCompletionHandlerTest(CompletionType.BASIC) -abstract class AbstractKeywordCompletionHandlerTest() : AbstractCompletionHandlerTest(CompletionType.BASIC) +abstract class AbstractKeywordCompletionHandlerTest : AbstractCompletionHandlerTest(CompletionType.BASIC) 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 386728b08ba..1fc1c5d24b2 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 @@ -15,7 +15,7 @@ import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture import org.jetbrains.kotlin.idea.completion.test.ExpectedCompletionUtils import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase -abstract class CompletionHandlerTestBase() : KotlinLightCodeInsightFixtureTestCase() { +abstract class CompletionHandlerTestBase : KotlinLightCodeInsightFixtureTestCase() { protected val fixture: JavaCodeInsightTestFixture get() = myFixture 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 4efec6aec9b..52f8dd24e5b 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 @@ -30,7 +30,6 @@ import com.intellij.psi.search.FileTypeIndex import com.intellij.psi.search.ProjectScope import com.intellij.testFramework.LightProjectDescriptor import com.intellij.testFramework.LoggedErrorProcessor -import com.sun.tools.corba.se.idl.toJavaPortable.Util.fileName import org.apache.log4j.Logger import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments import org.jetbrains.kotlin.config.CompilerSettings @@ -64,9 +63,13 @@ abstract class KotlinLightCodeInsightFixtureTestCase : KotlinLightCodeInsightFix protected open val captureExceptions = true - protected fun testDataFile(): File = File(testDataPath, fileName()) + protected fun testDataFile(fileName: String): File = File(testDataPath, fileName) - protected fun testPath(): String = testDataFile().toString() + protected fun testDataFile(): File = testDataFile(fileName()) + + protected fun testPath(fileName: String = fileName()): String = testDataFile(fileName).toString() + + protected fun testPath(): String = testPath(fileName()) protected open fun fileName(): String = KotlinTestUtils.getTestDataFileName(this::class.java, this.name) ?: (getTestName(false) + ".kt") diff --git a/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinLightCodeInsightFixtureTestCase.kt.193 b/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinLightCodeInsightFixtureTestCase.kt.193 index b6695f123c3..e6d630dff36 100644 --- a/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinLightCodeInsightFixtureTestCase.kt.193 +++ b/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/KotlinLightCodeInsightFixtureTestCase.kt.193 @@ -29,7 +29,6 @@ import com.intellij.psi.search.FileTypeIndex import com.intellij.psi.search.ProjectScope import com.intellij.testFramework.LightProjectDescriptor import com.intellij.testFramework.LoggedErrorProcessor -import com.sun.tools.corba.se.idl.toJavaPortable.Util.fileName import org.apache.log4j.Logger import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments import org.jetbrains.kotlin.config.CompilerSettings @@ -63,9 +62,13 @@ abstract class KotlinLightCodeInsightFixtureTestCase : KotlinLightCodeInsightFix protected open val captureExceptions = true - protected fun testDataFile(): File = File(testDataPath, fileName()) + protected fun testDataFile(fileName: String): File = File(testDataPath, fileName) - protected fun testPath(): String = testDataFile().toString() + protected fun testDataFile(): File = testDataFile(fileName()) + + protected fun testPath(fileName: String = fileName()): String = testDataFile(fileName).toString() + + protected fun testPath(): String = testPath(fileName()) protected open fun fileName(): String = KotlinTestUtils.getTestDataFileName(this::class.java, this.name) ?: (getTestName(false) + ".kt") 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 aa1bbe6f94a..8dd930cce32 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 @@ -22,6 +22,7 @@ import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase import org.jetbrains.kotlin.test.KotlinTestUtils import org.jetbrains.kotlin.test.TestMetadata +import java.io.File import kotlin.reflect.full.findAnnotation abstract class KotlinLightPlatformCodeInsightFixtureTestCase: LightPlatformCodeInsightFixtureTestCase() { @@ -38,5 +39,15 @@ abstract class KotlinLightPlatformCodeInsightFixtureTestCase: LightPlatformCodeI super.tearDown() } + protected fun testDataFile(fileName: String): File = File(testDataPath, fileName) + + protected fun testDataFile(): File = testDataFile(fileName()) + + protected fun testPath(fileName: String = fileName()): String = testDataFile(fileName).toString() + + protected fun testPath(): String = testPath(fileName()) + + protected open fun fileName(): String = KotlinTestUtils.getTestDataFileName(this::class.java, this.name) ?: (getTestName(false) + ".kt") + override fun getTestDataPath(): String = this::class.findAnnotation()?.value ?: super.getTestDataPath() } diff --git a/idea/jvm-debugger/jvm-debugger-test/test/org/jetbrains/kotlin/idea/debugger/test/AbstractBreakpointApplicabilityTest.kt b/idea/jvm-debugger/jvm-debugger-test/test/org/jetbrains/kotlin/idea/debugger/test/AbstractBreakpointApplicabilityTest.kt index 334cec8983f..62e1c42ab5a 100644 --- a/idea/jvm-debugger/jvm-debugger-test/test/org/jetbrains/kotlin/idea/debugger/test/AbstractBreakpointApplicabilityTest.kt +++ b/idea/jvm-debugger/jvm-debugger-test/test/org/jetbrains/kotlin/idea/debugger/test/AbstractBreakpointApplicabilityTest.kt @@ -14,37 +14,23 @@ import org.jetbrains.kotlin.idea.debugger.breakpoints.* import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor import org.jetbrains.kotlin.idea.test.PluginTestCaseBase -import org.jetbrains.kotlin.idea.test.allKotlinFiles import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.test.KotlinTestUtils -import java.io.File abstract class AbstractBreakpointApplicabilityTest : KotlinLightCodeInsightFixtureTestCase() { private companion object { private const val COMMENT = "///" } - override fun getTestDataPath(): String { - return PluginTestCaseBase.getTestDataPathBase() + "/debugger/breakpointApplicability/" - } - - override fun setUp() { - super.setUp() - myFixture.testDataPath = PluginTestCaseBase.getTestDataPathBase() - } - override fun getProjectDescriptor(): LightProjectDescriptor { return KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE } - protected fun doTest(path: String) { - myFixture.configureByFile(getPath(path)) - - val file = File(path) - val ktFile = project.allKotlinFiles().single() + protected fun doTest(unused: String) { + val ktFile = myFixture.configureByFile(fileName()) as KtFile val actualContents = checkBreakpoints(ktFile, BreakpointChecker()) - KotlinTestUtils.assertEqualsToFile(file, actualContents) + KotlinTestUtils.assertEqualsToFile(testDataFile(), actualContents) } private fun checkBreakpoints(file: KtFile, checker: BreakpointChecker): String { diff --git a/idea/jvm-debugger/jvm-debugger-test/test/org/jetbrains/kotlin/idea/debugger/test/AbstractSelectExpressionForDebuggerTest.kt b/idea/jvm-debugger/jvm-debugger-test/test/org/jetbrains/kotlin/idea/debugger/test/AbstractSelectExpressionForDebuggerTest.kt index 720bbaef8a9..bde89ee6ed8 100644 --- a/idea/jvm-debugger/jvm-debugger-test/test/org/jetbrains/kotlin/idea/debugger/test/AbstractSelectExpressionForDebuggerTest.kt +++ b/idea/jvm-debugger/jvm-debugger-test/test/org/jetbrains/kotlin/idea/debugger/test/AbstractSelectExpressionForDebuggerTest.kt @@ -5,15 +5,14 @@ package org.jetbrains.kotlin.idea.debugger.test -import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase import org.jetbrains.kotlin.idea.debugger.KotlinEditorTextProvider +import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase import org.jetbrains.kotlin.idea.test.KotlinLightProjectDescriptor -import org.jetbrains.kotlin.idea.test.PluginTestCaseBase import org.jetbrains.kotlin.idea.test.invalidateLibraryCache import org.jetbrains.kotlin.test.InTextDirectivesUtils import org.junit.Assert -abstract class AbstractSelectExpressionForDebuggerTest : LightCodeInsightFixtureTestCase() { +abstract class AbstractSelectExpressionForDebuggerTest : KotlinLightCodeInsightFixtureTestCase() { override fun setUp() { super.setUp() invalidateLibraryCache(project) @@ -27,8 +26,8 @@ abstract class AbstractSelectExpressionForDebuggerTest : LightCodeInsightFixture doTest(path, false) } - fun doTest(path: String, allowMethodCalls: Boolean) { - myFixture.configureByFile(path) + fun doTest(unused: String, allowMethodCalls: Boolean) { + myFixture.configureByFile(fileName()) val elementAt = myFixture.file?.findElementAt(myFixture.caretOffset)!! val selectedExpression = KotlinEditorTextProvider.findExpressionInner(elementAt, allowMethodCalls) @@ -44,7 +43,5 @@ abstract class AbstractSelectExpressionForDebuggerTest : LightCodeInsightFixture Assert.assertEquals("Another expression should be selected", expected, actualResult) } - override fun getProjectDescriptor(): KotlinLightProjectDescriptor = KotlinLightProjectDescriptor.INSTANCE - - override fun getTestDataPath() = PluginTestCaseBase.getTestDataPathBase() + "/debugger/selectExpression" + override fun getProjectDescriptor() = KotlinLightProjectDescriptor.INSTANCE } diff --git a/idea/testData/resolve/referenceInJava/binaryAndSource/FileFacade.java b/idea/testData/resolve/referenceInJava/binaryAndSource/FileFacade.java index f17f2b8afa5..8ada8ad10f0 100644 --- a/idea/testData/resolve/referenceInJava/binaryAndSource/FileFacade.java +++ b/idea/testData/resolve/referenceInJava/binaryAndSource/FileFacade.java @@ -4,5 +4,5 @@ public class PackageFacade { } } -// REF: /src//resolve/referenceInJava/dependency.dependencies.kt +// REF: /src.dependencies.kt // CLS_REF: !/k.DependenciesKt.class \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/checkers/AbstractJsCheckerTest.java b/idea/tests/org/jetbrains/kotlin/checkers/AbstractJsCheckerTest.java index 5e1046f182e..3a4ff7648e6 100644 --- a/idea/tests/org/jetbrains/kotlin/checkers/AbstractJsCheckerTest.java +++ b/idea/tests/org/jetbrains/kotlin/checkers/AbstractJsCheckerTest.java @@ -17,8 +17,8 @@ public abstract class AbstractJsCheckerTest extends KotlinLightCodeInsightFixtur return KotlinStdJSProjectDescriptor.INSTANCE; } - public void doTest(String filePath) { - myFixture.configureByFile(filePath); + public void doTest(String unused) { + myFixture.configureByFile(fileName()); myFixture.checkHighlighting(true, false, false); } } diff --git a/idea/tests/org/jetbrains/kotlin/checkers/AbstractJsCheckerTest.java.193 b/idea/tests/org/jetbrains/kotlin/checkers/AbstractJsCheckerTest.java.193 deleted file mode 100644 index a2cc2e3125d..00000000000 --- a/idea/tests/org/jetbrains/kotlin/checkers/AbstractJsCheckerTest.java.193 +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2010-2019 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.checkers; - -import com.intellij.testFramework.LightProjectDescriptor; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase; -import org.jetbrains.kotlin.idea.test.KotlinStdJSProjectDescriptor; - -public abstract class AbstractJsCheckerTest extends KotlinLightCodeInsightFixtureTestCase { - @NotNull - @Override - protected LightProjectDescriptor getProjectDescriptor() { - return KotlinStdJSProjectDescriptor.INSTANCE; - } - - public void doTest(String filePath) { - myFixture.configureByFile(fileName()); - myFixture.checkHighlighting(true, false, false); - } -} diff --git a/idea/tests/org/jetbrains/kotlin/checkers/PsiCheckerCustomTest.kt b/idea/tests/org/jetbrains/kotlin/checkers/PsiCheckerCustomTest.kt index 65c73c03b52..457a1a7e436 100644 --- a/idea/tests/org/jetbrains/kotlin/checkers/PsiCheckerCustomTest.kt +++ b/idea/tests/org/jetbrains/kotlin/checkers/PsiCheckerCustomTest.kt @@ -15,6 +15,7 @@ import org.junit.runner.RunWith @RunWith(JUnit3WithIdeaConfigurationRunner::class) class PsiCheckerCustomTest : AbstractPsiCheckerTest() { + @TestMetadata("noUnusedParameterWhenCustom.kt") fun testNoUnusedParameterWhenCustom() { val testAnnotation = "MyTestAnnotation" EntryPointsManagerBase.getInstance(project).ADDITIONAL_ANNOTATIONS.add(testAnnotation) diff --git a/idea/tests/org/jetbrains/kotlin/idea/AbstractCopyPasteTest.kt b/idea/tests/org/jetbrains/kotlin/idea/AbstractCopyPasteTest.kt index 1eac34f6a92..ead64c83263 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/AbstractCopyPasteTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/AbstractCopyPasteTest.kt @@ -10,7 +10,6 @@ import com.intellij.openapi.util.io.FileUtil import com.intellij.psi.PsiFile import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase import org.jetbrains.kotlin.psi.KtFile -import java.io.File abstract class AbstractCopyPasteTest : KotlinLightCodeInsightFixtureTestCase() { private var savedImportsOnPasteSetting: Int = 0 @@ -28,23 +27,21 @@ abstract class AbstractCopyPasteTest : KotlinLightCodeInsightFixtureTestCase() { } protected fun configureByDependencyIfExists(dependencyFileName: String): PsiFile? { - val file = File(testDataPath + File.separator + dependencyFileName) + val file = testDataFile(dependencyFileName) if (!file.exists()) return null return if (dependencyFileName.endsWith(".java")) { //allow test framework to put it under right directory myFixture.addClass(FileUtil.loadFile(file, true)).containingFile - } - else { + } else { myFixture.configureByFile(dependencyFileName) } } - protected fun configureTargetFile(fileName: String): KtFile { - if (File(testDataPath + File.separator + fileName).exists()) { - return myFixture.configureByFile(fileName) as KtFile - } - else { - return myFixture.configureByText(fileName, DEFAULT_TO_FILE_TEXT) as KtFile + protected fun configureTargetFile(fileName: String): KtFile { + return if (testDataFile(fileName).exists()) { + myFixture.configureByFile(fileName) as KtFile + } else { + myFixture.configureByText(fileName, DEFAULT_TO_FILE_TEXT) as KtFile } } } diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/AbstractBreadcrumbsTest.kt b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/AbstractBreadcrumbsTest.kt index c82b7fa83e2..a04a9c78985 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/AbstractBreadcrumbsTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/AbstractBreadcrumbsTest.kt @@ -8,28 +8,26 @@ package org.jetbrains.kotlin.idea.codeInsight import com.intellij.testFramework.LightProjectDescriptor import org.jetbrains.kotlin.idea.test.KotlinLightPlatformCodeInsightFixtureTestCase import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor -import org.jetbrains.kotlin.idea.test.PluginTestCaseBase import org.jetbrains.kotlin.test.KotlinTestUtils import java.io.File abstract class AbstractBreadcrumbsTest : KotlinLightPlatformCodeInsightFixtureTestCase() { override fun getProjectDescriptor(): LightProjectDescriptor? = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE - override fun getTestDataPath() = PluginTestCaseBase.getTestDataPathBase() + "/codeInsight/breadcrumbs" - - protected open fun doTest(path: String) { - assert(path.endsWith(".kt")) { path } - myFixture.configureByFile(path) + protected open fun doTest(unused: String) { + val fileName = fileName() + assert(fileName.endsWith(".kt")) { fileName } + myFixture.configureByFile(fileName) val element = myFixture.file.findElementAt(myFixture.caretOffset)!! val provider = KotlinBreadcrumbsInfoProvider() val elements = generateSequence(element) { provider.getParent(it) } - .filter { provider.acceptElement(it) } - .toList() - .asReversed() + .filter { provider.acceptElement(it) } + .toList() + .asReversed() val crumbs = elements.joinToString(separator = "\n") { " " + provider.getElementInfo(it) } val tooltips = elements.joinToString(separator = "\n") { " " + provider.getElementTooltip(it) } val resultText = "Crumbs:\n$crumbs\nTooltips:\n$tooltips" - KotlinTestUtils.assertEqualsToFile(File(testDataPath + "/" + File(path).nameWithoutExtension + ".txt"), resultText) + KotlinTestUtils.assertEqualsToFile(testDataFile(File(fileName).nameWithoutExtension + ".txt"), resultText) } } \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/AbstractBreadcrumbsTest.kt.193 b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/AbstractBreadcrumbsTest.kt.193 deleted file mode 100644 index 616e6d068bf..00000000000 --- a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/AbstractBreadcrumbsTest.kt.193 +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2010-2019 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.codeInsight - -import com.intellij.testFramework.LightProjectDescriptor -import org.jetbrains.kotlin.idea.test.KotlinLightPlatformCodeInsightFixtureTestCase -import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor -import org.jetbrains.kotlin.idea.test.PluginTestCaseBase -import org.jetbrains.kotlin.test.KotlinTestUtils -import java.io.File - -abstract class AbstractBreadcrumbsTest : KotlinLightPlatformCodeInsightFixtureTestCase() { - override fun getProjectDescriptor(): LightProjectDescriptor? = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE - - override fun getTestDataPath() = PluginTestCaseBase.getTestDataPathBase() + "/codeInsight/breadcrumbs" - - protected open fun doTest(path: String) { - assert(path.endsWith(".kt")) { path } - myFixture.configureByFile(path.substringAfterLast('/')) - - val element = myFixture.file.findElementAt(myFixture.caretOffset)!! - val provider = KotlinBreadcrumbsInfoProvider() - val elements = generateSequence(element) { provider.getParent(it) } - .filter { provider.acceptElement(it) } - .toList() - .asReversed() - val crumbs = elements.joinToString(separator = "\n") { " " + provider.getElementInfo(it) } - val tooltips = elements.joinToString(separator = "\n") { " " + provider.getElementTooltip(it) } - val resultText = "Crumbs:\n$crumbs\nTooltips:\n$tooltips" - KotlinTestUtils.assertEqualsToFile(File(testDataPath + "/" + File(path).nameWithoutExtension + ".txt"), resultText) - } -} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/AbstractExpressionTypeTest.kt b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/AbstractExpressionTypeTest.kt index b6d43db4fab..6cf89b19459 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/AbstractExpressionTypeTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/AbstractExpressionTypeTest.kt @@ -8,16 +8,14 @@ package org.jetbrains.kotlin.idea.codeInsight import com.intellij.testFramework.UsefulTestCase import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor -import org.jetbrains.kotlin.idea.test.PluginTestCaseBase import org.jetbrains.kotlin.test.InTextDirectivesUtils abstract class AbstractExpressionTypeTest : KotlinLightCodeInsightFixtureTestCase() { - override fun getBasePath() = PluginTestCaseBase.TEST_DATA_PROJECT_RELATIVE + "/codeInsight/expressionType" override fun getProjectDescriptor() = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE protected fun doTest(path: String) { - myFixture.configureByFile(path) + myFixture.configureByFile(fileName()) val expressionTypeProvider = KotlinExpressionTypeProvider() val elementAtCaret = myFixture.file.findElementAt(myFixture.editor.caretModel.offset)!! val expressions = expressionTypeProvider.getExpressionsAt(elementAtCaret) diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/AbstractExpressionTypeTest.kt.193 b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/AbstractExpressionTypeTest.kt.193 deleted file mode 100644 index 2d73438c8bc..00000000000 --- a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/AbstractExpressionTypeTest.kt.193 +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2010-2019 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.codeInsight - -import com.intellij.testFramework.UsefulTestCase -import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase -import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor -import org.jetbrains.kotlin.idea.test.PluginTestCaseBase -import org.jetbrains.kotlin.test.InTextDirectivesUtils - -abstract class AbstractExpressionTypeTest : KotlinLightCodeInsightFixtureTestCase() { - override fun getBasePath() = PluginTestCaseBase.TEST_DATA_PROJECT_RELATIVE + "/codeInsight/expressionType" - - override fun getProjectDescriptor() = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE - - protected fun doTest(path: String) { - myFixture.configureByFile(fileName()) - val expressionTypeProvider = KotlinExpressionTypeProvider() - val elementAtCaret = myFixture.file.findElementAt(myFixture.editor.caretModel.offset)!! - val expressions = expressionTypeProvider.getExpressionsAt(elementAtCaret) - val types = expressions.map { "${it.text.replace('\n', ' ')} -> ${expressionTypeProvider.getInformationHint(it)}" } - val expectedTypes = InTextDirectivesUtils.findLinesWithPrefixesRemoved(myFixture.file.text, "// TYPE: ") - UsefulTestCase.assertOrderedEquals(types, expectedTypes) - } -} diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/AbstractInsertImportOnPasteTest.kt b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/AbstractInsertImportOnPasteTest.kt index 44eb731d46a..db730bbcb4c 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/AbstractInsertImportOnPasteTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/AbstractInsertImportOnPasteTest.kt @@ -8,22 +8,16 @@ package org.jetbrains.kotlin.idea.codeInsight import com.intellij.openapi.actionSystem.IdeActions import com.intellij.openapi.util.io.FileUtil import org.jetbrains.kotlin.idea.AbstractCopyPasteTest -import org.jetbrains.kotlin.idea.test.PluginTestCaseBase import org.jetbrains.kotlin.idea.test.dumpTextWithErrors import org.jetbrains.kotlin.idea.util.application.runWriteAction import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.test.InTextDirectivesUtils import org.jetbrains.kotlin.test.KotlinTestUtils -import java.io.File abstract class AbstractInsertImportOnPasteTest : AbstractCopyPasteTest() { - private val BASE_PATH = PluginTestCaseBase.getTestDataPathBase() + "/copyPaste/imports" - private val NO_ERRORS_DUMP_DIRECTIVE = "// NO_ERRORS_DUMP" private val DELETE_DEPENDENCIES_BEFORE_PASTE_DIRECTIVE = "// DELETE_DEPENDENCIES_BEFORE_PASTE" - override fun getTestDataPath() = BASE_PATH - protected fun doTestCut(path: String) { doTestAction(IdeActions.ACTION_CUT, path) } @@ -32,9 +26,8 @@ abstract class AbstractInsertImportOnPasteTest : AbstractCopyPasteTest() { doTestAction(IdeActions.ACTION_COPY, path) } - private fun doTestAction(cutOrCopy: String, path: String) { - myFixture.testDataPath = BASE_PATH - val testFile = File(path) + private fun doTestAction(cutOrCopy: String, unused: String) { + val testFile = testDataFile() val testFileText = FileUtil.loadFile(testFile, true) val testFileName = testFile.name @@ -57,13 +50,13 @@ abstract class AbstractInsertImportOnPasteTest : AbstractCopyPasteTest() { performNotWriteEditorAction(IdeActions.ACTION_PASTE) val namesToImportDump = KotlinCopyPasteReferenceProcessor.declarationsToImportSuggested.joinToString("\n") - KotlinTestUtils.assertEqualsToFile(File(path.replace(".kt", ".expected.names")), namesToImportDump) + KotlinTestUtils.assertEqualsToFile(testDataFile(testFileName.replace(".kt", ".expected.names")), namesToImportDump) val resultFile = myFixture.file as KtFile val resultText = if (InTextDirectivesUtils.isDirectiveDefined(testFileText, NO_ERRORS_DUMP_DIRECTIVE)) resultFile.text else resultFile.dumpTextWithErrors() - KotlinTestUtils.assertEqualsToFile(File(path.replace(".kt", ".expected.kt")), resultText) + KotlinTestUtils.assertEqualsToFile(testDataFile(testFileName.replace(".kt", ".expected.kt")), resultText) } } diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/AbstractLineMarkersTest.kt b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/AbstractLineMarkersTest.kt index 38f29b7a352..658aedc5efd 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/AbstractLineMarkersTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/AbstractLineMarkersTest.kt @@ -23,7 +23,6 @@ import org.jetbrains.kotlin.idea.navigation.NavigationTestUtils import org.jetbrains.kotlin.idea.test.ConfigLibraryUtil import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor -import org.jetbrains.kotlin.idea.test.PluginTestCaseBase import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.test.InTextDirectivesUtils import org.jetbrains.kotlin.test.KotlinTestUtils @@ -34,10 +33,6 @@ import java.io.File abstract class AbstractLineMarkersTest : KotlinLightCodeInsightFixtureTestCase() { - override fun getBasePath(): String { - return PluginTestCaseBase.TEST_DATA_PROJECT_RELATIVE + "/codeInsight/lineMarker" - } - override fun getProjectDescriptor(): LightProjectDescriptor { return KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE } @@ -56,14 +51,14 @@ abstract class AbstractLineMarkersTest : KotlinLightCodeInsightFixtureTestCase() } fun doTest(path: String, additionalCheck: () -> Unit) { - val fileText = FileUtil.loadFile(File(path)) + val fileText = FileUtil.loadFile(testDataFile()) try { ConfigLibraryUtil.configureLibrariesByDirective(myFixture.module, PlatformTestUtil.getCommunityPath(), fileText) if (InTextDirectivesUtils.findStringWithPrefixes(fileText, "METHOD_SEPARATORS") != null) { DaemonCodeAnalyzerSettings.getInstance().SHOW_METHOD_SEPARATORS = true } - myFixture.configureByFile(path) + myFixture.configureByFile(fileName()) val project = myFixture.project val document = myFixture.editor.document @@ -72,7 +67,7 @@ abstract class AbstractLineMarkersTest : KotlinLightCodeInsightFixtureTestCase() PsiDocumentManager.getInstance(project).commitAllDocuments() - val markers = doAndCheckHighlighting(myFixture.project, document, data, File(path)) + val markers = doAndCheckHighlighting(myFixture.project, document, data, testDataFile()) assertNavigationElements(myFixture.project, myFixture.file as KtFile, markers) additionalCheck() diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/AbstractLineMarkersTest.kt.193 b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/AbstractLineMarkersTest.kt.193 deleted file mode 100644 index e11b51d8dbd..00000000000 --- a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/AbstractLineMarkersTest.kt.193 +++ /dev/null @@ -1,189 +0,0 @@ -/* - * Copyright 2010-2019 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.codeInsight - -import com.intellij.codeInsight.daemon.DaemonCodeAnalyzerSettings -import com.intellij.codeInsight.daemon.LineMarkerInfo -import com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl -import com.intellij.openapi.editor.Document -import com.intellij.openapi.project.Project -import com.intellij.openapi.util.io.FileUtil -import com.intellij.psi.PsiDocumentManager -import com.intellij.rt.execution.junit.FileComparisonFailure -import com.intellij.testFramework.ExpectedHighlightingData -import com.intellij.testFramework.LightProjectDescriptor -import com.intellij.testFramework.PlatformTestUtil -import com.intellij.testFramework.UsefulTestCase -import junit.framework.TestCase -import org.jetbrains.kotlin.idea.highlighter.markers.TestableLineMarkerNavigator -import org.jetbrains.kotlin.idea.navigation.NavigationTestUtils -import org.jetbrains.kotlin.idea.test.ConfigLibraryUtil -import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase -import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor -import org.jetbrains.kotlin.idea.test.PluginTestCaseBase -import org.jetbrains.kotlin.psi.KtFile -import org.jetbrains.kotlin.test.InTextDirectivesUtils -import org.jetbrains.kotlin.test.KotlinTestUtils -import org.jetbrains.kotlin.test.TagsTestDataUtil -import org.jetbrains.kotlin.test.util.renderAsGotoImplementation -import org.junit.Assert -import java.io.File - -abstract class AbstractLineMarkersTest : KotlinLightCodeInsightFixtureTestCase() { - - override fun getBasePath(): String { - return PluginTestCaseBase.TEST_DATA_PROJECT_RELATIVE + "/codeInsight/lineMarker" - } - - override fun getProjectDescriptor(): LightProjectDescriptor { - return KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE - } - - fun doTest(path: String) = doTest(path) {} - - protected fun doAndCheckHighlighting( - project: Project, - documentToAnalyze: Document, - expectedHighlighting: ExpectedHighlightingData, - expectedFile: File - ): List> { - myFixture.doHighlighting() - - return checkHighlighting(project, documentToAnalyze, expectedHighlighting, expectedFile) - } - - fun doTest(path: String, additionalCheck: () -> Unit) { - val fileText = FileUtil.loadFile(File(path)) - try { - ConfigLibraryUtil.configureLibrariesByDirective(myFixture.module, PlatformTestUtil.getCommunityPath(), fileText) - if (InTextDirectivesUtils.findStringWithPrefixes(fileText, "METHOD_SEPARATORS") != null) { - DaemonCodeAnalyzerSettings.getInstance().SHOW_METHOD_SEPARATORS = true - } - - myFixture.configureByFile(fileName()) - val project = myFixture.project - val document = myFixture.editor.document - - val data = ExpectedHighlightingData(document, false, false, false, myFixture.file) - data.init() - - PsiDocumentManager.getInstance(project).commitAllDocuments() - - val markers = doAndCheckHighlighting(myFixture.project, document, data, File(path)) - - assertNavigationElements(myFixture.project, myFixture.file as KtFile, markers) - additionalCheck() - } catch (exc: Exception) { - throw RuntimeException(exc) - } finally { - ConfigLibraryUtil.unconfigureLibrariesByDirective(module, fileText) - DaemonCodeAnalyzerSettings.getInstance().SHOW_METHOD_SEPARATORS = false - } - - } - - companion object { - - @Suppress("SpellCheckingInspection") - private const val LINE_MARKER_PREFIX = "LINEMARKER:" - private const val TARGETS_PREFIX = "TARGETS" - - fun assertNavigationElements(project: Project, file: KtFile, markers: List>) { - val navigationDataComments = KotlinTestUtils.getLastCommentsInFile( - file, KotlinTestUtils.CommentType.BLOCK_COMMENT, false - ) - if (navigationDataComments.isEmpty()) return - - for ((navigationCommentIndex, navigationComment) in navigationDataComments.reversed().withIndex()) { - val description = getLineMarkerDescription(navigationComment) - val navigateMarkers = markers.filter { it.lineMarkerTooltip?.startsWith(description) == true } - val navigateMarker = navigateMarkers.singleOrNull() ?: navigateMarkers.getOrNull(navigationCommentIndex) - - TestCase.assertNotNull( - String.format("Can't find marker for navigation check with description \"%s\"", description), - navigateMarker - ) - - val handler = navigateMarker!!.navigationHandler - if (handler is TestableLineMarkerNavigator) { - val navigateElements = handler.getTargetsPopupDescriptor(navigateMarker.element)?.targets?.sortedBy { - it.renderAsGotoImplementation() - } - val actualNavigationData = NavigationTestUtils.getNavigateElementsText(project, navigateElements) - - UsefulTestCase.assertSameLines(getExpectedNavigationText(navigationComment), actualNavigationData) - } else { - Assert.fail("Only TestableLineMarkerNavigator are supported in navigate check") - } - } - } - - private fun getLineMarkerDescription(navigationComment: String): String { - val firstLineEnd = navigationComment.indexOf("\n") - TestCase.assertTrue( - "The first line in block comment must contain description of marker for navigation check", firstLineEnd != -1 - ) - - var navigationMarkerText = navigationComment.substring(0, firstLineEnd) - - TestCase.assertTrue( - String.format("Add %s directive in first line of comment", LINE_MARKER_PREFIX), - navigationMarkerText.startsWith(LINE_MARKER_PREFIX) - ) - - navigationMarkerText = navigationMarkerText.substring(LINE_MARKER_PREFIX.length) - - return navigationMarkerText.trim { it <= ' ' } - } - - private fun getExpectedNavigationText(navigationComment: String): String { - val firstLineEnd = navigationComment.indexOf("\n") - - var expectedNavigationText = navigationComment.substring(firstLineEnd + 1) - - TestCase.assertTrue( - String.format("Marker %s is expected before navigation data", TARGETS_PREFIX), - expectedNavigationText.startsWith(TARGETS_PREFIX) - ) - - expectedNavigationText = expectedNavigationText.substring(expectedNavigationText.indexOf("\n") + 1) - - return expectedNavigationText - } - - fun checkHighlighting( - project: Project, - documentToAnalyze: Document, - expectedHighlighting: ExpectedHighlightingData, - expectedFile: File - ): MutableList> { - val markers = DaemonCodeAnalyzerImpl.getLineMarkers(documentToAnalyze, project) - - try { - expectedHighlighting.checkLineMarkers(markers, documentToAnalyze.text) - - // This is a workaround for sad bug in ExpectedHighlightingData: - // the latter doesn't throw assertion error when some line markers are expected, but none are present. - if (FileUtil.loadFile(expectedFile).contains(" - name.startsWith(fileNameBase) && name != mainFileName && (name.endsWith(".kt") || name.endsWith(".java")) - } - .forEach { - myFixture.configureByFile(File(rootDir, it).path.replace(File.separator, "/")) - } + .list { _, name -> + name.startsWith(fileNameBase) && name != mainFileName && (name.endsWith(".kt") || name.endsWith(".java")) + } + .forEach { + myFixture.configureByFile(it) + } - configure(path, fileText) + configure(fileName(), fileText) mainPsiFile = myFixture.file as KtFile val targetPlatformName = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// PLATFORM: ") diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/generate/AbstractCodeInsightActionTest.kt.193 b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/generate/AbstractCodeInsightActionTest.kt.193 deleted file mode 100644 index fb8a4f5e640..00000000000 --- a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/generate/AbstractCodeInsightActionTest.kt.193 +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright 2010-2019 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.codeInsight.generate - -import com.intellij.codeInsight.actions.CodeInsightAction -import com.intellij.openapi.actionSystem.AnAction -import com.intellij.openapi.actionSystem.Presentation -import com.intellij.openapi.util.io.FileUtil -import com.intellij.refactoring.util.CommonRefactoringUtil -import com.intellij.testFramework.PlatformTestUtil -import com.intellij.testFramework.TestActionEvent -import junit.framework.ComparisonFailure -import junit.framework.TestCase -import org.jetbrains.kotlin.idea.project.forcedTargetPlatform -import org.jetbrains.kotlin.idea.test.ConfigLibraryUtil -import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase -import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor -import org.jetbrains.kotlin.psi.KtFile -import org.jetbrains.kotlin.platform.CommonPlatforms -import org.jetbrains.kotlin.platform.js.JsPlatforms -import org.jetbrains.kotlin.platform.jvm.JvmPlatforms -import org.jetbrains.kotlin.test.InTextDirectivesUtils -import org.jetbrains.kotlin.test.KotlinTestUtils -import java.io.File - -abstract class AbstractCodeInsightActionTest : KotlinLightCodeInsightFixtureTestCase() { - protected open fun createAction(fileText: String): CodeInsightAction { - val actionClassName = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// ACTION_CLASS: ") - return Class.forName(actionClassName).newInstance() as CodeInsightAction - } - - protected open fun configure(mainFilePath: String, mainFileText: String) { - myFixture.configureByFile(fileName()) as KtFile - } - - protected open fun checkExtra() { - - } - - protected open fun testAction(action: AnAction, forced: Boolean): Presentation { - val e = TestActionEvent(action) - action.beforeActionPerformedUpdate(e) - if (forced || (e.presentation.isEnabled && e.presentation.isVisible)) { - action.actionPerformed(e) - } - return e.presentation - } - - protected open fun doTest(path: String) { - val fileText = FileUtil.loadFile(File(path), true) - - val conflictFile = File("$path.messages") - val afterFile = File("$path.after") - - var mainPsiFile: KtFile? = null - - try { - ConfigLibraryUtil.configureLibrariesByDirective(module, PlatformTestUtil.getCommunityPath(), fileText) - - val mainFile = File(path) - val mainFileName = mainFile.name - val fileNameBase = mainFile.nameWithoutExtension + "." - val rootDir = mainFile.parentFile - rootDir - .list { _, name -> - name.startsWith(fileNameBase) && name != mainFileName && (name.endsWith(".kt") || name.endsWith(".java")) - } - .forEach { - myFixture.configureByFile(File(rootDir, it).path.replace(File.separator, "/")) - } - - configure(path, fileText) - mainPsiFile = myFixture.file as KtFile - - val targetPlatformName = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// PLATFORM: ") - if (targetPlatformName != null) { - val targetPlatform = when (targetPlatformName) { - "JVM" -> JvmPlatforms.unspecifiedJvmPlatform - "JavaScript" -> JsPlatforms.defaultJsPlatform - "Common" -> CommonPlatforms.defaultCommonPlatform - else -> error("Unexpected platform name: $targetPlatformName") - } - mainPsiFile.forcedTargetPlatform = targetPlatform - } - - val action = createAction(fileText) - - val isApplicableExpected = !InTextDirectivesUtils.isDirectiveDefined(fileText, "// NOT_APPLICABLE") - val isForced = InTextDirectivesUtils.isDirectiveDefined(fileText, "// FORCED") - - val presentation = testAction(action, isForced) - if (!isForced) { - TestCase.assertEquals(isApplicableExpected, presentation.isEnabled) - } - - assert(!conflictFile.exists()) { "Conflict file $conflictFile should not exist" } - - if (isForced || isApplicableExpected) { - TestCase.assertTrue(afterFile.exists()) - myFixture.checkResult(FileUtil.loadFile(afterFile, true)) - checkExtra() - } - } - catch (e: ComparisonFailure) { - KotlinTestUtils.assertEqualsToFile(afterFile, myFixture.editor) - } - catch (e: CommonRefactoringUtil.RefactoringErrorHintException) { - KotlinTestUtils.assertEqualsToFile(conflictFile, e.message!!) - } - finally { - mainPsiFile?.forcedTargetPlatform = null - ConfigLibraryUtil.unconfigureLibrariesByDirective(module, fileText) - } - } - - override fun getProjectDescriptor() = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE -} diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/generate/AbstractGenerateHashCodeAndEqualsActionTest.kt b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/generate/AbstractGenerateHashCodeAndEqualsActionTest.kt index ec4461359c4..98eb1d45e00 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/generate/AbstractGenerateHashCodeAndEqualsActionTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/generate/AbstractGenerateHashCodeAndEqualsActionTest.kt @@ -9,13 +9,12 @@ import com.intellij.codeInsight.CodeInsightSettings import com.intellij.openapi.util.io.FileUtil import org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateEqualsAndHashcodeAction import org.jetbrains.kotlin.test.InTextDirectivesUtils -import java.io.File abstract class AbstractGenerateHashCodeAndEqualsActionTest : AbstractCodeInsightActionTest() { override fun createAction(fileText: String) = KotlinGenerateEqualsAndHashcodeAction() override fun doTest(path: String) { - val fileText = FileUtil.loadFile(File(path), true) + val fileText = FileUtil.loadFile(testDataFile(), true) val codeInsightSettings = CodeInsightSettings.getInstance() val useInstanceOfOnEqualsParameterOld = codeInsightSettings.USE_INSTANCEOF_ON_EQUALS_PARAMETER diff --git a/idea/tests/org/jetbrains/kotlin/idea/coverage/AbstractKotlinCoverageOutputFilesTest.kt b/idea/tests/org/jetbrains/kotlin/idea/coverage/AbstractKotlinCoverageOutputFilesTest.kt index dc098dda4f5..811a98f137a 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/coverage/AbstractKotlinCoverageOutputFilesTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/coverage/AbstractKotlinCoverageOutputFilesTest.kt @@ -14,23 +14,19 @@ import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.test.KotlinTestUtils import java.io.File -abstract class AbstractKotlinCoverageOutputFilesTest(): KotlinLightCodeInsightFixtureTestCase() { - private val TEST_DATA_PATH = PluginTestCaseBase.getTestDataPathBase() + "/coverage/outputFiles" - - override fun getTestDataPath(): String = TEST_DATA_PATH - +abstract class AbstractKotlinCoverageOutputFilesTest: KotlinLightCodeInsightFixtureTestCase() { fun doTest(path: String) { - val kotlinFile = myFixture.configureByFile(path) as KtFile + val kotlinFile = myFixture.configureByFile(fileName()) as KtFile val outDir = myFixture.tempDirFixture.findOrCreateDir("coverageTestOut") try { - FileUtil.loadLines(File(path.replace(".kt", ".classes.txt"))).forEach { + FileUtil.loadLines(File(testPath().replace(".kt", ".classes.txt"))).forEach { runWriteAction { createEmptyFile(outDir, it) } } val actualClasses = KotlinCoverageExtension.collectGeneratedClassQualifiedNames(outDir, kotlinFile) - KotlinTestUtils.assertEqualsToFile(File(path.replace(".kt", ".expected.txt")), actualClasses!!.joinToString("\n")) + KotlinTestUtils.assertEqualsToFile(File(testPath().replace(".kt", ".expected.txt")), actualClasses!!.joinToString("\n")) } finally { runWriteAction { diff --git a/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/AbstractCodeFragmentAutoImportTest.kt b/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/AbstractCodeFragmentAutoImportTest.kt index 516f9f93c53..7721f7cbd9f 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/AbstractCodeFragmentAutoImportTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/AbstractCodeFragmentAutoImportTest.kt @@ -8,8 +8,6 @@ package org.jetbrains.kotlin.idea.debugger.evaluate import org.jetbrains.kotlin.checkers.AbstractPsiCheckerTest import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor import org.jetbrains.kotlin.psi.KtCodeFragment -import org.jetbrains.kotlin.test.KotlinTestUtils -import java.io.File import kotlin.test.assertNull abstract class AbstractCodeFragmentAutoImportTest : AbstractPsiCheckerTest() { @@ -21,15 +19,14 @@ abstract class AbstractCodeFragmentAutoImportTest : AbstractPsiCheckerTest() { ?: error("No import fix available") importFix.invoke(project, editor, file) - myFixture.checkResultByFile("$filePath.after") + myFixture.checkResultByFile("${fileName()}.after") val fragment = myFixture.file as KtCodeFragment - fragment.checkImports(testDataPath + File.separator + filePath) + fragment.checkImports(testPath()) val fixAfter = myFixture.availableIntentions.firstOrNull { it.familyName == "Import" } assertNull(fixAfter, "No import fix should be available after") } override fun getProjectDescriptor() = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE - override fun getTestDataPath() = KotlinTestUtils.getHomeDirectory() } diff --git a/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/AbstractCodeFragmentCompletionHandlerTest.kt b/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/AbstractCodeFragmentCompletionHandlerTest.kt index 4f9fecc94f3..67e87b9208b 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/AbstractCodeFragmentCompletionHandlerTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/AbstractCodeFragmentCompletionHandlerTest.kt @@ -11,7 +11,7 @@ import org.jetbrains.kotlin.psi.KtCodeFragment abstract class AbstractCodeFragmentCompletionHandlerTest : AbstractCompletionHandlerTest(CompletionType.BASIC) { override fun setUpFixture(testPath: String) { - myFixture.configureByCodeFragment(testPath) + myFixture.configureByCodeFragment(testPath(testPath)) } override fun doTest(testPath: String) { diff --git a/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/AbstractEditorForEvaluateExpressionTest.kt.193 b/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/AbstractEditorForEvaluateExpressionTest.kt.193 deleted file mode 100644 index 214ae8f4e56..00000000000 --- a/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/AbstractEditorForEvaluateExpressionTest.kt.193 +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright 2010-2019 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.debugger.evaluate - -import com.intellij.codeInsight.completion.CompletionType -import com.intellij.codeInspection.InspectionProfileEntry -import com.intellij.openapi.util.io.FileUtil -import com.intellij.openapi.util.text.StringUtil -import com.intellij.psi.PsiElement -import com.intellij.psi.util.PsiTreeUtil -import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture -import org.jetbrains.kotlin.checkers.AbstractPsiCheckerTest -import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithContent -import org.jetbrains.kotlin.idea.caches.resolve.resolveImportReference -import org.jetbrains.kotlin.idea.completion.test.AbstractJvmBasicCompletionTest -import org.jetbrains.kotlin.idea.completion.test.ExpectedCompletionUtils -import org.jetbrains.kotlin.idea.completion.test.handlers.AbstractCompletionHandlerTest -import org.jetbrains.kotlin.idea.debugger.getContextElement -import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor -import org.jetbrains.kotlin.idea.util.ImportInsertHelper -import org.jetbrains.kotlin.idea.util.application.executeWriteCommand -import org.jetbrains.kotlin.name.FqName -import org.jetbrains.kotlin.psi.* -import org.jetbrains.kotlin.resolve.BindingContext -import org.jetbrains.kotlin.test.InTextDirectivesUtils -import org.jetbrains.kotlin.test.KotlinTestUtils -import java.io.File -import kotlin.test.assertNull -import kotlin.test.assertTrue - -abstract class AbstractCodeFragmentHighlightingTest : AbstractPsiCheckerTest() { - override fun doTest(filePath: String) { - myFixture.configureByCodeFragment(testDataFile()) - checkHighlighting(filePath) - } - - fun doTestWithImport(filePath: String) { - myFixture.configureByCodeFragment(testDataFile()) - - project.executeWriteCommand("Imports insertion") { - val fileText = FileUtil.loadFile(File(filePath), true) - val file = myFixture.file as KtFile - InTextDirectivesUtils.findListWithPrefixes(fileText, "// IMPORT: ").forEach { - val descriptor = file.resolveImportReference(FqName(it)).singleOrNull() - ?: error("Could not resolve descriptor to import: $it") - ImportInsertHelper.getInstance(project).importDescriptor(file, descriptor) - } - } - - checkHighlighting(filePath) - } - - private fun checkHighlighting(filePath: String) { - val inspectionName = InTextDirectivesUtils.findStringWithPrefixes(File(filePath).readText(), "// INSPECTION_CLASS: ") - if (inspectionName != null) { - val inspection = Class.forName(inspectionName).newInstance() as InspectionProfileEntry - myFixture.enableInspections(inspection) - try { - myFixture.checkHighlighting(true, false, false) - } finally { - myFixture.disableInspections(inspection) - } - return - } - - myFixture.checkHighlighting(true, false, false) - } -} - -abstract class AbstractCodeFragmentCompletionTest : AbstractJvmBasicCompletionTest() { - override fun setUpFixture(testPath: String) { - myFixture.configureByCodeFragment(testDataFile()) - } -} - -abstract class AbstractCodeFragmentCompletionHandlerTest : AbstractCompletionHandlerTest(CompletionType.BASIC) { - override fun setUpFixture(testPath: String) { - myFixture.configureByCodeFragment(testDataFile()) - } - - override fun doTest(testPath: String) { - super.doTest(testPath) - - val fragment = myFixture.file as KtCodeFragment - fragment.checkImports(testPath) - } -} - -abstract class AbstractCodeFragmentAutoImportTest : AbstractPsiCheckerTest() { - override fun doTest(filePath: String) { - myFixture.configureByCodeFragment(testDataFile()) - myFixture.doHighlighting() - - val importFix = myFixture.availableIntentions.singleOrNull { it.familyName == "Import" } - ?: error("No import fix available") - importFix.invoke(project, editor, file) - - myFixture.checkResultByFile(filePath + ".after") - - val fragment = myFixture.file as KtCodeFragment - fragment.checkImports(testDataPath + File.separator + filePath) - - val fixAfter = myFixture.availableIntentions.firstOrNull { it.familyName == "Import" } - assertNull(fixAfter, "No import fix should be available after") - } - - override fun getProjectDescriptor() = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE - override fun getTestDataPath() = KotlinTestUtils.getHomeDirectory() -} - -private fun KtCodeFragment.checkImports(testPath: String) { - val importList = importsAsImportList() - val importsText = StringUtil.convertLineSeparators(importList?.text ?: "") - val fragmentAfterFile = File(testPath + ".after.imports") - - if (fragmentAfterFile.exists()) { - KotlinTestUtils.assertEqualsToFile(fragmentAfterFile, importsText) - } - else { - assertTrue(importsText.isEmpty(), "Unexpected imports found: $importsText" ) - } -} - -private fun JavaCodeInsightTestFixture.configureByCodeFragment(testDataFile: File) { - configureByFile(testDataFile.name) - - val elementAt = file?.findElementAt(caretOffset) - val file = createCodeFragment(testDataFile.path, elementAt!!) - - val typeStr = InTextDirectivesUtils.findStringWithPrefixes(getFile().text, "// ${ExpectedCompletionUtils.RUNTIME_TYPE} ") - if (typeStr != null) { - file.putCopyableUserData(KtCodeFragment.RUNTIME_TYPE_EVALUATOR, { - val codeFragment = KtPsiFactory(project).createBlockCodeFragment("val xxx: $typeStr", PsiTreeUtil.getParentOfType(elementAt, KtElement::class.java)) - val context = codeFragment.analyzeWithContent() - val typeReference: KtTypeReference = PsiTreeUtil.getChildOfType(codeFragment.getContentElement().firstChild, KtTypeReference::class.java)!! - context[BindingContext.TYPE, typeReference] - }) - } - - configureFromExistingVirtualFile(file.virtualFile!!) -} - -private fun createCodeFragment(filePath: String, contextElement: PsiElement): KtCodeFragment { - val fileForFragment = File(filePath + ".fragment") - val codeFragmentText = FileUtil.loadFile(fileForFragment, true).trim() - val psiFactory = KtPsiFactory(contextElement.project) - if (fileForFragment.readLines().size == 1) { - return psiFactory.createExpressionCodeFragment(codeFragmentText, getContextElement(contextElement)) - } - return psiFactory.createBlockCodeFragment(codeFragmentText, getContextElement(contextElement)) -} diff --git a/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/AbstractSelectExpressionForDebuggerTest.kt.193 b/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/AbstractSelectExpressionForDebuggerTest.kt.193 deleted file mode 100644 index 1cf11f116ac..00000000000 --- a/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/AbstractSelectExpressionForDebuggerTest.kt.193 +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2010-2019 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.debugger.evaluate - -import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase -import org.jetbrains.kotlin.idea.debugger.KotlinEditorTextProvider -import org.jetbrains.kotlin.idea.test.KotlinLightProjectDescriptor -import org.jetbrains.kotlin.idea.test.PluginTestCaseBase -import org.jetbrains.kotlin.idea.test.invalidateLibraryCache -import org.jetbrains.kotlin.test.InTextDirectivesUtils -import org.junit.Assert - -abstract class AbstractSelectExpressionForDebuggerTest : LightCodeInsightFixtureTestCase() { - - override fun setUp() { - super.setUp() - invalidateLibraryCache(project) - } - - fun doTest(path: String) { - doTest(path, true) - } - - fun doTestWoMethodCalls(path: String) { - doTest(path, false) - } - - fun doTest(path: String, allowMethodCalls: Boolean) { - myFixture.configureByFile(path.substringAfterLast('/')) - - val elementAt = myFixture.file?.findElementAt(myFixture.caretOffset)!! - val selectedExpression = KotlinEditorTextProvider.findExpressionInner(elementAt, allowMethodCalls) - - val expected = InTextDirectivesUtils.findStringWithPrefixes(myFixture.file?.text!!, "// EXPECTED: ") - val actualResult = if (selectedExpression != null) - KotlinEditorTextProvider.getElementInfo(selectedExpression) { it.text } - else - "null" - - Assert.assertEquals("Another expression should be selected", expected, actualResult) - } - - override fun getProjectDescriptor() = KotlinLightProjectDescriptor.INSTANCE - - override fun getTestDataPath() = PluginTestCaseBase.getTestDataPathBase() + "/debugger/selectExpression" -} diff --git a/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/CodeFragmentTestUtils.kt b/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/CodeFragmentTestUtils.kt index 6dde00a4170..08b9c134fbf 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/CodeFragmentTestUtils.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/debugger/evaluate/CodeFragmentTestUtils.kt @@ -36,7 +36,7 @@ internal fun KtCodeFragment.checkImports(testPath: String) { } internal fun JavaCodeInsightTestFixture.configureByCodeFragment(filePath: String) { - configureByFile(filePath) + configureByFile(File(filePath).name) val elementAt = file?.findElementAt(caretOffset) val file = createCodeFragment(filePath, elementAt!!) diff --git a/idea/tests/org/jetbrains/kotlin/idea/decompiler/stubBuilder/BuiltInDecompilerTest.kt b/idea/tests/org/jetbrains/kotlin/idea/decompiler/stubBuilder/BuiltInDecompilerTest.kt index c9d4d185ca9..94554faabfd 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/decompiler/stubBuilder/BuiltInDecompilerTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/decompiler/stubBuilder/BuiltInDecompilerTest.kt @@ -51,7 +51,7 @@ class BuiltInDecompilerForWrongAbiVersionTest : AbstractBuiltInDecompilerTest() override fun getTestDataPath() = PluginTestCaseBase.TEST_DATA_DIR + "/decompiler/builtins/" override fun configureAndBuildFileStub(packageFqName: String): PsiFileStub<*> { - myFixture.configureByFile(testDataPath + BuiltInSerializerProtocol.getBuiltInsFilePath(FqName(packageFqName))) + myFixture.configureByFile(BuiltInSerializerProtocol.getBuiltInsFilePath(FqName(packageFqName))) return KotlinBuiltInDecompiler().stubBuilder.buildFileStub(FileContentImpl.createByFile(myFixture.file.virtualFile))!! } diff --git a/idea/tests/org/jetbrains/kotlin/idea/externalAnnotations/ExternalAnnotationTest.kt b/idea/tests/org/jetbrains/kotlin/idea/externalAnnotations/ExternalAnnotationTest.kt index 0f7baad1509..98597e2d80c 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/externalAnnotations/ExternalAnnotationTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/externalAnnotations/ExternalAnnotationTest.kt @@ -7,6 +7,7 @@ import com.intellij.openapi.util.io.FileUtil import com.intellij.openapi.vfs.VfsUtilCore import com.intellij.psi.codeStyle.JavaCodeStyleSettings import com.intellij.testFramework.LightPlatformTestCase +import com.intellij.testFramework.TestDataPath import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor import org.jetbrains.kotlin.idea.util.application.runWriteAction @@ -19,6 +20,8 @@ import java.io.File @RunWith(JUnit3WithIdeaConfigurationRunner::class) class ExternalAnnotationTest : KotlinLightCodeInsightFixtureTestCase() { + override fun getTestDataPath() = KotlinTestUtils.getHomeDirectory() + fun testNotNullMethod() { KotlinTestUtils.runTest(::doTest, TargetBackend.ANY, "idea/testData/externalAnnotations/notNullMethod.kt") } diff --git a/idea/tests/org/jetbrains/kotlin/idea/highlighter/AbstractDslHighlighterTest.kt b/idea/tests/org/jetbrains/kotlin/idea/highlighter/AbstractDslHighlighterTest.kt index 5c995cf7ce6..1b3af009ab6 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/highlighter/AbstractDslHighlighterTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/highlighter/AbstractDslHighlighterTest.kt @@ -8,20 +8,20 @@ package org.jetbrains.kotlin.idea.highlighter import com.intellij.codeInsight.daemon.impl.AnnotationHolderImpl import com.intellij.lang.annotation.AnnotationSession import com.intellij.psi.PsiComment -import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithAllCompilerChecks import org.jetbrains.kotlin.idea.highlighter.dsl.DslHighlighterExtension +import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor import org.jetbrains.kotlin.psi.KtElement import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.psi.KtTreeVisitor import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall -abstract class AbstractDslHighlighterTest : LightCodeInsightFixtureTestCase() { +abstract class AbstractDslHighlighterTest : KotlinLightCodeInsightFixtureTestCase() { override fun getProjectDescriptor() = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE - protected fun doTest(filePath: String) { - val psiFile = myFixture.configureByFile(filePath) as KtFile + protected fun doTest(unused: String) { + val psiFile = myFixture.configureByFile(fileName()) as KtFile val extension = DslHighlighterExtension() val bindingContext = psiFile.analyzeWithAllCompilerChecks().bindingContext @@ -64,5 +64,4 @@ abstract class AbstractDslHighlighterTest : LightCodeInsightFixtureTestCase() { psiFile.accept(visitor) } - override fun getTestDataPath() = "" } \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/highlighter/AbstractUsageHighlightingTest.kt b/idea/tests/org/jetbrains/kotlin/idea/highlighter/AbstractUsageHighlightingTest.kt index b3821c9ef33..3e1fdfcdfcc 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/highlighter/AbstractUsageHighlightingTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/highlighter/AbstractUsageHighlightingTest.kt @@ -23,8 +23,8 @@ abstract class AbstractUsageHighlightingTest : KotlinLightCodeInsightFixtureTest const val CARET_TAG = "~" } - protected fun doTest(filePath: String) { - myFixture.configureByFile(filePath) + protected fun doTest(unused: String) { + myFixture.configureByFile(fileName()) val document = myFixture.editor.document val data = ExpectedHighlightingData(document, false, false, true, false, myFixture.file) data.init() @@ -65,5 +65,4 @@ abstract class AbstractUsageHighlightingTest : KotlinLightCodeInsightFixtureTest } override fun getProjectDescriptor(): KotlinLightProjectDescriptor = KotlinLightProjectDescriptor.INSTANCE - override fun getTestDataPath() = "" } diff --git a/idea/tests/org/jetbrains/kotlin/idea/intentions/AbstractConcatenatedStringGeneratorTest.kt b/idea/tests/org/jetbrains/kotlin/idea/intentions/AbstractConcatenatedStringGeneratorTest.kt index 2a1c23a7d9e..c663dea9ad7 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/AbstractConcatenatedStringGeneratorTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/AbstractConcatenatedStringGeneratorTest.kt @@ -20,12 +20,12 @@ import java.io.File abstract class AbstractConcatenatedStringGeneratorTest : KotlinLightCodeInsightFixtureTestCase() { @Throws(Exception::class) protected fun doTest(path: String) { - myFixture.configureByFile(path) + myFixture.configureByFile(fileName()) val expression = myFixture.file.collectDescendantsOfType().lastOrNull() TestCase.assertNotNull("No binary expression found: $path", expression) val generatedString = ConcatenatedStringGenerator().create(expression!!) - KotlinTestUtils.assertEqualsToFile(File("$path.result"), generatedString) + KotlinTestUtils.assertEqualsToFile(File("${testPath()}.result"), generatedString) } } diff --git a/idea/tests/org/jetbrains/kotlin/idea/navigation/AbstractKotlinGotoTest.java b/idea/tests/org/jetbrains/kotlin/idea/navigation/AbstractKotlinGotoTest.java index 93fa8958f1b..644b6e16496 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/navigation/AbstractKotlinGotoTest.java +++ b/idea/tests/org/jetbrains/kotlin/idea/navigation/AbstractKotlinGotoTest.java @@ -15,12 +15,12 @@ import static org.jetbrains.kotlin.idea.navigation.GotoCheck.checkGotoDirectives public abstract class AbstractKotlinGotoTest extends KotlinLightCodeInsightFixtureTestCase { protected void doSymbolTest(String path) { - myFixture.configureByFile(path); + myFixture.configureByFile(fileName()); checkGotoDirectives(new GotoSymbolModel2(getProject()), myFixture.getEditor()); } protected void doClassTest(String path) { - myFixture.configureByFile(path); + myFixture.configureByFile(fileName()); checkGotoDirectives(new GotoClassModel2(getProject()), myFixture.getEditor()); } diff --git a/idea/tests/org/jetbrains/kotlin/idea/navigation/AbstractKotlinGotoTest.java.193 b/idea/tests/org/jetbrains/kotlin/idea/navigation/AbstractKotlinGotoTest.java.193 deleted file mode 100644 index 644b6e16496..00000000000 --- a/idea/tests/org/jetbrains/kotlin/idea/navigation/AbstractKotlinGotoTest.java.193 +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2010-2019 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.navigation; - -import com.intellij.ide.util.gotoByName.GotoClassModel2; -import com.intellij.ide.util.gotoByName.GotoSymbolModel2; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase; -import org.jetbrains.kotlin.test.KotlinTestUtils; - -import static org.jetbrains.kotlin.idea.navigation.GotoCheck.checkGotoDirectives; - -public abstract class AbstractKotlinGotoTest extends KotlinLightCodeInsightFixtureTestCase { - protected void doSymbolTest(String path) { - myFixture.configureByFile(fileName()); - checkGotoDirectives(new GotoSymbolModel2(getProject()), myFixture.getEditor()); - } - - protected void doClassTest(String path) { - myFixture.configureByFile(fileName()); - checkGotoDirectives(new GotoClassModel2(getProject()), myFixture.getEditor()); - } - - private String dirPath = null; - - @Override - protected void setUp() { - dirPath = KotlinTestUtils.getTestsRoot(getClass()); - super.setUp(); - } - - @Override - protected void tearDown() { - super.tearDown(); - dirPath = null; - } - - @NotNull - @Override - protected String getTestDataPath() { - return dirPath; - } - - @NotNull - @Override - protected String fileName() { - return getTestName(true) + ".kt"; - } -} diff --git a/idea/tests/org/jetbrains/kotlin/idea/refactoring/AbstractNameSuggestionProviderTest.kt b/idea/tests/org/jetbrains/kotlin/idea/refactoring/AbstractNameSuggestionProviderTest.kt index ff90eaf1403..9fce04f27ee 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/refactoring/AbstractNameSuggestionProviderTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/refactoring/AbstractNameSuggestionProviderTest.kt @@ -27,7 +27,7 @@ abstract class AbstractNameSuggestionProviderTest : KotlinLightCodeInsightFixtur } protected fun doTest(path: String) { - val file = myFixture.configureByFile(path) + val file = myFixture.configureByFile(fileName()) val targetElement = TargetElementUtil.findTargetElement( myFixture.editor, TargetElementUtil.ELEMENT_NAME_ACCEPTED or TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED diff --git a/idea/tests/org/jetbrains/kotlin/idea/refactoring/AbstractNameSuggestionProviderTest.kt.193 b/idea/tests/org/jetbrains/kotlin/idea/refactoring/AbstractNameSuggestionProviderTest.kt.193 deleted file mode 100644 index 93a8535eea3..00000000000 --- a/idea/tests/org/jetbrains/kotlin/idea/refactoring/AbstractNameSuggestionProviderTest.kt.193 +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2010-2019 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.refactoring - -import com.intellij.codeInsight.TargetElementUtil -import com.intellij.psi.PsiElement -import com.intellij.refactoring.rename.NameSuggestionProvider -import com.intellij.refactoring.rename.PreferrableNameSuggestionProvider -import junit.framework.TestCase -import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase -import org.jetbrains.kotlin.idea.test.ProjectDescriptorWithStdlibSources -import org.jetbrains.kotlin.test.InTextDirectivesUtils - -abstract class AbstractNameSuggestionProviderTest : KotlinLightCodeInsightFixtureTestCase() { - private fun getSuggestNames(element: PsiElement): List { - val names = HashSet() - for (provider in NameSuggestionProvider.EP_NAME.extensions) { - val info = provider.getSuggestedNames(element, null, names) - if (info != null) { - if (provider is PreferrableNameSuggestionProvider && !provider.shouldCheckOthers()) break - } - } - return names.sorted() - } - - protected fun doTest(path: String) { - val file = myFixture.configureByFile(fileName()) - val targetElement = TargetElementUtil.findTargetElement( - myFixture.editor, - TargetElementUtil.ELEMENT_NAME_ACCEPTED or TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED - )!! - val expectedNames = InTextDirectivesUtils.findListWithPrefixes(file.text, "// SUGGESTED_NAMES: ") - val actualNames = getSuggestNames(targetElement) - TestCase.assertEquals(expectedNames, actualNames) - } - - override fun getProjectDescriptor() = ProjectDescriptorWithStdlibSources.INSTANCE -} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/refactoring/inline/AbstractInlineTest.kt b/idea/tests/org/jetbrains/kotlin/idea/refactoring/inline/AbstractInlineTest.kt index 9873908ca04..5b1322ab3c1 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/refactoring/inline/AbstractInlineTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/refactoring/inline/AbstractInlineTest.kt @@ -29,17 +29,17 @@ abstract class AbstractInlineTest : KotlinLightCodeInsightFixtureTestCase() { val fixture: JavaCodeInsightTestFixture get() = myFixture - protected fun doTest(path: String) { - val mainFile = File(path) - val afterFile = File(path + ".after") + protected fun doTest(unused: String) { + val mainFile = testDataFile() + val afterFile = File(testDataPath, "${fileName()}.after") val mainFileName = mainFile.name val mainFileBaseName = FileUtil.getNameWithoutExtension(mainFileName) val extraFiles = mainFile.parentFile.listFiles { _, name -> name != mainFileName && name.startsWith("$mainFileBaseName.") && (name.endsWith(".kt") || name.endsWith(".java")) } - val extraFilesToPsi = extraFiles.associateBy { fixture.configureByFile(path.replace(mainFileName, it.name)) } - val file = myFixture.configureByFile(path) + val extraFilesToPsi = extraFiles.associateBy { fixture.configureByFile(it.name) } + val file = myFixture.configureByFile(fileName()) val configured = configureCompilerOptions(file.text, project, module) diff --git a/idea/tests/org/jetbrains/kotlin/idea/refactoring/inline/AbstractInlineTest.kt.193 b/idea/tests/org/jetbrains/kotlin/idea/refactoring/inline/AbstractInlineTest.kt.193 deleted file mode 100644 index c020758098b..00000000000 --- a/idea/tests/org/jetbrains/kotlin/idea/refactoring/inline/AbstractInlineTest.kt.193 +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2010-2019 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.refactoring.inline - -import com.intellij.codeInsight.TargetElementUtil -import com.intellij.codeInsight.TargetElementUtil.ELEMENT_NAME_ACCEPTED -import com.intellij.codeInsight.TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED -import com.intellij.lang.refactoring.InlineActionHandler -import com.intellij.openapi.extensions.Extensions -import com.intellij.openapi.util.io.FileUtil -import com.intellij.refactoring.BaseRefactoringProcessor -import com.intellij.refactoring.util.CommonRefactoringUtil -import com.intellij.testFramework.UsefulTestCase -import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture -import junit.framework.TestCase -import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase -import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor -import org.jetbrains.kotlin.idea.test.configureCompilerOptions -import org.jetbrains.kotlin.idea.test.rollbackCompilerOptions -import org.jetbrains.kotlin.idea.util.application.runWriteAction -import org.jetbrains.kotlin.test.InTextDirectivesUtils -import org.jetbrains.kotlin.test.KotlinTestUtils -import java.io.File - -abstract class AbstractInlineTest : KotlinLightCodeInsightFixtureTestCase() { - val fixture: JavaCodeInsightTestFixture - get() = myFixture - - protected fun doTest(path: String) { - val mainFile = File(path) - val afterFile = File(path + ".after") - - val mainFileName = mainFile.name - val mainFileBaseName = FileUtil.getNameWithoutExtension(mainFileName) - val extraFiles = mainFile.parentFile.listFiles { _, name -> - name != mainFileName && name.startsWith("$mainFileBaseName.") && (name.endsWith(".kt") || name.endsWith(".java")) - } - val extraFilesToPsi = extraFiles.associateBy { fixture.configureByFile(path.replace(mainFileName, it.name)) } - val file = myFixture.configureByFile(fileName()) - - val configured = configureCompilerOptions(file.text, project, module) - - try { - val afterFileExists = afterFile.exists() - - val targetElement = TargetElementUtil.findTargetElement(myFixture.editor, ELEMENT_NAME_ACCEPTED or REFERENCED_ELEMENT_ACCEPTED)!! - val handler = Extensions.getExtensions(InlineActionHandler.EP_NAME).firstOrNull { it.canInlineElement(targetElement) } - val expectedErrors = InTextDirectivesUtils.findLinesWithPrefixesRemoved(myFixture.file.text, "// ERROR: ") - if (handler != null) { - try { - runWriteAction { handler.inlineElement(myFixture.project, myFixture.editor, targetElement) } - - UsefulTestCase.assertEmpty(expectedErrors) - KotlinTestUtils.assertEqualsToFile(afterFile, file.text) - for ((extraPsiFile, extraFile) in extraFilesToPsi) { - KotlinTestUtils.assertEqualsToFile(File("${extraFile.path}.after"), extraPsiFile.text) - } - } - catch (e: CommonRefactoringUtil.RefactoringErrorHintException) { - TestCase.assertFalse("Refactoring not available: ${e.message}", afterFileExists) - TestCase.assertEquals("Expected errors", 1, expectedErrors.size) - TestCase.assertEquals("Error message", expectedErrors[0].replace("\\n", "\n"), e.message) - } - catch (e: BaseRefactoringProcessor.ConflictsInTestsException) { - TestCase.assertFalse("Conflicts: ${e.message}", afterFileExists) - TestCase.assertEquals("Expected errors", 1, expectedErrors.size) - TestCase.assertEquals("Error message", expectedErrors[0].replace("\\n", "\n"), e.message) - } - } - else { - TestCase.assertFalse("No refactoring handler available", afterFileExists) - } - } finally { - if (configured) { - rollbackCompilerOptions(project, module) - } - } - } - - override fun getProjectDescriptor() = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE -} diff --git a/idea/tests/org/jetbrains/kotlin/idea/resolve/AbstractReferenceResolveInJavaTest.kt b/idea/tests/org/jetbrains/kotlin/idea/resolve/AbstractReferenceResolveInJavaTest.kt index 23d0bee2603..500614d14b6 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/resolve/AbstractReferenceResolveInJavaTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/resolve/AbstractReferenceResolveInJavaTest.kt @@ -5,6 +5,7 @@ package org.jetbrains.kotlin.idea.resolve +import com.intellij.openapi.util.io.FileUtil import com.intellij.psi.PsiElement import org.jetbrains.kotlin.asJava.elements.KtLightElement import org.jetbrains.kotlin.idea.decompiler.classFile.KtClsFile @@ -12,21 +13,23 @@ import org.jetbrains.kotlin.idea.test.PluginTestCaseBase import org.jetbrains.kotlin.idea.test.SdkAndMockLibraryProjectDescriptor import org.jetbrains.kotlin.psi.KtDeclaration import org.junit.Assert +import java.io.File private val FILE_WITH_KOTLIN_CODE = PluginTestCaseBase.TEST_DATA_DIR + "/resolve/referenceInJava/dependency/dependencies.kt" abstract class AbstractReferenceResolveInJavaTest : AbstractReferenceResolveTest() { override fun doTest(path: String) { - assert(path.endsWith(".java")) { path } - myFixture.configureByFile(FILE_WITH_KOTLIN_CODE) - myFixture.configureByFile(path) + val fileName = fileName() + assert(fileName.endsWith(".java")) { fileName } + myFixture.configureByText("dependencies.kt", FileUtil.loadFile(File(FILE_WITH_KOTLIN_CODE), true)) + myFixture.configureByFile(fileName) performChecks() } } abstract class AbstractReferenceToCompiledKotlinResolveInJavaTest : AbstractReferenceResolveTest() { override fun doTest(path: String) { - myFixture.configureByFile(path) + myFixture.configureByFile(fileName()) performChecks() } @@ -37,7 +40,13 @@ abstract class AbstractReferenceToCompiledKotlinResolveInJavaTest : AbstractRefe override fun checkResolvedTo(element: PsiElement) { val navigationElement = element.navigationElement - Assert.assertFalse("Reference should not navigate to a light element\nWas: ${navigationElement::class.java.simpleName}", navigationElement is KtLightElement<*, *>) - Assert.assertTrue("Reference should navigate to a kotlin declaration\nWas: ${navigationElement::class.java.simpleName}", navigationElement is KtDeclaration || navigationElement is KtClsFile) + Assert.assertFalse( + "Reference should not navigate to a light element\nWas: ${navigationElement::class.java.simpleName}", + navigationElement is KtLightElement<*, *> + ) + Assert.assertTrue( + "Reference should navigate to a kotlin declaration\nWas: ${navigationElement::class.java.simpleName}", + navigationElement is KtDeclaration || navigationElement is KtClsFile + ) } } diff --git a/idea/tests/org/jetbrains/kotlin/idea/resolve/AbstractReferenceResolveInLibrarySourcesTest.kt b/idea/tests/org/jetbrains/kotlin/idea/resolve/AbstractReferenceResolveInLibrarySourcesTest.kt index 26b4278a266..7b80e68388c 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/resolve/AbstractReferenceResolveInLibrarySourcesTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/resolve/AbstractReferenceResolveInLibrarySourcesTest.kt @@ -8,40 +8,36 @@ package org.jetbrains.kotlin.idea.resolve import junit.framework.AssertionFailedError import org.jetbrains.kotlin.idea.navigation.NavigationTestUtils import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase -import org.jetbrains.kotlin.idea.test.PluginTestCaseBase import org.jetbrains.kotlin.test.InTextDirectivesUtils import org.junit.Assert -import java.io.File abstract class AbstractReferenceResolveInLibrarySourcesTest : KotlinLightCodeInsightFixtureTestCase() { companion object { private val REF_CARET_MARKER = "" } - fun doTest(path: String) { + fun doTest(unused: String) { val fixture = myFixture!! - fixture.configureByFile(path) + fixture.configureByFile(fileName()) val expectedResolveData = AbstractReferenceResolveTest.readResolveData(fixture.file!!.text, 0) val gotoData = NavigationTestUtils.invokeGotoImplementations(fixture.editor, fixture.file)!! - Assert.assertEquals("Single target expected for origianl file", 1, gotoData.targets.size) + Assert.assertEquals("Single target expected for original file", 1, gotoData.targets.size) val testedPsiElement = gotoData.targets[0].navigationElement val testedElementFile = testedPsiElement.containingFile!! val lineContext = InTextDirectivesUtils.findStringWithPrefixes(fixture.file!!.text, "CONTEXT:") - if (lineContext == null) { - throw AssertionFailedError("'CONTEXT: ' directive is expected to set up position in library file: ${testedElementFile.name}") - } + ?: throw AssertionFailedError("'CONTEXT: ' directive is expected to set up position in library file: ${testedElementFile.name}") val inContextOffset = lineContext.indexOf(REF_CARET_MARKER) - if (inContextOffset == -1) throw IllegalStateException("No '$REF_CARET_MARKER' marker found in 'CONTEXT: $lineContext'") + check(inContextOffset != -1) { "No '$REF_CARET_MARKER' marker found in 'CONTEXT: $lineContext'" } val contextStr = lineContext.replace(REF_CARET_MARKER, "") val offsetInFile = testedElementFile.text!!.indexOf(contextStr) - if (offsetInFile == -1) throw IllegalStateException("Context '$contextStr' wasn't found in file ${testedElementFile.name}") + check(offsetInFile != -1) { "Context '$contextStr' wasn't found in file ${testedElementFile.name}" } val offset = offsetInFile + inContextOffset @@ -50,6 +46,4 @@ abstract class AbstractReferenceResolveInLibrarySourcesTest : KotlinLightCodeIns AbstractReferenceResolveTest.checkReferenceResolve(expectedResolveData, offset, reference) } - override fun getTestDataPath() : String = File(PluginTestCaseBase.getTestDataPathBase(), "/resolve/referenceInLib").path + File.separator - override fun fileName(): String = getTestName(true) + ".kt" } diff --git a/idea/tests/org/jetbrains/kotlin/idea/resolve/AbstractReferenceToJavaWithWrongFileStructureTest.java b/idea/tests/org/jetbrains/kotlin/idea/resolve/AbstractReferenceToJavaWithWrongFileStructureTest.java index 4c6c56fdf0f..e2622b8e079 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/resolve/AbstractReferenceToJavaWithWrongFileStructureTest.java +++ b/idea/tests/org/jetbrains/kotlin/idea/resolve/AbstractReferenceToJavaWithWrongFileStructureTest.java @@ -11,8 +11,9 @@ public abstract class AbstractReferenceToJavaWithWrongFileStructureTest extends @Override protected void doTest(@NotNull String path) { //this line intentionally creates wrong file structure for java file - myFixture.configureByFile(path.replace(".kt", ".java")); - myFixture.configureByFile(path); + String fileName = fileName(); + myFixture.configureByFile(fileName.replace(".kt", ".java")); + myFixture.configureByFile(fileName); performChecks(); } } diff --git a/idea/tests/org/jetbrains/kotlin/idea/stubs/AbstractResolveByStubTest.kt b/idea/tests/org/jetbrains/kotlin/idea/stubs/AbstractResolveByStubTest.kt index 3b84a09f84b..5afaa6309f1 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/stubs/AbstractResolveByStubTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/stubs/AbstractResolveByStubTest.kt @@ -22,16 +22,17 @@ import java.io.File abstract class AbstractResolveByStubTest : KotlinLightCodeInsightFixtureTestCase() { protected fun doTest(testFileName: String) { - if (InTextDirectivesUtils.isDirectiveDefined(File(testFileName).readText(), "NO_CHECK_SOURCE_VS_BINARY")) { + if (InTextDirectivesUtils.isDirectiveDefined(testDataFile().readText(), "NO_CHECK_SOURCE_VS_BINARY")) { // If NO_CHECK_SOURCE_VS_BINARY is enabled, source vs binary descriptors differ, which means that we should not run this test: // it would compare descriptors resolved from sources (by stubs) with .txt, which describes binary descriptors return } - myFixture.configureByFile(testFileName) + val fileName = fileName() + myFixture.configureByFile(fileName) val shouldFail = getTestName(false) == "ClassWithConstVal" AstAccessControl.testWithControlledAccessToAst(shouldFail, project, testRootDisposable) { - performTest(testFileName) + performTest(testPath()) } } diff --git a/idea/tests/org/jetbrains/kotlin/idea/stubs/AbstractResolveByStubTest.kt.193 b/idea/tests/org/jetbrains/kotlin/idea/stubs/AbstractResolveByStubTest.kt.193 deleted file mode 100644 index 7d047181367..00000000000 --- a/idea/tests/org/jetbrains/kotlin/idea/stubs/AbstractResolveByStubTest.kt.193 +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2010-2019 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.stubs - -import com.intellij.openapi.util.io.FileUtil -import com.intellij.testFramework.LightProjectDescriptor -import org.jetbrains.kotlin.idea.caches.resolve.findModuleDescriptor -import org.jetbrains.kotlin.idea.test.AstAccessControl -import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase -import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor -import org.jetbrains.kotlin.load.java.descriptors.PossiblyExternalAnnotationDescriptor -import org.jetbrains.kotlin.name.FqName -import org.jetbrains.kotlin.psi.KtFile -import org.jetbrains.kotlin.test.InTextDirectivesUtils -import org.jetbrains.kotlin.test.util.DescriptorValidator.ValidationVisitor.errorTypesForbidden -import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator -import org.junit.Assert -import java.io.File - -abstract class AbstractResolveByStubTest : KotlinLightCodeInsightFixtureTestCase() { - protected fun doTest(testFileName: String) { - if (InTextDirectivesUtils.isDirectiveDefined(File(testFileName).readText(), "NO_CHECK_SOURCE_VS_BINARY")) { - // If NO_CHECK_SOURCE_VS_BINARY is enabled, source vs binary descriptors differ, which means that we should not run this test: - // it would compare descriptors resolved from sources (by stubs) with .txt, which describes binary descriptors - return - } - - myFixture.configureByFile(fileName()) - val shouldFail = getTestName(false) == "ClassWithConstVal" - AstAccessControl.testWithControlledAccessToAst(shouldFail, project, testRootDisposable) { - performTest(testFileName) - } - } - - override fun getProjectDescriptor(): LightProjectDescriptor = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE - - private fun performTest(path: String) { - val file = file as KtFile - val module = file.findModuleDescriptor() - val packageViewDescriptor = module.getPackage(FqName("test")) - Assert.assertFalse(packageViewDescriptor.isEmpty()) - - val fileToCompareTo = File(FileUtil.getNameWithoutExtension(path) + ".txt") - - RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile( - packageViewDescriptor, - RecursiveDescriptorComparator.DONT_INCLUDE_METHODS_OF_OBJECT - .filterRecursion(RecursiveDescriptorComparator.SKIP_BUILT_INS_PACKAGES) - .checkPrimaryConstructors(true) - .checkPropertyAccessors(true) - .withValidationStrategy(errorTypesForbidden()) - .withRendererOptions { options -> - options.annotationFilter = { annotationDescriptor -> - annotationDescriptor !is PossiblyExternalAnnotationDescriptor || !annotationDescriptor.isIdeExternalAnnotation - } - }, - fileToCompareTo - ) - } -} diff --git a/idea/tests/org/jetbrains/kotlin/idea/stubs/AbstractStubBuilderTest.kt b/idea/tests/org/jetbrains/kotlin/idea/stubs/AbstractStubBuilderTest.kt index 58e189dd55d..7b72bfbc91f 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/stubs/AbstractStubBuilderTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/stubs/AbstractStubBuilderTest.kt @@ -7,7 +7,7 @@ package org.jetbrains.kotlin.idea.stubs import com.intellij.psi.impl.DebugUtil import com.intellij.psi.stubs.StubElement -import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase +import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase import org.jetbrains.kotlin.name.SpecialNames import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.psi.stubs.elements.KtFileStubBuilder @@ -16,13 +16,13 @@ import org.jetbrains.kotlin.test.KotlinTestUtils import java.io.File -abstract class AbstractStubBuilderTest : LightCodeInsightFixtureTestCase() { - protected fun doTest(sourcePath: String) { - val file = myFixture.configureByFile(sourcePath) as KtFile - val jetStubBuilder = KtFileStubBuilder() - val lighterTree = jetStubBuilder.buildStubTree(file) +abstract class AbstractStubBuilderTest : KotlinLightCodeInsightFixtureTestCase() { + protected fun doTest(unused: String) { + val file = myFixture.configureByFile(fileName()) as KtFile + val ktStubBuilder = KtFileStubBuilder() + val lighterTree = ktStubBuilder.buildStubTree(file) val stubTree = serializeStubToString(lighterTree) - val expectedFile = sourcePath.replace(".kt", ".expected") + val expectedFile = testPath().replace(".kt", ".expected") KotlinTestUtils.assertEqualsToFile(File(expectedFile), stubTree) } diff --git a/idea/tests/org/jetbrains/kotlin/psi/patternMatching/AbstractPsiUnifierTest.kt b/idea/tests/org/jetbrains/kotlin/psi/patternMatching/AbstractPsiUnifierTest.kt index 548d3b7d332..cafe63196a9 100644 --- a/idea/tests/org/jetbrains/kotlin/psi/patternMatching/AbstractPsiUnifierTest.kt +++ b/idea/tests/org/jetbrains/kotlin/psi/patternMatching/AbstractPsiUnifierTest.kt @@ -17,7 +17,7 @@ import org.jetbrains.kotlin.test.KotlinTestUtils import java.io.File abstract class AbstractPsiUnifierTest : KotlinLightCodeInsightFixtureTestCase() { - fun doTest(filePath: String) { + fun doTest(unused: String) { fun findPattern(file: KtFile): KtElement { val selectionModel = myFixture.editor.selectionModel val start = selectionModel.selectionStart @@ -29,8 +29,7 @@ abstract class AbstractPsiUnifierTest : KotlinLightCodeInsightFixtureTestCase() } as KtElement } - myFixture.configureByFile(filePath) - val file = myFixture.file as KtFile + val file = myFixture.configureByFile(fileName()) as KtFile DirectiveBasedActionUtils.checkForUnexpectedErrors(file) @@ -40,7 +39,7 @@ abstract class AbstractPsiUnifierTest : KotlinLightCodeInsightFixtureTestCase() .match(file, KotlinPsiUnifier.DEFAULT) .map { it.range.getTextRange().substring(file.getText()!!) } .joinToString("\n\n") - KotlinTestUtils.assertEqualsToFile(File("$filePath.match"), actualText) + KotlinTestUtils.assertEqualsToFile(File(testDataPath, "${fileName()}.match"), actualText) } override fun getProjectDescriptor(): LightProjectDescriptor = getProjectDescriptorFromTestName() diff --git a/idea/tests/org/jetbrains/kotlin/search/AbstractInheritorsSearchTest.java b/idea/tests/org/jetbrains/kotlin/search/AbstractInheritorsSearchTest.java index a76ea9a2c2d..bcad01d77c4 100644 --- a/idea/tests/org/jetbrains/kotlin/search/AbstractInheritorsSearchTest.java +++ b/idea/tests/org/jetbrains/kotlin/search/AbstractInheritorsSearchTest.java @@ -6,9 +6,7 @@ package org.jetbrains.kotlin.search; import org.jetbrains.annotations.NotNull; -import org.jetbrains.kotlin.idea.test.PluginTestCaseBase; -import java.io.File; import java.io.IOException; public abstract class AbstractInheritorsSearchTest extends AbstractSearcherTest { @@ -16,8 +14,4 @@ public abstract class AbstractInheritorsSearchTest extends AbstractSearcherTest checkClassWithDirectives(path); } - @Override - protected String getTestDataPath() { - return new File(PluginTestCaseBase.getTestDataPathBase(), "/search/inheritance").getPath() + File.separator; - } } diff --git a/idea/tests/org/jetbrains/kotlin/search/AbstractSearcherTest.java b/idea/tests/org/jetbrains/kotlin/search/AbstractSearcherTest.java index dc979e7ae35..6a69f316139 100644 --- a/idea/tests/org/jetbrains/kotlin/search/AbstractSearcherTest.java +++ b/idea/tests/org/jetbrains/kotlin/search/AbstractSearcherTest.java @@ -10,10 +10,10 @@ import com.intellij.psi.*; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.search.searches.ClassInheritorsSearch; import com.intellij.testFramework.LightProjectDescriptor; -import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase; import com.intellij.util.Query; import kotlin.collections.CollectionsKt; import org.jetbrains.annotations.NotNull; +import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase; import org.jetbrains.kotlin.idea.test.KotlinLightProjectDescriptor; import org.jetbrains.kotlin.idea.test.TestUtilsKt; import org.jetbrains.kotlin.test.InTextDirectivesUtils; @@ -24,9 +24,9 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -public abstract class AbstractSearcherTest extends LightCodeInsightFixtureTestCase { +public abstract class AbstractSearcherTest extends KotlinLightCodeInsightFixtureTestCase { @Override - public void setUp() throws Exception { + public void setUp() { super.setUp(); TestUtilsKt.invalidateLibraryCache(getProject()); } @@ -75,14 +75,14 @@ public abstract class AbstractSearcherTest extends LightCodeInsightFixtureTestCa assertOrderedEquals(actualModified, expected); } - protected void checkClassWithDirectives(@NotNull String path) throws IOException { - myFixture.configureByFile(path); + protected void checkClassWithDirectives(@NotNull String unused) throws IOException { + myFixture.configureByFile(fileName()); List directives = InTextDirectivesUtils.findListWithPrefixes( - FileUtil.loadFile(new File(path), true), "// CLASS: "); + FileUtil.loadFile(testDataFile(), true), "// CLASS: "); assertFalse("Specify CLASS directive in test file", directives.isEmpty()); String superClassName = directives.get(0); PsiClass psiClass = getPsiClass(superClassName); - checkResult(path, ClassInheritorsSearch.search(psiClass, getProjectScope(), false)); + checkResult(testPath(), ClassInheritorsSearch.search(psiClass, getProjectScope(), false)); } private static String stringRepresentation(Object member) { diff --git a/idea/tests/org/jetbrains/kotlin/search/AnnotatedMembersSearchTest.kt b/idea/tests/org/jetbrains/kotlin/search/AnnotatedMembersSearchTest.kt index 02ad0ef4992..64f717e1bb4 100644 --- a/idea/tests/org/jetbrains/kotlin/search/AnnotatedMembersSearchTest.kt +++ b/idea/tests/org/jetbrains/kotlin/search/AnnotatedMembersSearchTest.kt @@ -18,19 +18,17 @@ import org.jetbrains.kotlin.idea.caches.lightClasses.IDELightClassConstructionCo import org.jetbrains.kotlin.idea.completion.test.withServiceRegistered import org.jetbrains.kotlin.idea.search.PsiBasedClassResolver import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor -import org.jetbrains.kotlin.idea.test.PluginTestCaseBase import org.jetbrains.kotlin.test.InTextDirectivesUtils import org.junit.Assert -import java.io.File abstract class AbstractAnnotatedMembersSearchTest : AbstractSearcherTest() { override fun getProjectDescriptor(): LightProjectDescriptor { return KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE } - fun doTest(path: String) { - myFixture.configureByFile(path) - val fileText = FileUtil.loadFile(File(path), true) + fun doTest(unused: String) { + myFixture.configureByFile(fileName()) + val fileText = FileUtil.loadFile(testDataFile(), true) val directives = InTextDirectivesUtils.findListWithPrefixes(fileText, "// ANNOTATION: ") TestCase.assertFalse("Specify ANNOTATION directive in test file", directives.isEmpty()) @@ -42,7 +40,7 @@ abstract class AbstractAnnotatedMembersSearchTest : AbstractSearcherTest() { PsiBasedClassResolver.falseHits.set(0) checkResult( - path, + testPath(), AnnotatedElementsSearch.searchElements( psiClass, projectScope, @@ -62,9 +60,6 @@ abstract class AbstractAnnotatedMembersSearchTest : AbstractSearcherTest() { } - override fun getTestDataPath(): String { - return File(PluginTestCaseBase.getTestDataPathBase(), "/search/annotations").path + File.separator - } } private object NoRealDelegatesComputed : StubComputationTracker { diff --git a/idea/tests/org/jetbrains/kotlin/search/JUnitMembersSearcherTest.java b/idea/tests/org/jetbrains/kotlin/search/JUnitMembersSearcherTest.java index 85357b36bf2..e34a40149d9 100644 --- a/idea/tests/org/jetbrains/kotlin/search/JUnitMembersSearcherTest.java +++ b/idea/tests/org/jetbrains/kotlin/search/JUnitMembersSearcherTest.java @@ -12,20 +12,22 @@ import com.intellij.psi.search.searches.AnnotatedMembersSearch; import com.intellij.testFramework.LightProjectDescriptor; import org.jetbrains.annotations.NotNull; import org.jetbrains.kotlin.idea.test.KotlinJdkAndLibraryProjectDescriptor; -import org.jetbrains.kotlin.idea.test.PluginTestCaseBase; import org.jetbrains.kotlin.test.InTextDirectivesUtils; import org.jetbrains.kotlin.test.JUnit3WithIdeaConfigurationRunner; +import org.jetbrains.kotlin.test.TestMetadata; import org.junit.runner.RunWith; import java.io.File; import java.io.IOException; import java.util.List; +@TestMetadata("idea/testData/search/junit/") @RunWith(JUnit3WithIdeaConfigurationRunner.class) public class JUnitMembersSearcherTest extends AbstractSearcherTest { private static final LightProjectDescriptor junitProjectDescriptor = new KotlinJdkAndLibraryProjectDescriptor(new File(PathManager.getHomePath().replace(File.separatorChar, '/') + "/lib/junit-4.12.jar")); + @TestMetadata("testJunit3.kt") public void testJunit3() throws IOException { doJUnit3test(); } @@ -56,11 +58,6 @@ public class JUnitMembersSearcherTest extends AbstractSearcherTest { checkResult(getPathToFile(), AnnotatedMembersSearch.search(psiClass, getProjectScope())); } - @Override - protected String getTestDataPath() { - return new File(PluginTestCaseBase.getTestDataPathBase(), "/search/junit").getPath() + File.separator; - } - @NotNull @Override protected LightProjectDescriptor getProjectDescriptor() {