From 3b563eaca18f9c9c9cbe483fe1f41b698b05f55e Mon Sep 17 00:00:00 2001 From: Vladimir Dolzhenko Date: Sun, 29 Sep 2019 10:43:38 +0200 Subject: [PATCH] Use test path relative to testDataPath in fixture.configureByFile to be complaint with 193, part 2 --- .../generators/tests/GenerateTests.kt.183 | 10 +---- .../KotlinLightCodeInsightFixtureTestCase.kt | 17 +++++---- ...manceLiteralKotlinToKotlinCopyPasteTest.kt | 14 +++---- .../idea/testFramework/projectRoutines.kt.183 | 18 ++++++++- .../jetbrains/kotlin/AbstractImportsTest.kt | 10 ++--- .../kotlin/checkers/PsiCheckerCustomTest.kt | 25 +++++++------ .../resolve/AbstractIdeLightClassTest.kt | 37 +++++++++++-------- ...bstractLiteralTextToKotlinCopyPasteTest.kt | 18 ++++----- ...TextJavaToKotlinCopyPasteConversionTest.kt | 28 ++++++-------- ...tractLiteralKotlinToKotlinCopyPasteTest.kt | 18 ++++----- .../AbstractHighlightExitPointsTest.kt | 8 ++-- .../highlighter/AbstractHighlightingTest.java | 6 +-- .../DeprecatedSymbolUsageFixSpecialTest.kt | 8 +--- .../resolve/AbstractPartialBodyResolveTest.kt | 15 ++++---- .../scratch/AbstractScratchRunActionTest.kt | 5 ++- ...TextJavaToKotlinCopyPasteConversionTest.kt | 3 -- 16 files changed, 119 insertions(+), 121 deletions(-) rename idea/tests/org/jetbrains/kotlin/idea/{editor => conversion/copy}/AbstractLiteralTextToKotlinCopyPasteTest.kt (70%) diff --git a/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt.183 b/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt.183 index b7c6839430a..7c62ecbaf3f 100644 --- a/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt.183 +++ b/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt.183 @@ -19,16 +19,7 @@ package org.jetbrains.kotlin.generators.tests import org.jetbrains.kotlin.AbstractDataFlowValueRenderingTest import org.jetbrains.kotlin.addImport.AbstractAddImportTest import org.jetbrains.kotlin.allopen.AbstractBytecodeListingTestForAllOpen -import org.jetbrains.kotlin.android.* -import org.jetbrains.kotlin.android.annotator.AbstractAndroidGutterIconTest -import org.jetbrains.kotlin.android.configure.AbstractConfigureProjectTest -import org.jetbrains.kotlin.android.folding.AbstractAndroidResourceFoldingTest -import org.jetbrains.kotlin.android.intention.AbstractAndroidIntentionTest -import org.jetbrains.kotlin.android.intention.AbstractAndroidResourceIntentionTest -import org.jetbrains.kotlin.android.lint.AbstractKotlinLintTest import org.jetbrains.kotlin.android.parcel.AbstractParcelBytecodeListingTest -import org.jetbrains.kotlin.android.quickfix.AbstractAndroidLintQuickfixTest -import org.jetbrains.kotlin.android.quickfix.AbstractAndroidQuickFixMultiFileTest import org.jetbrains.kotlin.android.synthetic.test.AbstractAndroidBoxTest import org.jetbrains.kotlin.android.synthetic.test.AbstractAndroidBytecodeShapeTest import org.jetbrains.kotlin.android.synthetic.test.AbstractAndroidSyntheticPropertyDescriptorTest @@ -1333,4 +1324,5 @@ fun main(args: Array) { model("android/gutterIcon") } } +*/ } 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 314ce45346b..dfd6257ea2c 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 @@ -29,6 +29,7 @@ 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 @@ -62,8 +63,15 @@ abstract class KotlinLightCodeInsightFixtureTestCase : KotlinLightCodeInsightFix protected open val captureExceptions = true - protected fun testPath(): String = - File(testDataPath, fileName()).toString() + protected fun testDataFile(): File = File(testDataPath, fileName()) + + protected fun testPath(): String = testDataFile().toString() + + protected open fun fileName(): String = KotlinTestUtils.getTestDataFileName(this::class.java, this.name) ?: (getTestName(false) + ".kt") + + override fun getTestDataPath(): String { + return this::class.findAnnotation()?.value ?: super.getTestDataPath() + } override fun setUp() { super.setUp() @@ -194,8 +202,6 @@ abstract class KotlinLightCodeInsightFixtureTestCase : KotlinLightCodeInsightFix protected fun isAllFilesPresentInTest(): Boolean = KotlinTestUtils.isAllFilesPresentTest(getTestName(false)) - protected open fun fileName(): String = KotlinTestUtils.getTestDataFileName(this::class.java, this.name) ?: (getTestName(false) + ".kt") - protected fun performNotWriteEditorAction(actionId: String): Boolean { val dataContext = (myFixture.editor as EditorEx).dataContext @@ -215,9 +221,6 @@ abstract class KotlinLightCodeInsightFixtureTestCase : KotlinLightCodeInsightFix return true } - override fun getTestDataPath(): String { - return this::class.findAnnotation()?.value ?: super.getTestDataPath() - } } diff --git a/idea/performanceTests/org/jetbrains/kotlin/idea/perf/AbstractPerformanceLiteralKotlinToKotlinCopyPasteTest.kt b/idea/performanceTests/org/jetbrains/kotlin/idea/perf/AbstractPerformanceLiteralKotlinToKotlinCopyPasteTest.kt index 5375f9cb17a..ec5dd591e96 100644 --- a/idea/performanceTests/org/jetbrains/kotlin/idea/perf/AbstractPerformanceLiteralKotlinToKotlinCopyPasteTest.kt +++ b/idea/performanceTests/org/jetbrains/kotlin/idea/perf/AbstractPerformanceLiteralKotlinToKotlinCopyPasteTest.kt @@ -12,7 +12,6 @@ import com.intellij.psi.PsiFile import org.jetbrains.kotlin.idea.AbstractCopyPasteTest import org.jetbrains.kotlin.idea.perf.Stats.Companion.WARM_UP import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor -import org.jetbrains.kotlin.idea.test.PluginTestCaseBase import org.jetbrains.kotlin.test.KotlinTestUtils import java.io.File @@ -22,8 +21,6 @@ import java.io.File abstract class AbstractPerformanceLiteralKotlinToKotlinCopyPasteTest : AbstractCopyPasteTest() { companion object { - val BASE_PATH = PluginTestCaseBase.getTestDataPathBase() + "/copyPaste/literal" - @JvmStatic var warmedUp: Boolean = false @@ -36,8 +33,6 @@ abstract class AbstractPerformanceLiteralKotlinToKotlinCopyPasteTest : AbstractC } } - override fun getTestDataPath() = BASE_PATH - override fun getProjectDescriptor() = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE override fun setUp() { @@ -83,14 +78,17 @@ abstract class AbstractPerformanceLiteralKotlinToKotlinCopyPasteTest : AbstractC ) } - fun doPerfTest(path: String) { + fun doPerfTest(unused: String) { val testName = getTestName(false) + val fileName = fileName() + val testPath = testPath() + val expectedPath = File(testPath.replace(".kt", ".expected.kt")) val fileEditorManager = FileEditorManagerEx.getInstance(project) stats.perfTest, Unit>( testName = testName, setUp = { - it.setUpValue = myFixture.configureByFiles("$testName.kt", "$testName.to.kt") + it.setUpValue = myFixture.configureByFiles(fileName, fileName.replace(".kt", ".to.kt")) }, test = { fileEditorManager.setSelectedEditor(it.setUpValue!![0].virtualFile, "") @@ -100,7 +98,7 @@ abstract class AbstractPerformanceLiteralKotlinToKotlinCopyPasteTest : AbstractC myFixture.performEditorAction(IdeActions.ACTION_PASTE) }, tearDown = { - KotlinTestUtils.assertEqualsToFile(File(path.replace(".kt", ".expected.kt")), it.setUpValue!![1].text) + KotlinTestUtils.assertEqualsToFile(expectedPath, it.setUpValue!![1].text) // to avoid VFS refresh myFixture.performEditorAction(IdeActions.ACTION_UNDO) diff --git a/idea/performanceTests/org/jetbrains/kotlin/idea/testFramework/projectRoutines.kt.183 b/idea/performanceTests/org/jetbrains/kotlin/idea/testFramework/projectRoutines.kt.183 index 23e1cf2e3e0..748f2f81457 100644 --- a/idea/performanceTests/org/jetbrains/kotlin/idea/testFramework/projectRoutines.kt.183 +++ b/idea/performanceTests/org/jetbrains/kotlin/idea/testFramework/projectRoutines.kt.183 @@ -5,15 +5,21 @@ package org.jetbrains.kotlin.idea.testFramework +import com.intellij.ide.startup.impl.StartupManagerImpl +import com.intellij.lang.LanguageAnnotators +import com.intellij.lang.LanguageExtensionPoint +import com.intellij.lang.annotation.Annotator import com.intellij.openapi.Disposable import com.intellij.openapi.editor.Document import com.intellij.openapi.fileEditor.FileDocumentManager import com.intellij.openapi.fileEditor.FileEditorManager import com.intellij.openapi.project.Project import com.intellij.openapi.project.ex.ProjectManagerEx +import com.intellij.openapi.startup.StartupManager import com.intellij.psi.PsiDocumentManager import com.intellij.psi.impl.PsiDocumentManagerBase import com.intellij.testFramework.EdtTestUtil +import com.intellij.testFramework.PlatformTestUtil import com.intellij.testFramework.runInEdtAndWait import com.intellij.util.ThrowableRunnable import com.intellij.util.ui.UIUtil @@ -55,13 +61,23 @@ fun dispatchAllInvocationEvents() { } } +fun loadProjectWithName(path: String, name: String): Project? = + ProjectManagerEx.getInstanceEx().loadProject(name, path) + fun closeProject(project: Project) { dispatchAllInvocationEvents() val projectManagerEx = ProjectManagerEx.getInstanceEx() projectManagerEx.closeAndDispose(project) } -// BUNCH: 183 +fun runStartupActivities(project: Project) { + with(StartupManager.getInstance(project) as StartupManagerImpl) { + scheduleInitialVfsRefresh() + runStartupActivities() + runPostStartupActivities() + } +} + fun waitForAllEditorsFinallyLoaded(project: Project) { // 183 does not have this public api } diff --git a/idea/tests/org/jetbrains/kotlin/AbstractImportsTest.kt b/idea/tests/org/jetbrains/kotlin/AbstractImportsTest.kt index ebd6237714c..a34965121b7 100644 --- a/idea/tests/org/jetbrains/kotlin/AbstractImportsTest.kt +++ b/idea/tests/org/jetbrains/kotlin/AbstractImportsTest.kt @@ -19,10 +19,10 @@ import org.jetbrains.kotlin.test.KotlinTestUtils import java.io.File abstract class AbstractImportsTest : KotlinLightCodeInsightFixtureTestCase() { - override fun getTestDataPath() = KotlinTestUtils.getHomeDirectory() override fun getProjectDescriptor(): LightProjectDescriptor = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE - protected fun doTest(testPath: String) { + protected fun doTest(unused: String) { + val testPath = testPath() CodeStyle.setTemporarySettings(project, CodeStyle.getSettings(project).clone()) val codeStyleSettings = KotlinCodeStyleSettings.getInstance(project) @@ -30,13 +30,13 @@ abstract class AbstractImportsTest : KotlinLightCodeInsightFixtureTestCase() { val fixture = myFixture val dependencySuffixes = listOf(".dependency.kt", ".dependency.java", ".dependency1.kt", ".dependency2.kt") for (suffix in dependencySuffixes) { - val dependencyPath = testPath.replace(".kt", suffix) - if (File(dependencyPath).exists()) { + val dependencyPath = fileName().replace(".kt", suffix) + if (File(testDataPath, dependencyPath).exists()) { fixture.configureByFile(dependencyPath) } } - fixture.configureByFile(testPath) + fixture.configureByFile(fileName()) val file = fixture.file as KtFile diff --git a/idea/tests/org/jetbrains/kotlin/checkers/PsiCheckerCustomTest.kt b/idea/tests/org/jetbrains/kotlin/checkers/PsiCheckerCustomTest.kt index eb485b6952e..65c73c03b52 100644 --- a/idea/tests/org/jetbrains/kotlin/checkers/PsiCheckerCustomTest.kt +++ b/idea/tests/org/jetbrains/kotlin/checkers/PsiCheckerCustomTest.kt @@ -8,35 +8,36 @@ package org.jetbrains.kotlin.checkers import com.intellij.codeInspection.ex.EntryPointsManagerBase import com.intellij.testFramework.LightProjectDescriptor import org.jetbrains.kotlin.test.JUnit3WithIdeaConfigurationRunner -import org.jetbrains.kotlin.test.KotlinTestUtils +import org.jetbrains.kotlin.test.TestMetadata import org.junit.runner.RunWith +@TestMetadata("idea/testData/checker/custom") @RunWith(JUnit3WithIdeaConfigurationRunner::class) class PsiCheckerCustomTest : AbstractPsiCheckerTest() { + fun testNoUnusedParameterWhenCustom() { val testAnnotation = "MyTestAnnotation" EntryPointsManagerBase.getInstance(project).ADDITIONAL_ANNOTATIONS.add(testAnnotation) try { - doTest(getTestDataFile("noUnusedParameterWhenCustom.kt")) - } - finally { + doTest("noUnusedParameterWhenCustom.kt") + } finally { EntryPointsManagerBase.getInstance(project).ADDITIONAL_ANNOTATIONS.remove(testAnnotation) } } fun testConflictingOverloadsMultifile1() { - doTest(getTestDataFile("conflictingOverloadsMultifile1a.kt"), - getTestDataFile("conflictingOverloadsMultifile1b.kt")) + doTest( + "conflictingOverloadsMultifile1a.kt", + "conflictingOverloadsMultifile1b.kt" + ) } fun testConflictingOverloadsMultifile2() { - doTest(getTestDataFile("conflictingOverloadsMultifile2a.kt"), - getTestDataFile("conflictingOverloadsMultifile2b.kt")) + doTest( + "conflictingOverloadsMultifile2a.kt", + "conflictingOverloadsMultifile2b.kt" + ) } - private fun getTestDataFile(localName: String) = "idea/testData/checker/custom/$localName" - - override fun getTestDataPath(): String = KotlinTestUtils.getHomeDirectory() - override fun getProjectDescriptor(): LightProjectDescriptor = getProjectDescriptorFromTestName() } \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/caches/resolve/AbstractIdeLightClassTest.kt b/idea/tests/org/jetbrains/kotlin/idea/caches/resolve/AbstractIdeLightClassTest.kt index 2026d8ec57b..f89df2f17bd 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/caches/resolve/AbstractIdeLightClassTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/caches/resolve/AbstractIdeLightClassTest.kt @@ -44,34 +44,39 @@ import kotlin.test.assertNotNull import kotlin.test.assertTrue abstract class AbstractIdeLightClassTest : KotlinLightCodeInsightFixtureTestCase() { - fun doTest(testDataPath: String) { + fun doTest(unused: String) { forceUsingOldLightClassesForTest() + val fileName = fileName() val extraFilePath = when { - testDataPath.endsWith(fileExtension) -> testDataPath.replace(fileExtension, ".extra" + fileExtension) + fileName.endsWith(fileExtension) -> fileName.replace(fileExtension, ".extra" + fileExtension) else -> error("Invalid test data extension") } - val testFiles = if (File(extraFilePath).isFile) listOf(testDataPath, extraFilePath) else listOf(testDataPath) + val testFiles = if (File(testDataPath, extraFilePath).isFile) listOf(fileName, extraFilePath) else listOf(fileName) - val lazinessMode = lazinessModeByFileText(testDataPath) + val lazinessMode = lazinessModeByFileText() myFixture.configureByFiles(*testFiles.toTypedArray()) val ktFile = myFixture.file as KtFile - val testData = File(testDataPath) - testLightClass(KotlinTestUtils.replaceExtension(testData, "java"), testData, { LightClassTestCommon.removeEmptyDefaultImpls(it) }, { fqName -> - val tracker = LightClassLazinessChecker.Tracker(fqName) - project.withServiceRegistered(tracker) { - findClass(fqName, ktFile, project)?.apply { - LightClassLazinessChecker.check(this as KtLightClass, tracker, lazinessMode) - tracker.allowLevel(EXACT) - PsiElementChecker.checkPsiElementStructure(this) + val testData = testDataFile() + testLightClass( + KotlinTestUtils.replaceExtension(testData, "java"), + testData, + { LightClassTestCommon.removeEmptyDefaultImpls(it) }, + { fqName -> + val tracker = LightClassLazinessChecker.Tracker(fqName) + project.withServiceRegistered(tracker) { + findClass(fqName, ktFile, project)?.apply { + LightClassLazinessChecker.check(this as KtLightClass, tracker, lazinessMode) + tracker.allowLevel(EXACT) + PsiElementChecker.checkPsiElementStructure(this) + } } - } - }) + }) } - private fun lazinessModeByFileText(testDataPath: String): LightClassLazinessChecker.Mode { - return File(testDataPath).readText().run { + private fun lazinessModeByFileText(): LightClassLazinessChecker.Mode { + return testDataFile().readText().run { val argument = substringAfter("LAZINESS:", "").substringBefore(" ") LightClassLazinessChecker.Mode.values().firstOrNull { it.name == argument } ?: LightClassLazinessChecker.Mode.AllChecks } diff --git a/idea/tests/org/jetbrains/kotlin/idea/editor/AbstractLiteralTextToKotlinCopyPasteTest.kt b/idea/tests/org/jetbrains/kotlin/idea/conversion/copy/AbstractLiteralTextToKotlinCopyPasteTest.kt similarity index 70% rename from idea/tests/org/jetbrains/kotlin/idea/editor/AbstractLiteralTextToKotlinCopyPasteTest.kt rename to idea/tests/org/jetbrains/kotlin/idea/conversion/copy/AbstractLiteralTextToKotlinCopyPasteTest.kt index e25b8b7d9be..e3163e6bd12 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/editor/AbstractLiteralTextToKotlinCopyPasteTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/conversion/copy/AbstractLiteralTextToKotlinCopyPasteTest.kt @@ -9,21 +9,18 @@ import com.intellij.openapi.actionSystem.IdeActions import org.jetbrains.kotlin.idea.AbstractCopyPasteTest import org.jetbrains.kotlin.idea.caches.resolve.forceResolveInWriteActionCheckInTests 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 AbstractLiteralTextToKotlinCopyPasteTest : AbstractCopyPasteTest() { - private val _basePath = PluginTestCaseBase.getTestDataPathBase() + "/copyPaste/plainTextLiteral" - - override fun getTestDataPath() = _basePath override fun getProjectDescriptor() = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE - fun doTest(path: String) { - myFixture.testDataPath = _basePath - val testName = getTestName(false) - myFixture.configureByFiles("$testName.txt") + fun doTest(unused: String) { + val fileName = fileName() + val targetFileName = fileName.replace(".txt", ".kt") + + myFixture.configureByFile(fileName) val fileText = myFixture.editor.document.text if (!myFixture.editor.selectionModel.hasSelection()) @@ -33,12 +30,13 @@ abstract class AbstractLiteralTextToKotlinCopyPasteTest : AbstractCopyPasteTest( myFixture.performEditorAction(IdeActions.ACTION_COPY) } - configureTargetFile("$testName.kt") + configureTargetFile(targetFileName) forceResolveInWriteActionCheckInTests { myFixture.performEditorAction(IdeActions.ACTION_PASTE) } - KotlinTestUtils.assertEqualsToFile(File(path.replace(".txt", ".expected.kt")), myFixture.file.text) + val expectedFile = File(testPath().replace(".txt", ".expected.kt")) + KotlinTestUtils.assertEqualsToFile(expectedFile, myFixture.file.text) } } diff --git a/idea/tests/org/jetbrains/kotlin/idea/conversion/copy/AbstractTextJavaToKotlinCopyPasteConversionTest.kt b/idea/tests/org/jetbrains/kotlin/idea/conversion/copy/AbstractTextJavaToKotlinCopyPasteConversionTest.kt index c5f09524e31..ff23100d914 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/conversion/copy/AbstractTextJavaToKotlinCopyPasteConversionTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/conversion/copy/AbstractTextJavaToKotlinCopyPasteConversionTest.kt @@ -6,21 +6,15 @@ package org.jetbrains.kotlin.idea.conversion.copy import com.intellij.openapi.actionSystem.IdeActions -import org.jetbrains.kotlin.idea.AbstractCopyPasteTest import org.jetbrains.kotlin.idea.editor.KotlinEditorOptions import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor -import org.jetbrains.kotlin.idea.test.PluginTestCaseBase import org.jetbrains.kotlin.test.InTextDirectivesUtils import org.jetbrains.kotlin.test.KotlinTestUtils import java.io.File abstract class AbstractTextJavaToKotlinCopyPasteConversionTest : AbstractJ2kCopyPasteTest() { - protected open val BASE_PATH = PluginTestCaseBase.getTestDataPathBase() + "/copyPaste/plainTextConversion" - private var oldEditorOptions: KotlinEditorOptions? = null - override fun getTestDataPath() = BASE_PATH - override fun getProjectDescriptor() = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE override fun setUp() { @@ -35,10 +29,9 @@ abstract class AbstractTextJavaToKotlinCopyPasteConversionTest : AbstractJ2kCopy super.tearDown() } - fun doTest(path: String) { - myFixture.testDataPath = BASE_PATH - val testName = getTestName(false) - myFixture.configureByFiles(testName + ".txt") + fun doTest(unused: String) { + val fileName = fileName() + myFixture.configureByFile(fileName) val fileText = myFixture.editor.document.text val noConversionExpected = InTextDirectivesUtils.findListWithPrefixes(fileText, "// NO_CONVERSION_EXPECTED").isNotEmpty() @@ -46,18 +39,21 @@ abstract class AbstractTextJavaToKotlinCopyPasteConversionTest : AbstractJ2kCopy myFixture.editor.selectionModel.setSelection(0, fileText.length) myFixture.performEditorAction(IdeActions.ACTION_COPY) - configureByDependencyIfExists(testName + ".dependency.kt") - configureByDependencyIfExists(testName + ".dependency.java") + configureByDependencyIfExists(fileName.replace(".txt", ".dependency.kt")) + configureByDependencyIfExists(fileName.replace(".txt", ".dependency.java")) - configureTargetFile(testName + ".to.kt") + configureTargetFile(fileName.replace(".txt", ".to.kt")) ConvertTextJavaCopyPasteProcessor.conversionPerformed = false myFixture.performEditorAction(IdeActions.ACTION_PASTE) - kotlin.test.assertEquals(noConversionExpected, !ConvertTextJavaCopyPasteProcessor.conversionPerformed, - if (noConversionExpected) "Conversion to Kotlin should not be suggested" else "No conversion to Kotlin suggested") + kotlin.test.assertEquals( + noConversionExpected, !ConvertTextJavaCopyPasteProcessor.conversionPerformed, + if (noConversionExpected) "Conversion to Kotlin should not be suggested" else "No conversion to Kotlin suggested" + ) - KotlinTestUtils.assertEqualsToFile(File(path.replace(".txt", ".expected.kt")), myFixture.file.text) + val expectedFile = File(testPath().replace(".txt", ".expected.kt")) + KotlinTestUtils.assertEqualsToFile(expectedFile, myFixture.file.text) } } diff --git a/idea/tests/org/jetbrains/kotlin/idea/editor/AbstractLiteralKotlinToKotlinCopyPasteTest.kt b/idea/tests/org/jetbrains/kotlin/idea/editor/AbstractLiteralKotlinToKotlinCopyPasteTest.kt index 0fa74f73482..681bbb4547a 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/editor/AbstractLiteralKotlinToKotlinCopyPasteTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/editor/AbstractLiteralKotlinToKotlinCopyPasteTest.kt @@ -8,29 +8,25 @@ package org.jetbrains.kotlin.idea.conversion.copy import com.intellij.openapi.actionSystem.IdeActions import org.jetbrains.kotlin.idea.AbstractCopyPasteTest 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 AbstractLiteralKotlinToKotlinCopyPasteTest : AbstractCopyPasteTest() { - private val BASE_PATH = PluginTestCaseBase.getTestDataPathBase() + "/copyPaste/literal" - - - override fun getTestDataPath() = BASE_PATH override fun getProjectDescriptor() = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE + fun doTest(unused: String) { + val fileName = fileName() + val testPath = testPath() + val expectedPath = File(testPath.replace(".kt", ".expected.kt")) - fun doTest(path: String) { - myFixture.testDataPath = BASE_PATH - val testName = getTestName(false) - myFixture.configureByFiles(testName + ".kt") + myFixture.configureByFile(fileName) myFixture.performEditorAction(IdeActions.ACTION_COPY) - configureTargetFile(testName + ".to.kt") + configureTargetFile(fileName.replace(".kt", ".to.kt")) myFixture.performEditorAction(IdeActions.ACTION_PASTE) - KotlinTestUtils.assertEqualsToFile(File(path.replace(".kt", ".expected.kt")), myFixture.file.text) + KotlinTestUtils.assertEqualsToFile(expectedPath, myFixture.file.text) } } diff --git a/idea/tests/org/jetbrains/kotlin/idea/highlighter/AbstractHighlightExitPointsTest.kt b/idea/tests/org/jetbrains/kotlin/idea/highlighter/AbstractHighlightExitPointsTest.kt index 694162c1af7..4bcc2f73316 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/highlighter/AbstractHighlightExitPointsTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/highlighter/AbstractHighlightExitPointsTest.kt @@ -8,12 +8,12 @@ package org.jetbrains.kotlin.idea.highlighter import com.intellij.codeInsight.highlighting.HighlightUsagesHandler import com.intellij.openapi.editor.colors.EditorColors import com.intellij.openapi.editor.colors.EditorColorsManager -import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase +import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase import org.jetbrains.kotlin.test.InTextDirectivesUtils -abstract class AbstractHighlightExitPointsTest : LightCodeInsightFixtureTestCase() { - fun doTest(testDataPath: String) { - myFixture.configureByFile(testDataPath) +abstract class AbstractHighlightExitPointsTest : KotlinLightCodeInsightFixtureTestCase() { + fun doTest(unused: String) { + myFixture.configureByFile(fileName()) HighlightUsagesHandler.invoke(myFixture.project, myFixture.editor, myFixture.file) val text = myFixture.file.text diff --git a/idea/tests/org/jetbrains/kotlin/idea/highlighter/AbstractHighlightingTest.java b/idea/tests/org/jetbrains/kotlin/idea/highlighter/AbstractHighlightingTest.java index 3cf5707aa08..0a53045a0d8 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/highlighter/AbstractHighlightingTest.java +++ b/idea/tests/org/jetbrains/kotlin/idea/highlighter/AbstractHighlightingTest.java @@ -18,14 +18,14 @@ import java.util.List; public abstract class AbstractHighlightingTest extends KotlinLightCodeInsightFixtureTestCase { - protected void doTest(String filePath) throws Exception { - String fileText = FileUtil.loadFile(new File(filePath), true); + protected void doTest(String unused) throws Exception { + String fileText = FileUtil.loadFile(new File(testPath()), true); boolean checkInfos = !InTextDirectivesUtils.isDirectiveDefined(fileText, "// NO_CHECK_INFOS"); boolean checkWeakWarnings = !InTextDirectivesUtils.isDirectiveDefined(fileText, "// NO_CHECK_WEAK_WARNINGS"); boolean checkWarnings = !InTextDirectivesUtils.isDirectiveDefined(fileText, "// NO_CHECK_WARNINGS"); boolean expectedDuplicatedHighlighting = InTextDirectivesUtils.isDirectiveDefined(fileText, "// EXPECTED_DUPLICATED_HIGHLIGHTING"); - myFixture.configureByFile(filePath); + myFixture.configureByFile(fileName()); withExpectedDuplicatedHighlighting(expectedDuplicatedHighlighting, () -> { try { diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/DeprecatedSymbolUsageFixSpecialTest.kt b/idea/tests/org/jetbrains/kotlin/idea/quickfix/DeprecatedSymbolUsageFixSpecialTest.kt index 5ca4de24145..536996b9aaa 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/DeprecatedSymbolUsageFixSpecialTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/DeprecatedSymbolUsageFixSpecialTest.kt @@ -14,20 +14,16 @@ import org.jetbrains.kotlin.idea.util.application.executeWriteCommand import org.jetbrains.kotlin.psi.KtSimpleNameExpression import org.jetbrains.kotlin.psi.psiUtil.parents import org.jetbrains.kotlin.test.JUnit3RunnerWithInners -import org.jetbrains.kotlin.test.KotlinTestUtils import org.jetbrains.kotlin.test.TestMetadata import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance import org.junit.runner.RunWith -@TestMetadata("idea/testData/quickfix.special") +@TestMetadata("idea/testData/quickfix.special/deprecatedSymbolUsage") @TestDataPath("\$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners::class) class DeprecatedSymbolUsageFixSpecialTest : KotlinLightCodeInsightFixtureTestCase() { - override fun getTestDataPath() = KotlinTestUtils.getHomeDirectory() override fun getProjectDescriptor() = ProjectDescriptorWithStdlibSources.INSTANCE - private val TEST_DATA_DIR = "idea/testData/quickfix.special/deprecatedSymbolUsage" - fun testMemberInCompiledClass() { doTest("matches(input)") } @@ -37,7 +33,7 @@ class DeprecatedSymbolUsageFixSpecialTest : KotlinLightCodeInsightFixtureTestCas } private fun doTest(pattern: String) { - val testPath = KotlinTestUtils.navigationMetadata(TEST_DATA_DIR + "/" + getTestName(true) + ".kt") + val testPath = getTestName(true) + ".kt" myFixture.configureByFile(testPath) val offset = editor.caretModel.offset diff --git a/idea/tests/org/jetbrains/kotlin/idea/resolve/AbstractPartialBodyResolveTest.kt b/idea/tests/org/jetbrains/kotlin/idea/resolve/AbstractPartialBodyResolveTest.kt index 3adf9f4683d..d8ebdc73d4d 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/resolve/AbstractPartialBodyResolveTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/resolve/AbstractPartialBodyResolveTest.kt @@ -30,21 +30,20 @@ import java.io.File import java.util.* abstract class AbstractPartialBodyResolveTest : KotlinLightCodeInsightFixtureTestCase() { - override fun getTestDataPath() = KotlinTestUtils.getHomeDirectory() override fun getProjectDescriptor() = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE - fun doTest(testPath: String) { + fun doTest(unused: String) { + val testPath = testPath() val dumpNormal = dump(testPath, BodyResolveMode.PARTIAL) val testPathNoExt = FileUtil.getNameWithoutExtension(testPath) - KotlinTestUtils.assertEqualsToFile(File(testPathNoExt + ".dump"), dumpNormal) + KotlinTestUtils.assertEqualsToFile(File("$testPathNoExt.dump"), dumpNormal) val dumpForCompletion = dump(testPath, BodyResolveMode.PARTIAL_FOR_COMPLETION) - val completionDump = File(testPathNoExt + ".completion") + val completionDump = File("$testPathNoExt.completion") if (dumpForCompletion != dumpNormal) { KotlinTestUtils.assertEqualsToFile(completionDump, dumpForCompletion) - } - else { + } else { Assert.assertFalse(completionDump.exists()) } } @@ -64,11 +63,11 @@ abstract class AbstractPartialBodyResolveTest : KotlinLightCodeInsightFixtureTes selectionModel.selectionEnd, KtExpression::class.java ) - ?: error("No JetExpression at selection range") + ?: error("No KtExpression at selection range") } else { val offset = editor.caretModel.offset val element = file.findElementAt(offset)!! - element.getNonStrictParentOfType() ?: error("No JetSimpleNameExpression at caret") + element.getNonStrictParentOfType() ?: error("No KtSimpleNameExpression at caret") } val resolutionFacade = file.getResolutionFacade() diff --git a/idea/tests/org/jetbrains/kotlin/idea/scratch/AbstractScratchRunActionTest.kt b/idea/tests/org/jetbrains/kotlin/idea/scratch/AbstractScratchRunActionTest.kt index a9c96bcf785..1b1ec12870b 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/scratch/AbstractScratchRunActionTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/scratch/AbstractScratchRunActionTest.kt @@ -86,8 +86,9 @@ abstract class AbstractScratchRunActionTest : FileEditorManagerTestCase() { } } - javaFiles.forEach { myFixture.copyFileToProject(it.path, FileUtil.getRelativePath(baseDir, it)!!) } - kotlinFiles.forEach { myFixture.copyFileToProject(it.path, FileUtil.getRelativePath(baseDir, it)!!) } + val testDataPathFile = File(myFixture.testDataPath) + javaFiles.forEach { myFixture.copyFileToProject(FileUtil.getRelativePath(testDataPathFile, it)!!, FileUtil.getRelativePath(baseDir, it)!!) } + kotlinFiles.forEach { myFixture.copyFileToProject(FileUtil.getRelativePath(testDataPathFile, it)!!, FileUtil.getRelativePath(baseDir, it)!!) } val outputDir = createTempDir(dirName) diff --git a/nj2k/tests/org/jetbrains/kotlin/nj2k/AbstractTextJavaToKotlinCopyPasteConversionTest.kt b/nj2k/tests/org/jetbrains/kotlin/nj2k/AbstractTextJavaToKotlinCopyPasteConversionTest.kt index 6beef7a4929..273b01f977e 100644 --- a/nj2k/tests/org/jetbrains/kotlin/nj2k/AbstractTextJavaToKotlinCopyPasteConversionTest.kt +++ b/nj2k/tests/org/jetbrains/kotlin/nj2k/AbstractTextJavaToKotlinCopyPasteConversionTest.kt @@ -6,10 +6,7 @@ package org.jetbrains.kotlin.nj2k import org.jetbrains.kotlin.idea.conversion.copy.AbstractTextJavaToKotlinCopyPasteConversionTest -import org.jetbrains.kotlin.test.KotlinTestUtils abstract class AbstractTextNewJavaToKotlinCopyPasteConversionTest : AbstractTextJavaToKotlinCopyPasteConversionTest() { - override val BASE_PATH = KotlinTestUtils.getHomeDirectory() + "/nj2k/testData/copyPastePlainText" - override fun isNewJ2K(): Boolean = true } \ No newline at end of file