From 199ce6706b5cff01609b94b206c31d3df76ce157 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Wed, 22 Mar 2017 17:04:19 +0100 Subject: [PATCH] Convert AbstractConcatenatedStringGeneratorTest to light test case Remove explicit library configuration; rely on getProjectDescriptorFromFileDirective() instead. --- .../KotlinLightCodeInsightFixtureTestCase.kt | 14 +++++--- ...AbstractConcatenatedStringGeneratorTest.kt | 32 +++++-------------- 2 files changed, 18 insertions(+), 28 deletions(-) diff --git a/idea/idea-test-framework/src/org/jetbrains/kotlin/idea/test/KotlinLightCodeInsightFixtureTestCase.kt b/idea/idea-test-framework/src/org/jetbrains/kotlin/idea/test/KotlinLightCodeInsightFixtureTestCase.kt index 913149f17ce..64e51248502 100644 --- a/idea/idea-test-framework/src/org/jetbrains/kotlin/idea/test/KotlinLightCodeInsightFixtureTestCase.kt +++ b/idea/idea-test-framework/src/org/jetbrains/kotlin/idea/test/KotlinLightCodeInsightFixtureTestCase.kt @@ -23,29 +23,32 @@ import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.actionSystem.Presentation import com.intellij.openapi.actionSystem.ex.ActionManagerEx import com.intellij.openapi.editor.ex.EditorEx -import com.intellij.openapi.project.Project +import com.intellij.openapi.module.Module import com.intellij.openapi.startup.StartupManager import com.intellij.openapi.util.io.FileUtil import com.intellij.openapi.util.text.StringUtil import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess import com.intellij.testFramework.LightProjectDescriptor import com.intellij.testFramework.LoggedErrorProcessor -import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase import org.apache.log4j.Logger import org.jetbrains.kotlin.idea.actions.internal.KotlinInternalMode import org.jetbrains.kotlin.test.InTextDirectivesUtils import org.jetbrains.kotlin.test.KotlinTestUtils +import org.jetbrains.kotlin.test.TestMetadata import org.jetbrains.kotlin.utils.addIfNotNull import org.jetbrains.kotlin.utils.rethrow import java.io.File import java.io.IOException import java.util.* +import kotlin.reflect.full.findAnnotation abstract class KotlinLightCodeInsightFixtureTestCase : KotlinLightCodeInsightFixtureTestCaseBase() { private var kotlinInternalModeOriginalValue = false private val exceptions = ArrayList() + protected val module: Module get() = myFixture.module + override fun setUp() { super.setUp() (StartupManager.getInstance(project) as StartupManagerImpl).runPostStartupActivities() @@ -101,7 +104,9 @@ abstract class KotlinLightCodeInsightFixtureTestCase : KotlinLightCodeInsightFix protected fun getProjectDescriptorFromFileDirective(): LightProjectDescriptor { if (!isAllFilesPresentInTest()) { try { - val fileText = FileUtil.loadFile(File(testDataPath, fileName()), true) + val metadata = this::class.findAnnotation() + val basePath = metadata?.value ?: testDataPath + val fileText = FileUtil.loadFile(File(basePath, fileName()), true) val withLibraryDirective = InTextDirectivesUtils.findLinesWithPrefixesRemoved(fileText, "WITH_LIBRARY:") if (!withLibraryDirective.isEmpty()) { @@ -110,7 +115,8 @@ abstract class KotlinLightCodeInsightFixtureTestCase : KotlinLightCodeInsightFix else if (InTextDirectivesUtils.isDirectiveDefined(fileText, "RUNTIME_WITH_SOURCES")) { return ProjectDescriptorWithStdlibSources.INSTANCE } - else if (InTextDirectivesUtils.isDirectiveDefined(fileText, "RUNTIME")) { + else if (InTextDirectivesUtils.isDirectiveDefined(fileText, "RUNTIME") || + InTextDirectivesUtils.isDirectiveDefined(fileText, "WITH_RUNTIME")) { return KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE } else if (InTextDirectivesUtils.isDirectiveDefined(fileText, "JS")) { diff --git a/idea/tests/org/jetbrains/kotlin/idea/intentions/AbstractConcatenatedStringGeneratorTest.kt b/idea/tests/org/jetbrains/kotlin/idea/intentions/AbstractConcatenatedStringGeneratorTest.kt index af9bc45df63..30a48d3a20f 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/AbstractConcatenatedStringGeneratorTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/AbstractConcatenatedStringGeneratorTest.kt @@ -19,23 +19,18 @@ package org.jetbrains.kotlin.idea.intentions import com.intellij.openapi.fileEditor.FileDocumentManager import com.intellij.openapi.vfs.LocalFileSystem import com.intellij.psi.PsiDocumentManager -import com.intellij.testFramework.PlatformTestUtil import junit.framework.TestCase import org.jetbrains.kotlin.idea.intentions.copyConcatenatedStringToClipboard.ConcatenatedStringGenerator -import org.jetbrains.kotlin.idea.test.ConfigLibraryUtil -import org.jetbrains.kotlin.idea.test.KotlinCodeInsightTestCase -import org.jetbrains.kotlin.idea.test.PluginTestCaseBase +import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase import org.jetbrains.kotlin.psi.KtBinaryExpression import org.jetbrains.kotlin.psi.KtPsiFactory import org.jetbrains.kotlin.psi.psiUtil.collectDescendantsOfType -import org.jetbrains.kotlin.test.InTextDirectivesUtils import java.io.File /** * Compare xxx.kt.result file with the result of ConcatenatedStringGenerator().create(KtBinaryExpression) where KtBinaryExpression is the last KtBinaryExpression of xxx.kt file */ -abstract class AbstractConcatenatedStringGeneratorTest : KotlinCodeInsightTestCase() { - +abstract class AbstractConcatenatedStringGeneratorTest : KotlinLightCodeInsightFixtureTestCase() { @Throws(Exception::class) protected fun doTest(path: String) { val mainFile = File(path) @@ -47,21 +42,10 @@ abstract class AbstractConcatenatedStringGeneratorTest : KotlinCodeInsightTestCa val document = FileDocumentManager.getInstance().getDocument(vFile) ?: return val psiFile = PsiDocumentManager.getInstance(project).getPsiFile(document) ?: return - val isWithRuntime = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// WITH_RUNTIME") != null - - try { - if (isWithRuntime) ConfigLibraryUtil.configureKotlinRuntimeAndSdk(module, PluginTestCaseBase.mockJdk()) - ConfigLibraryUtil.configureLibrariesByDirective(module, PlatformTestUtil.getCommunityPath(), fileText) - - val ktFile = KtPsiFactory(project).createAnalyzableFile("dummy.kt", fileText, psiFile) - val expression = ktFile.collectDescendantsOfType().lastOrNull() - TestCase.assertNotNull("No binary expression found: $path", expression) - val generatedString = ConcatenatedStringGenerator().create(expression!!) - TestCase.assertEquals("mismatch '$expectedText' - '$generatedString'", expectedText, generatedString) - } - finally { - ConfigLibraryUtil.unconfigureLibrariesByDirective(myModule, fileText) - if (isWithRuntime) ConfigLibraryUtil.unConfigureKotlinRuntimeAndSdk(module, testProjectJdk) - } + val ktFile = KtPsiFactory(project).createAnalyzableFile("dummy.kt", fileText, psiFile) + val expression = ktFile.collectDescendantsOfType().lastOrNull() + TestCase.assertNotNull("No binary expression found: $path", expression) + val generatedString = ConcatenatedStringGenerator().create(expression!!) + TestCase.assertEquals("mismatch '$expectedText' - '$generatedString'", expectedText, generatedString) } -} \ No newline at end of file +}