Convert IntentionTestGenerated to light fixture test case
This commit is contained in:
+5
-3
@@ -104,9 +104,7 @@ abstract class KotlinLightCodeInsightFixtureTestCase : KotlinLightCodeInsightFix
|
|||||||
protected fun getProjectDescriptorFromFileDirective(): LightProjectDescriptor {
|
protected fun getProjectDescriptorFromFileDirective(): LightProjectDescriptor {
|
||||||
if (!isAllFilesPresentInTest()) {
|
if (!isAllFilesPresentInTest()) {
|
||||||
try {
|
try {
|
||||||
val metadata = this::class.findAnnotation<TestMetadata>()
|
val fileText = FileUtil.loadFile(File(testDataPath, fileName()), true)
|
||||||
val basePath = metadata?.value ?: testDataPath
|
|
||||||
val fileText = FileUtil.loadFile(File(basePath, fileName()), true)
|
|
||||||
|
|
||||||
val withLibraryDirective = InTextDirectivesUtils.findLinesWithPrefixesRemoved(fileText, "WITH_LIBRARY:")
|
val withLibraryDirective = InTextDirectivesUtils.findLinesWithPrefixesRemoved(fileText, "WITH_LIBRARY:")
|
||||||
if (!withLibraryDirective.isEmpty()) {
|
if (!withLibraryDirective.isEmpty()) {
|
||||||
@@ -157,4 +155,8 @@ abstract class KotlinLightCodeInsightFixtureTestCase : KotlinLightCodeInsightFix
|
|||||||
managerEx.fireAfterActionPerformed(action, dataContext, event)
|
managerEx.fireAfterActionPerformed(action, dataContext, event)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getTestDataPath(): String {
|
||||||
|
return this::class.findAnnotation<TestMetadata>()?.value ?: super.getTestDataPath()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
// INTENTION_TEXT: "Add import for 'kotlin.test.assertFailsWith'"
|
// INTENTION_TEXT: "Add import for 'kotlin.test.assertFailsWith'"
|
||||||
// WITH_RUNTIME
|
// RUNTIME_WITH_KOTLIN_TEST
|
||||||
|
|
||||||
fun foo() {
|
fun foo() {
|
||||||
kotlin.test.<caret>assertFailsWith<Exception>("", {})
|
kotlin.test.<caret>assertFailsWith<Exception>("", {})
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import kotlin.test.assertFailsWith
|
import kotlin.test.assertFailsWith
|
||||||
|
|
||||||
// INTENTION_TEXT: "Add import for 'kotlin.test.assertFailsWith'"
|
// INTENTION_TEXT: "Add import for 'kotlin.test.assertFailsWith'"
|
||||||
// WITH_RUNTIME
|
// RUNTIME_WITH_KOTLIN_TEST
|
||||||
|
|
||||||
fun foo() {
|
fun foo() {
|
||||||
<caret>assertFailsWith<Exception>("", {})
|
<caret>assertFailsWith<Exception>("", {})
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ class KtFileLightClassTest : KotlinLightCodeInsightFixtureTestCase() {
|
|||||||
assertEquals(0, facadeFiles.size)
|
assertEquals(0, facadeFiles.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getTestDataPath(): String? {
|
override fun getTestDataPath(): String {
|
||||||
return PluginTestCaseBase.getTestDataPathBase() + "/asJava/fileLightClass/"
|
return PluginTestCaseBase.getTestDataPathBase() + "/asJava/fileLightClass/"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ class LightClassFromTextTest : KotlinLightCodeInsightFixtureTestCase() {
|
|||||||
return classes
|
return classes
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getTestDataPath(): String? {
|
override fun getTestDataPath(): String {
|
||||||
return PluginTestCaseBase.getTestDataPathBase() + "/asJava/fileLightClass/"
|
return PluginTestCaseBase.getTestDataPathBase() + "/asJava/fileLightClass/"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+4
-4
@@ -16,19 +16,19 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.coverage
|
package org.jetbrains.kotlin.idea.coverage
|
||||||
|
|
||||||
|
import com.intellij.openapi.util.io.FileUtil
|
||||||
|
import com.intellij.openapi.vfs.VirtualFile
|
||||||
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
||||||
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
|
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
|
||||||
|
import org.jetbrains.kotlin.idea.util.application.runWriteAction
|
||||||
import org.jetbrains.kotlin.psi.KtFile
|
import org.jetbrains.kotlin.psi.KtFile
|
||||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import com.intellij.openapi.util.io.FileUtil
|
|
||||||
import com.intellij.openapi.vfs.VirtualFile
|
|
||||||
import org.jetbrains.kotlin.idea.util.application.runWriteAction
|
|
||||||
|
|
||||||
abstract class AbstractKotlinCoverageOutputFilesTest(): KotlinLightCodeInsightFixtureTestCase() {
|
abstract class AbstractKotlinCoverageOutputFilesTest(): KotlinLightCodeInsightFixtureTestCase() {
|
||||||
private val TEST_DATA_PATH = PluginTestCaseBase.getTestDataPathBase() + "/coverage/outputFiles"
|
private val TEST_DATA_PATH = PluginTestCaseBase.getTestDataPathBase() + "/coverage/outputFiles"
|
||||||
|
|
||||||
override fun getTestDataPath(): String? = TEST_DATA_PATH
|
override fun getTestDataPath(): String = TEST_DATA_PATH
|
||||||
|
|
||||||
fun doTest(path: String) {
|
fun doTest(path: String) {
|
||||||
val kotlinFile = myFixture.configureByFile(path) as KtFile
|
val kotlinFile = myFixture.configureByFile(path) as KtFile
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ abstract class AbstractSmartStepIntoTest : KotlinLightCodeInsightFixtureTestCase
|
|||||||
return sb.toString()
|
return sb.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getTestDataPath(): String? {
|
override fun getTestDataPath(): String {
|
||||||
return PluginTestCaseBase.getTestDataPathBase() + "/debugger/smartStepInto"
|
return PluginTestCaseBase.getTestDataPathBase() + "/debugger/smartStepInto"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,9 +18,7 @@ package org.jetbrains.kotlin.idea.intentions
|
|||||||
|
|
||||||
import com.google.common.collect.Lists
|
import com.google.common.collect.Lists
|
||||||
import com.intellij.codeInsight.intention.IntentionAction
|
import com.intellij.codeInsight.intention.IntentionAction
|
||||||
import com.intellij.ide.startup.impl.StartupManagerImpl
|
|
||||||
import com.intellij.openapi.application.ApplicationManager
|
import com.intellij.openapi.application.ApplicationManager
|
||||||
import com.intellij.openapi.startup.StartupManager
|
|
||||||
import com.intellij.openapi.util.Computable
|
import com.intellij.openapi.util.Computable
|
||||||
import com.intellij.openapi.util.SystemInfo
|
import com.intellij.openapi.util.SystemInfo
|
||||||
import com.intellij.openapi.util.io.FileUtil
|
import com.intellij.openapi.util.io.FileUtil
|
||||||
@@ -28,16 +26,10 @@ import com.intellij.openapi.util.text.StringUtil
|
|||||||
import com.intellij.psi.PsiFile
|
import com.intellij.psi.PsiFile
|
||||||
import com.intellij.refactoring.BaseRefactoringProcessor
|
import com.intellij.refactoring.BaseRefactoringProcessor
|
||||||
import com.intellij.refactoring.util.CommonRefactoringUtil
|
import com.intellij.refactoring.util.CommonRefactoringUtil
|
||||||
import com.intellij.testFramework.PlatformTestUtil
|
|
||||||
import com.intellij.util.PathUtil
|
|
||||||
import com.intellij.util.containers.ContainerUtil
|
|
||||||
import com.intellij.util.containers.Convertor
|
|
||||||
import junit.framework.ComparisonFailure
|
import junit.framework.ComparisonFailure
|
||||||
import junit.framework.TestCase
|
import junit.framework.TestCase
|
||||||
import org.jetbrains.kotlin.idea.test.ConfigLibraryUtil
|
|
||||||
import org.jetbrains.kotlin.idea.test.DirectiveBasedActionUtils
|
import org.jetbrains.kotlin.idea.test.DirectiveBasedActionUtils
|
||||||
import org.jetbrains.kotlin.idea.test.KotlinCodeInsightTestCase
|
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
||||||
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
|
|
||||||
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand
|
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand
|
||||||
import org.jetbrains.kotlin.psi.KtFile
|
import org.jetbrains.kotlin.psi.KtFile
|
||||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||||
@@ -46,20 +38,14 @@ import org.junit.Assert
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
abstract class AbstractIntentionTest : KotlinCodeInsightTestCase() {
|
abstract class AbstractIntentionTest : KotlinLightCodeInsightFixtureTestCase() {
|
||||||
protected open fun intentionFileName(): String {
|
protected open fun intentionFileName(): String = ".intention"
|
||||||
return ".intention"
|
|
||||||
}
|
|
||||||
|
|
||||||
protected open fun afterFileNameSuffix(): String {
|
protected open fun afterFileNameSuffix(): String = ".after"
|
||||||
return ".after"
|
|
||||||
}
|
|
||||||
|
|
||||||
protected open fun isApplicableDirectiveName(): String = "IS_APPLICABLE"
|
protected open fun isApplicableDirectiveName(): String = "IS_APPLICABLE"
|
||||||
|
|
||||||
protected open fun intentionTextDirectiveName(): String {
|
protected open fun intentionTextDirectiveName(): String = "INTENTION_TEXT"
|
||||||
return "INTENTION_TEXT"
|
|
||||||
}
|
|
||||||
|
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
private fun createIntention(testDataFile: File): IntentionAction {
|
private fun createIntention(testDataFile: File): IntentionAction {
|
||||||
@@ -95,32 +81,21 @@ abstract class AbstractIntentionTest : KotlinCodeInsightTestCase() {
|
|||||||
val sourceFilePaths = ArrayList<String>()
|
val sourceFilePaths = ArrayList<String>()
|
||||||
val parentDir = mainFile.parentFile
|
val parentDir = mainFile.parentFile
|
||||||
var i = 1
|
var i = 1
|
||||||
|
sourceFilePaths.add(mainFile.name)
|
||||||
extraFileLoop@ while (true) {
|
extraFileLoop@ while (true) {
|
||||||
for (extension in EXTENSIONS) {
|
for (extension in EXTENSIONS) {
|
||||||
val extraFile = File(parentDir, mainFileName + "." + i + extension)
|
val extraFile = File(parentDir, mainFileName + "." + i + extension)
|
||||||
if (extraFile.exists()) {
|
if (extraFile.exists()) {
|
||||||
sourceFilePaths.add(extraFile.path)
|
sourceFilePaths.add(extraFile.name)
|
||||||
i++
|
i++
|
||||||
continue@extraFileLoop
|
continue@extraFileLoop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
sourceFilePaths.add(path)
|
|
||||||
|
|
||||||
val pathToFiles = ContainerUtil.newMapFromKeys(
|
val psiFiles = myFixture.configureByFiles(*sourceFilePaths.toTypedArray())
|
||||||
sourceFilePaths.iterator(),
|
val pathToFiles = mapOf(*(sourceFilePaths zip psiFiles).toTypedArray())
|
||||||
Convertor<String, PsiFile> { path ->
|
|
||||||
try {
|
|
||||||
configureByFile(path)
|
|
||||||
}
|
|
||||||
catch (e: Exception) {
|
|
||||||
throw RuntimeException(e)
|
|
||||||
}
|
|
||||||
|
|
||||||
myFile
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
val fileText = FileUtil.loadFile(mainFile, true)
|
val fileText = FileUtil.loadFile(mainFile, true)
|
||||||
|
|
||||||
@@ -129,30 +104,14 @@ abstract class AbstractIntentionTest : KotlinCodeInsightTestCase() {
|
|||||||
val minJavaVersion = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// MIN_JAVA_VERSION: ")
|
val minJavaVersion = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// MIN_JAVA_VERSION: ")
|
||||||
if (minJavaVersion != null && !SystemInfo.isJavaVersionAtLeast(minJavaVersion)) return
|
if (minJavaVersion != null && !SystemInfo.isJavaVersionAtLeast(minJavaVersion)) return
|
||||||
|
|
||||||
val isWithRuntime = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// WITH_RUNTIME") != null
|
if (file is KtFile && !InTextDirectivesUtils.isDirectiveDefined(fileText, "// SKIP_ERRORS_BEFORE")) {
|
||||||
|
DirectiveBasedActionUtils.checkForUnexpectedErrors(file as KtFile)
|
||||||
try {
|
|
||||||
if (isWithRuntime) {
|
|
||||||
ConfigLibraryUtil.configureKotlinRuntimeAndSdk(module, PluginTestCaseBase.mockJdk())
|
|
||||||
}
|
|
||||||
|
|
||||||
ConfigLibraryUtil.configureLibrariesByDirective(module, PlatformTestUtil.getCommunityPath(), fileText)
|
|
||||||
|
|
||||||
if (file is KtFile && !InTextDirectivesUtils.isDirectiveDefined(fileText, "// SKIP_ERRORS_BEFORE")) {
|
|
||||||
DirectiveBasedActionUtils.checkForUnexpectedErrors(file as KtFile)
|
|
||||||
}
|
|
||||||
|
|
||||||
doTestFor(path, pathToFiles, intentionAction, fileText)
|
|
||||||
|
|
||||||
if (file is KtFile && !InTextDirectivesUtils.isDirectiveDefined(fileText, "// SKIP_ERRORS_AFTER")) {
|
|
||||||
DirectiveBasedActionUtils.checkForUnexpectedErrors(file as KtFile)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
finally {
|
|
||||||
ConfigLibraryUtil.unconfigureLibrariesByDirective(myModule, fileText)
|
doTestFor(mainFile.name, pathToFiles, intentionAction, fileText)
|
||||||
if (isWithRuntime) {
|
|
||||||
ConfigLibraryUtil.unConfigureKotlinRuntimeAndSdk(module, testProjectJdk)
|
if (file is KtFile && !InTextDirectivesUtils.isDirectiveDefined(fileText, "// SKIP_ERRORS_AFTER")) {
|
||||||
}
|
DirectiveBasedActionUtils.checkForUnexpectedErrors(file as KtFile)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,19 +149,19 @@ abstract class AbstractIntentionTest : KotlinCodeInsightTestCase() {
|
|||||||
// Don't bother checking if it should have failed.
|
// Don't bother checking if it should have failed.
|
||||||
if (shouldFailString.isEmpty()) {
|
if (shouldFailString.isEmpty()) {
|
||||||
for ((filePath, value) in pathToFiles) {
|
for ((filePath, value) in pathToFiles) {
|
||||||
val canonicalPathToExpectedFile = PathUtil.getCanonicalPath(filePath + afterFileNameSuffix())
|
val canonicalPathToExpectedFile = filePath + afterFileNameSuffix()
|
||||||
if (filePath == mainFilePath) {
|
if (filePath == mainFilePath) {
|
||||||
try {
|
try {
|
||||||
checkResultByFile(canonicalPathToExpectedFile)
|
myFixture.checkResultByFile(canonicalPathToExpectedFile)
|
||||||
}
|
}
|
||||||
catch (e: ComparisonFailure) {
|
catch (e: ComparisonFailure) {
|
||||||
KotlinTestUtils
|
KotlinTestUtils
|
||||||
.assertEqualsToFile(File(canonicalPathToExpectedFile), editor.document.text)
|
.assertEqualsToFile(File(testDataPath, canonicalPathToExpectedFile), editor.document.text)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
KotlinTestUtils.assertEqualsToFile(File(canonicalPathToExpectedFile), value.text)
|
KotlinTestUtils.assertEqualsToFile(File(testDataPath, canonicalPathToExpectedFile), value.text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -215,17 +174,6 @@ abstract class AbstractIntentionTest : KotlinCodeInsightTestCase() {
|
|||||||
catch (e: CommonRefactoringUtil.RefactoringErrorHintException) {
|
catch (e: CommonRefactoringUtil.RefactoringErrorHintException) {
|
||||||
TestCase.assertEquals("Failure message mismatch.", shouldFailString, e.message?.replace('\n', ' '))
|
TestCase.assertEquals("Failure message mismatch.", shouldFailString, e.message?.replace('\n', ' '))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Throws(Exception::class)
|
|
||||||
override fun setUp() {
|
|
||||||
super.setUp()
|
|
||||||
(StartupManager.getInstance(project) as StartupManagerImpl).runPostStartupActivities()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getTestDataPath(): String {
|
|
||||||
return ""
|
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|||||||
Reference in New Issue
Block a user