Convert AbstractConcatenatedStringGeneratorTest to light test case
Remove explicit library configuration; rely on getProjectDescriptorFromFileDirective() instead.
This commit is contained in:
+10
-4
@@ -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<Throwable>()
|
||||
|
||||
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<TestMetadata>()
|
||||
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")) {
|
||||
|
||||
+8
-24
@@ -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<KtBinaryExpression>().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<KtBinaryExpression>().lastOrNull()
|
||||
TestCase.assertNotNull("No binary expression found: $path", expression)
|
||||
val generatedString = ConcatenatedStringGenerator().create(expression!!)
|
||||
TestCase.assertEquals("mismatch '$expectedText' - '$generatedString'", expectedText, generatedString)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user