Refactoring: always use compiler settings with de-configuration in tests
This commit is contained in:
committed by
Nikolay Krasko
parent
018215f47d
commit
3a5f42cc5e
+14
-18
@@ -11,8 +11,7 @@ import com.intellij.openapi.util.io.FileUtil
|
|||||||
import org.jetbrains.kotlin.idea.caches.project.LibraryModificationTracker
|
import org.jetbrains.kotlin.idea.caches.project.LibraryModificationTracker
|
||||||
import org.jetbrains.kotlin.idea.test.CompilerTestDirectives
|
import org.jetbrains.kotlin.idea.test.CompilerTestDirectives
|
||||||
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
||||||
import org.jetbrains.kotlin.idea.test.configureCompilerOptions
|
import org.jetbrains.kotlin.idea.test.withCustomCompilerOptions
|
||||||
import org.jetbrains.kotlin.idea.test.rollbackCompilerOptions
|
|
||||||
import org.jetbrains.kotlin.platform.TargetPlatform
|
import org.jetbrains.kotlin.platform.TargetPlatform
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
@@ -30,27 +29,24 @@ abstract class KotlinFixtureCompletionBaseTestCase : KotlinLightCodeInsightFixtu
|
|||||||
setUpFixture(testPath)
|
setUpFixture(testPath)
|
||||||
|
|
||||||
val fileText = FileUtil.loadFile(File(testPath), true)
|
val fileText = FileUtil.loadFile(File(testPath), true)
|
||||||
val configured = configureCompilerOptions(fileText, project, module)
|
|
||||||
try {
|
try {
|
||||||
|
withCustomCompilerOptions(fileText, project, module) {
|
||||||
|
assertTrue("\"<caret>\" is missing in file \"$testPath\"", fileText.contains("<caret>"))
|
||||||
|
|
||||||
assertTrue("\"<caret>\" is missing in file \"$testPath\"", fileText.contains("<caret>"))
|
if (ExpectedCompletionUtils.shouldRunHighlightingBeforeCompletion(fileText)) {
|
||||||
|
myFixture.doHighlighting()
|
||||||
|
}
|
||||||
|
|
||||||
if (ExpectedCompletionUtils.shouldRunHighlightingBeforeCompletion(fileText)) {
|
testCompletion(
|
||||||
myFixture.doHighlighting()
|
fileText,
|
||||||
|
getPlatform(),
|
||||||
|
{ completionType, count -> complete(completionType, count) },
|
||||||
|
defaultCompletionType(),
|
||||||
|
defaultInvocationCount(),
|
||||||
|
additionalValidDirectives = CompilerTestDirectives.ALL_COMPILER_TEST_DIRECTIVES
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
testCompletion(
|
|
||||||
fileText,
|
|
||||||
getPlatform(),
|
|
||||||
{ completionType, count -> complete(completionType, count) },
|
|
||||||
defaultCompletionType(),
|
|
||||||
defaultInvocationCount(),
|
|
||||||
additionalValidDirectives = CompilerTestDirectives.ALL_COMPILER_TEST_DIRECTIVES
|
|
||||||
)
|
|
||||||
} finally {
|
} finally {
|
||||||
if (configured) {
|
|
||||||
rollbackCompilerOptions(project, module)
|
|
||||||
}
|
|
||||||
tearDownFixture()
|
tearDownFixture()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+36
-40
@@ -12,8 +12,7 @@ import org.jetbrains.kotlin.idea.completion.test.ExpectedCompletionUtils
|
|||||||
import org.jetbrains.kotlin.idea.completion.test.configureWithExtraFile
|
import org.jetbrains.kotlin.idea.completion.test.configureWithExtraFile
|
||||||
import org.jetbrains.kotlin.idea.core.formatter.KotlinCodeStyleSettings
|
import org.jetbrains.kotlin.idea.core.formatter.KotlinCodeStyleSettings
|
||||||
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
|
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
|
||||||
import org.jetbrains.kotlin.idea.test.configureCompilerOptions
|
import org.jetbrains.kotlin.idea.test.withCustomCompilerOptions
|
||||||
import org.jetbrains.kotlin.idea.test.rollbackCompilerOptions
|
|
||||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.indexOfOrNull
|
import org.jetbrains.kotlin.utils.addToStdlib.indexOfOrNull
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@@ -36,51 +35,48 @@ abstract class AbstractCompletionHandlerTest(private val defaultCompletionType:
|
|||||||
val tempSettings = CodeStyle.getSettings(project).clone()
|
val tempSettings = CodeStyle.getSettings(project).clone()
|
||||||
CodeStyle.setTemporarySettings(project, tempSettings)
|
CodeStyle.setTemporarySettings(project, tempSettings)
|
||||||
val fileText = FileUtil.loadFile(File(testPath))
|
val fileText = FileUtil.loadFile(File(testPath))
|
||||||
val configured = configureCompilerOptions(fileText, project, module)
|
|
||||||
try {
|
try {
|
||||||
assertTrue("\"<caret>\" is missing in file \"$testPath\"", fileText.contains("<caret>"))
|
withCustomCompilerOptions(fileText, project, module) {
|
||||||
|
assertTrue("\"<caret>\" is missing in file \"$testPath\"", fileText.contains("<caret>"))
|
||||||
|
|
||||||
|
val invocationCount = InTextDirectivesUtils.getPrefixedInt(fileText, INVOCATION_COUNT_PREFIX) ?: 1
|
||||||
|
val lookupString = InTextDirectivesUtils.findStringWithPrefixes(fileText, LOOKUP_STRING_PREFIX)
|
||||||
|
val itemText = InTextDirectivesUtils.findStringWithPrefixes(fileText, ELEMENT_TEXT_PREFIX)
|
||||||
|
val tailText = InTextDirectivesUtils.findStringWithPrefixes(fileText, TAIL_TEXT_PREFIX)
|
||||||
|
val completionChars = completionChars(fileText)
|
||||||
|
|
||||||
val invocationCount = InTextDirectivesUtils.getPrefixedInt(fileText, INVOCATION_COUNT_PREFIX) ?: 1
|
val completionType = ExpectedCompletionUtils.getCompletionType(fileText) ?: defaultCompletionType
|
||||||
val lookupString = InTextDirectivesUtils.findStringWithPrefixes(fileText, LOOKUP_STRING_PREFIX)
|
|
||||||
val itemText = InTextDirectivesUtils.findStringWithPrefixes(fileText, ELEMENT_TEXT_PREFIX)
|
|
||||||
val tailText = InTextDirectivesUtils.findStringWithPrefixes(fileText, TAIL_TEXT_PREFIX)
|
|
||||||
val completionChars = completionChars(fileText)
|
|
||||||
|
|
||||||
val completionType = ExpectedCompletionUtils.getCompletionType(fileText) ?: defaultCompletionType
|
val kotlinStyleSettings = KotlinCodeStyleSettings.getInstance(project)
|
||||||
|
val commonStyleSettings = CodeStyle.getLanguageSettings(file)
|
||||||
val kotlinStyleSettings = KotlinCodeStyleSettings.getInstance(project)
|
for (line in InTextDirectivesUtils.findLinesWithPrefixesRemoved(fileText, CODE_STYLE_SETTING_PREFIX)) {
|
||||||
val commonStyleSettings = CodeStyle.getLanguageSettings(file)
|
val index = line.indexOfOrNull('=') ?: error("Invalid code style setting '$line': '=' expected")
|
||||||
for (line in InTextDirectivesUtils.findLinesWithPrefixesRemoved(fileText, CODE_STYLE_SETTING_PREFIX)) {
|
val settingName = line.substring(0, index).trim()
|
||||||
val index = line.indexOfOrNull('=') ?: error("Invalid code style setting '$line': '=' expected")
|
val settingValue = line.substring(index + 1).trim()
|
||||||
val settingName = line.substring(0, index).trim()
|
val (field, settings) = try {
|
||||||
val settingValue = line.substring(index + 1).trim()
|
kotlinStyleSettings::class.java.getField(settingName) to kotlinStyleSettings
|
||||||
val (field, settings) = try {
|
} catch (e: NoSuchFieldException) {
|
||||||
kotlinStyleSettings::class.java.getField(settingName) to kotlinStyleSettings
|
commonStyleSettings::class.java.getField(settingName) to commonStyleSettings
|
||||||
} catch (e: NoSuchFieldException) {
|
}
|
||||||
commonStyleSettings::class.java.getField(settingName) to commonStyleSettings
|
when (field.type.name) {
|
||||||
}
|
"boolean" -> field.setBoolean(settings, settingValue.toBoolean())
|
||||||
when (field.type.name) {
|
"int" -> field.setInt(settings, settingValue.toInt())
|
||||||
"boolean" -> field.setBoolean(settings, settingValue.toBoolean())
|
else -> error("Unsupported setting type: ${field.type}")
|
||||||
"int" -> field.setInt(settings, settingValue.toInt())
|
}
|
||||||
else -> error("Unsupported setting type: ${field.type}")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
doTestWithTextLoaded(
|
||||||
|
myFixture,
|
||||||
|
completionType,
|
||||||
|
invocationCount,
|
||||||
|
lookupString,
|
||||||
|
itemText,
|
||||||
|
tailText,
|
||||||
|
completionChars,
|
||||||
|
File(testPath).name + ".after",
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
doTestWithTextLoaded(
|
|
||||||
myFixture,
|
|
||||||
completionType,
|
|
||||||
invocationCount,
|
|
||||||
lookupString,
|
|
||||||
itemText,
|
|
||||||
tailText,
|
|
||||||
completionChars,
|
|
||||||
File(testPath).name + ".after"
|
|
||||||
)
|
|
||||||
} finally {
|
} finally {
|
||||||
if (configured) {
|
|
||||||
rollbackCompilerOptions(project, module)
|
|
||||||
}
|
|
||||||
CodeStyle.dropTemporarySettings(project)
|
CodeStyle.dropTemporarySettings(project)
|
||||||
tearDownFixture()
|
tearDownFixture()
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-9
@@ -10,8 +10,7 @@ import org.jetbrains.kotlin.idea.completion.test.RELATIVE_COMPLETION_TEST_DATA_B
|
|||||||
import org.jetbrains.kotlin.idea.completion.test.configureWithExtraFile
|
import org.jetbrains.kotlin.idea.completion.test.configureWithExtraFile
|
||||||
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
||||||
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
|
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
|
||||||
import org.jetbrains.kotlin.idea.test.configureCompilerOptions
|
import org.jetbrains.kotlin.idea.test.withCustomCompilerOptions
|
||||||
import org.jetbrains.kotlin.idea.test.rollbackCompilerOptions
|
|
||||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||||
import org.junit.Assert
|
import org.junit.Assert
|
||||||
|
|
||||||
@@ -26,18 +25,12 @@ abstract class AbstractCompletionWeigherTest(val completionType: CompletionType,
|
|||||||
|
|
||||||
val text = myFixture.editor.document.text
|
val text = myFixture.editor.document.text
|
||||||
|
|
||||||
val configured = configureCompilerOptions(text, project, module)
|
|
||||||
|
|
||||||
val items = InTextDirectivesUtils.findArrayWithPrefixes(text, "// ORDER:")
|
val items = InTextDirectivesUtils.findArrayWithPrefixes(text, "// ORDER:")
|
||||||
Assert.assertTrue("""Some items should be defined with "// ORDER:" directive""", items.isNotEmpty())
|
Assert.assertTrue("""Some items should be defined with "// ORDER:" directive""", items.isNotEmpty())
|
||||||
|
|
||||||
try {
|
withCustomCompilerOptions(text, project, module) {
|
||||||
myFixture.complete(completionType, InTextDirectivesUtils.getPrefixedInt(text, "// INVOCATION_COUNT:") ?: 1)
|
myFixture.complete(completionType, InTextDirectivesUtils.getPrefixedInt(text, "// INVOCATION_COUNT:") ?: 1)
|
||||||
myFixture.assertPreferredCompletionItems(InTextDirectivesUtils.getPrefixedInt(text, "// SELECTED:") ?: 0, *items)
|
myFixture.assertPreferredCompletionItems(InTextDirectivesUtils.getPrefixedInt(text, "// SELECTED:") ?: 0, *items)
|
||||||
} finally {
|
|
||||||
if (configured) {
|
|
||||||
rollbackCompilerOptions(project, module)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-2
@@ -228,7 +228,6 @@ abstract class KotlinLightCodeInsightFixtureTestCase : KotlinLightCodeInsightFix
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
object CompilerTestDirectives {
|
object CompilerTestDirectives {
|
||||||
const val LANGUAGE_VERSION_DIRECTIVE = "LANGUAGE_VERSION:"
|
const val LANGUAGE_VERSION_DIRECTIVE = "LANGUAGE_VERSION:"
|
||||||
const val JVM_TARGET_DIRECTIVE = "JVM_TARGET:"
|
const val JVM_TARGET_DIRECTIVE = "JVM_TARGET:"
|
||||||
@@ -237,6 +236,17 @@ object CompilerTestDirectives {
|
|||||||
val ALL_COMPILER_TEST_DIRECTIVES = listOf(LANGUAGE_VERSION_DIRECTIVE, JVM_TARGET_DIRECTIVE, COMPILER_ARGUMENTS_DIRECTIVE)
|
val ALL_COMPILER_TEST_DIRECTIVES = listOf(LANGUAGE_VERSION_DIRECTIVE, JVM_TARGET_DIRECTIVE, COMPILER_ARGUMENTS_DIRECTIVE)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun <T> withCustomCompilerOptions(fileText: String, project: Project, module: Module, body: () -> T): T {
|
||||||
|
val configured = configureCompilerOptions(fileText, project, module)
|
||||||
|
try {
|
||||||
|
return body()
|
||||||
|
} finally {
|
||||||
|
if (configured) {
|
||||||
|
rollbackCompilerOptions(project, module)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun configureCompilerOptions(fileText: String, project: Project, module: Module): Boolean {
|
fun configureCompilerOptions(fileText: String, project: Project, module: Module): Boolean {
|
||||||
val version = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// $LANGUAGE_VERSION_DIRECTIVE ")
|
val version = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// $LANGUAGE_VERSION_DIRECTIVE ")
|
||||||
val jvmTarget = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// $JVM_TARGET_DIRECTIVE ")
|
val jvmTarget = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// $JVM_TARGET_DIRECTIVE ")
|
||||||
@@ -286,7 +296,7 @@ fun <T> configureRegistryAndRun(fileText: String, body: () -> T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun rollbackCompilerOptions(project: Project, module: Module) {
|
private fun rollbackCompilerOptions(project: Project, module: Module) {
|
||||||
configureLanguageAndApiVersion(project, module, LanguageVersion.LATEST_STABLE.versionString)
|
configureLanguageAndApiVersion(project, module, LanguageVersion.LATEST_STABLE.versionString)
|
||||||
|
|
||||||
val facetSettings = KotlinFacet.get(module)!!.configuration.settings
|
val facetSettings = KotlinFacet.get(module)!!.configuration.settings
|
||||||
|
|||||||
+31
-34
@@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.perf
|
package org.jetbrains.kotlin.idea.perf
|
||||||
|
|
||||||
import org.jetbrains.kotlin.idea.completion.test.handlers.CompletionHandlerTestBase
|
|
||||||
import com.intellij.application.options.CodeStyle
|
import com.intellij.application.options.CodeStyle
|
||||||
import com.intellij.codeInsight.completion.CompletionType
|
import com.intellij.codeInsight.completion.CompletionType
|
||||||
import com.intellij.openapi.application.runWriteAction
|
import com.intellij.openapi.application.runWriteAction
|
||||||
@@ -17,10 +16,10 @@ import org.jetbrains.kotlin.idea.completion.test.handlers.AbstractCompletionHand
|
|||||||
import org.jetbrains.kotlin.idea.completion.test.handlers.AbstractCompletionHandlerTest.Companion.INVOCATION_COUNT_PREFIX
|
import org.jetbrains.kotlin.idea.completion.test.handlers.AbstractCompletionHandlerTest.Companion.INVOCATION_COUNT_PREFIX
|
||||||
import org.jetbrains.kotlin.idea.completion.test.handlers.AbstractCompletionHandlerTest.Companion.LOOKUP_STRING_PREFIX
|
import org.jetbrains.kotlin.idea.completion.test.handlers.AbstractCompletionHandlerTest.Companion.LOOKUP_STRING_PREFIX
|
||||||
import org.jetbrains.kotlin.idea.completion.test.handlers.AbstractCompletionHandlerTest.Companion.TAIL_TEXT_PREFIX
|
import org.jetbrains.kotlin.idea.completion.test.handlers.AbstractCompletionHandlerTest.Companion.TAIL_TEXT_PREFIX
|
||||||
|
import org.jetbrains.kotlin.idea.completion.test.handlers.CompletionHandlerTestBase
|
||||||
import org.jetbrains.kotlin.idea.core.formatter.KotlinCodeStyleSettings
|
import org.jetbrains.kotlin.idea.core.formatter.KotlinCodeStyleSettings
|
||||||
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
|
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
|
||||||
import org.jetbrains.kotlin.idea.test.configureCompilerOptions
|
import org.jetbrains.kotlin.idea.test.withCustomCompilerOptions
|
||||||
import org.jetbrains.kotlin.idea.test.rollbackCompilerOptions
|
|
||||||
import org.jetbrains.kotlin.idea.testFramework.commitAllDocuments
|
import org.jetbrains.kotlin.idea.testFramework.commitAllDocuments
|
||||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.indexOfOrNull
|
import org.jetbrains.kotlin.utils.addToStdlib.indexOfOrNull
|
||||||
@@ -62,44 +61,42 @@ abstract class AbstractPerformanceCompletionHandlerTests(
|
|||||||
|
|
||||||
val tempSettings = CodeStyle.getSettings(project).clone()
|
val tempSettings = CodeStyle.getSettings(project).clone()
|
||||||
CodeStyle.setTemporarySettings(project, tempSettings)
|
CodeStyle.setTemporarySettings(project, tempSettings)
|
||||||
val fileText = FileUtil.loadFile(File(testPath))
|
|
||||||
val configured = configureCompilerOptions(fileText, project, module)
|
|
||||||
try {
|
try {
|
||||||
assertTrue("\"<caret>\" is missing in file \"$testPath\"", fileText.contains("<caret>"))
|
val fileText = FileUtil.loadFile(File(testPath))
|
||||||
|
withCustomCompilerOptions(fileText, project, module) {
|
||||||
|
assertTrue("\"<caret>\" is missing in file \"$testPath\"", fileText.contains("<caret>"))
|
||||||
|
|
||||||
val invocationCount = InTextDirectivesUtils.getPrefixedInt(fileText, INVOCATION_COUNT_PREFIX) ?: 1
|
val invocationCount = InTextDirectivesUtils.getPrefixedInt(fileText, INVOCATION_COUNT_PREFIX) ?: 1
|
||||||
val lookupString = InTextDirectivesUtils.findStringWithPrefixes(fileText, LOOKUP_STRING_PREFIX)
|
val lookupString = InTextDirectivesUtils.findStringWithPrefixes(fileText, LOOKUP_STRING_PREFIX)
|
||||||
val itemText = InTextDirectivesUtils.findStringWithPrefixes(fileText, ELEMENT_TEXT_PREFIX)
|
val itemText = InTextDirectivesUtils.findStringWithPrefixes(fileText, ELEMENT_TEXT_PREFIX)
|
||||||
val tailText = InTextDirectivesUtils.findStringWithPrefixes(fileText, TAIL_TEXT_PREFIX)
|
val tailText = InTextDirectivesUtils.findStringWithPrefixes(fileText, TAIL_TEXT_PREFIX)
|
||||||
val completionChars = completionChars(fileText)
|
val completionChars = completionChars(fileText)
|
||||||
|
|
||||||
val completionType = ExpectedCompletionUtils.getCompletionType(fileText) ?: defaultCompletionType
|
val completionType = ExpectedCompletionUtils.getCompletionType(fileText) ?: defaultCompletionType
|
||||||
|
|
||||||
val kotlinStyleSettings = KotlinCodeStyleSettings.getInstance(project)
|
val kotlinStyleSettings = KotlinCodeStyleSettings.getInstance(project)
|
||||||
val commonStyleSettings = CodeStyle.getLanguageSettings(file)
|
val commonStyleSettings = CodeStyle.getLanguageSettings(file)
|
||||||
for (line in InTextDirectivesUtils.findLinesWithPrefixesRemoved(fileText, CODE_STYLE_SETTING_PREFIX)) {
|
for (line in InTextDirectivesUtils.findLinesWithPrefixesRemoved(fileText, CODE_STYLE_SETTING_PREFIX)) {
|
||||||
val index = line.indexOfOrNull('=') ?: error("Invalid code style setting '$line': '=' expected")
|
val index = line.indexOfOrNull('=') ?: error("Invalid code style setting '$line': '=' expected")
|
||||||
val settingName = line.substring(0, index).trim()
|
val settingName = line.substring(0, index).trim()
|
||||||
val settingValue = line.substring(index + 1).trim()
|
val settingValue = line.substring(index + 1).trim()
|
||||||
val (field, settings) = try {
|
val (field, settings) = try {
|
||||||
kotlinStyleSettings::class.java.getField(settingName) to kotlinStyleSettings
|
kotlinStyleSettings::class.java.getField(settingName) to kotlinStyleSettings
|
||||||
} catch (e: NoSuchFieldException) {
|
} catch (e: NoSuchFieldException) {
|
||||||
commonStyleSettings::class.java.getField(settingName) to commonStyleSettings
|
commonStyleSettings::class.java.getField(settingName) to commonStyleSettings
|
||||||
}
|
}
|
||||||
when (field.type.name) {
|
when (field.type.name) {
|
||||||
"boolean" -> field.setBoolean(settings, settingValue.toBoolean())
|
"boolean" -> field.setBoolean(settings, settingValue.toBoolean())
|
||||||
"int" -> field.setInt(settings, settingValue.toInt())
|
"int" -> field.setInt(settings, settingValue.toInt())
|
||||||
else -> error("Unsupported setting type: ${field.type}")
|
else -> error("Unsupported setting type: ${field.type}")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
doPerfTestWithTextLoaded(
|
||||||
|
testPath, completionType, invocationCount, lookupString, itemText, tailText, completionChars,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
doPerfTestWithTextLoaded(
|
|
||||||
testPath, completionType, invocationCount, lookupString, itemText, tailText, completionChars
|
|
||||||
)
|
|
||||||
} finally {
|
} finally {
|
||||||
if (configured) {
|
|
||||||
rollbackCompilerOptions(project, module)
|
|
||||||
}
|
|
||||||
CodeStyle.dropTemporarySettings(project)
|
CodeStyle.dropTemporarySettings(project)
|
||||||
tearDownFixture()
|
tearDownFixture()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,7 @@ package org.jetbrains.kotlin.checkers
|
|||||||
|
|
||||||
import com.intellij.rt.execution.junit.FileComparisonFailure
|
import com.intellij.rt.execution.junit.FileComparisonFailure
|
||||||
import org.jetbrains.kotlin.idea.fir.FirResolution
|
import org.jetbrains.kotlin.idea.fir.FirResolution
|
||||||
import org.jetbrains.kotlin.idea.test.configureCompilerOptions
|
import org.jetbrains.kotlin.idea.test.withCustomCompilerOptions
|
||||||
import org.jetbrains.kotlin.idea.test.rollbackCompilerOptions
|
|
||||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
@@ -29,21 +28,18 @@ abstract class AbstractFirPsiCheckerTest : AbstractPsiCheckerTest() {
|
|||||||
checkWeakWarnings: Boolean
|
checkWeakWarnings: Boolean
|
||||||
): Long {
|
): Long {
|
||||||
val file = file
|
val file = file
|
||||||
val configured = configureCompilerOptions(file.text, project, module)
|
return withCustomCompilerOptions(file.text, project, module) {
|
||||||
val doComparison = InTextDirectivesUtils.isDirectiveDefined(myFixture.file.text, "FIR_COMPARISON")
|
val doComparison = InTextDirectivesUtils.isDirectiveDefined(myFixture.file.text, "FIR_COMPARISON")
|
||||||
return try {
|
try {
|
||||||
myFixture.checkHighlighting(checkWarnings, checkInfos, checkWeakWarnings)
|
myFixture.checkHighlighting(checkWarnings, checkInfos, checkWeakWarnings)
|
||||||
} catch (e: FileComparisonFailure) {
|
} catch (e: FileComparisonFailure) {
|
||||||
if (doComparison) {
|
if (doComparison) {
|
||||||
// Even this is very partial check (only error compatibility, no warnings / infos)
|
// Even this is very partial check (only error compatibility, no warnings / infos)
|
||||||
throw FileComparisonFailure(e.message, e.expected, e.actual, File(e.filePath).absolutePath)
|
throw FileComparisonFailure(e.message, e.expected, e.actual, File(e.filePath).absolutePath)
|
||||||
} else {
|
} else {
|
||||||
// Here we just check that we haven't crashed due to exception
|
// Here we just check that we haven't crashed due to exception
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
if (configured) {
|
|
||||||
rollbackCompilerOptions(project, module)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,20 +62,19 @@ public abstract class AbstractPsiCheckerTest extends KotlinLightCodeInsightFixtu
|
|||||||
|
|
||||||
protected long checkHighlighting(boolean checkWarnings, boolean checkInfos, boolean checkWeakWarnings) {
|
protected long checkHighlighting(boolean checkWarnings, boolean checkInfos, boolean checkWeakWarnings) {
|
||||||
PsiFile file = getFile();
|
PsiFile file = getFile();
|
||||||
boolean configured = KotlinLightCodeInsightFixtureTestCaseKt.configureCompilerOptions(file.getText(), getProject(), getModule());
|
return KotlinLightCodeInsightFixtureTestCaseKt
|
||||||
try {
|
.withCustomCompilerOptions(file.getText(), getProject(), getModule(), () -> {
|
||||||
if (file instanceof KtFile && ((KtFile) file).isScript() && myFixture instanceof JavaCodeInsightTestFixtureImpl) {
|
try {
|
||||||
((JavaCodeInsightTestFixtureImpl) myFixture).canChangeDocumentDuringHighlighting(true);
|
if (file instanceof KtFile && ((KtFile) file).isScript() && myFixture instanceof JavaCodeInsightTestFixtureImpl) {
|
||||||
}
|
((JavaCodeInsightTestFixtureImpl) myFixture).canChangeDocumentDuringHighlighting(true);
|
||||||
return myFixture.checkHighlighting(checkWarnings, checkInfos, checkWeakWarnings);
|
}
|
||||||
}
|
return myFixture.checkHighlighting(checkWarnings, checkInfos, checkWeakWarnings);
|
||||||
catch (FileComparisonFailure e) {
|
}
|
||||||
throw new FileComparisonFailure(e.getMessage(), e.getExpected(), e.getActual(), new File(e.getFilePath()).getAbsolutePath());
|
catch (FileComparisonFailure e) {
|
||||||
} finally {
|
throw new FileComparisonFailure(e.getMessage(), e.getExpected(), e.getActual(),
|
||||||
if (configured) {
|
new File(e.getFilePath()).getAbsolutePath());
|
||||||
KotlinLightCodeInsightFixtureTestCaseKt.rollbackCompilerOptions(getProject(), getModule());
|
}
|
||||||
}
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkResolveToDescriptor() {
|
void checkResolveToDescriptor() {
|
||||||
|
|||||||
@@ -18,7 +18,10 @@ import org.jdom.input.SAXBuilder
|
|||||||
import org.jetbrains.kotlin.formatter.FormatSettingsUtil
|
import org.jetbrains.kotlin.formatter.FormatSettingsUtil
|
||||||
import org.jetbrains.kotlin.idea.core.script.isScriptChangesNotifierDisabled
|
import org.jetbrains.kotlin.idea.core.script.isScriptChangesNotifierDisabled
|
||||||
import org.jetbrains.kotlin.idea.inspections.runInspection
|
import org.jetbrains.kotlin.idea.inspections.runInspection
|
||||||
import org.jetbrains.kotlin.idea.test.*
|
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
||||||
|
import org.jetbrains.kotlin.idea.test.TestFixtureExtension
|
||||||
|
import org.jetbrains.kotlin.idea.test.configureRegistryAndRun
|
||||||
|
import org.jetbrains.kotlin.idea.test.withCustomCompilerOptions
|
||||||
import org.jetbrains.kotlin.idea.util.application.runWriteAction
|
import org.jetbrains.kotlin.idea.util.application.runWriteAction
|
||||||
import org.jetbrains.kotlin.idea.versions.bundledRuntimeVersion
|
import org.jetbrains.kotlin.idea.versions.bundledRuntimeVersion
|
||||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||||
@@ -63,95 +66,93 @@ abstract class AbstractInspectionTest : KotlinLightCodeInsightFixtureTestCase()
|
|||||||
|
|
||||||
val fixtureClasses = InTextDirectivesUtils.findListWithPrefixes(options, "// FIXTURE_CLASS: ")
|
val fixtureClasses = InTextDirectivesUtils.findListWithPrefixes(options, "// FIXTURE_CLASS: ")
|
||||||
|
|
||||||
val configured = configureCompilerOptions(options, project, module)
|
withCustomCompilerOptions(options, project, module) {
|
||||||
|
val inspectionsTestDir = optionsFile.parentFile!!
|
||||||
|
val srcDir = inspectionsTestDir.parentFile!!
|
||||||
|
|
||||||
val inspectionsTestDir = optionsFile.parentFile!!
|
val settingsFile = File(inspectionsTestDir, "settings.xml")
|
||||||
val srcDir = inspectionsTestDir.parentFile!!
|
val settingsElement = if (settingsFile.exists()) {
|
||||||
|
(SAXBuilder().build(settingsFile) as Document).rootElement
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
val settingsFile = File(inspectionsTestDir, "settings.xml")
|
with(myFixture) {
|
||||||
val settingsElement = if (settingsFile.exists()) {
|
testDataPath = "${KotlinTestUtils.getHomeDirectory()}/$srcDir"
|
||||||
(SAXBuilder().build(settingsFile) as Document).rootElement
|
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
|
|
||||||
with(myFixture) {
|
val afterFiles =
|
||||||
testDataPath = "${KotlinTestUtils.getHomeDirectory()}/$srcDir"
|
srcDir.listFiles { it -> it.name == "inspectionData" }?.single()?.listFiles { it -> it.extension == "after" }
|
||||||
|
?: emptyArray()
|
||||||
val afterFiles = srcDir.listFiles { it -> it.name == "inspectionData" }?.single()?.listFiles { it -> it.extension == "after" }
|
val psiFiles = srcDir.walkTopDown().onEnter { it.name != "inspectionData" }.mapNotNull { file ->
|
||||||
?: emptyArray()
|
when {
|
||||||
val psiFiles = srcDir.walkTopDown().onEnter { it.name != "inspectionData" }.mapNotNull { file ->
|
file.isDirectory -> null
|
||||||
when {
|
file.extension == "kt" -> {
|
||||||
file.isDirectory -> null
|
val text = FileUtil.loadFile(file, true)
|
||||||
file.extension == "kt" -> {
|
val fileText =
|
||||||
val text = FileUtil.loadFile(file, true)
|
if (text.lines().any { it.startsWith("package") })
|
||||||
val fileText =
|
text
|
||||||
if (text.lines().any { it.startsWith("package") })
|
else
|
||||||
text
|
"package ${file.nameWithoutExtension};$text"
|
||||||
else
|
if (forceUsePackageFolder) {
|
||||||
"package ${file.nameWithoutExtension};$text"
|
val packageName = fileText.substring(
|
||||||
if (forceUsePackageFolder) {
|
"package".length,
|
||||||
val packageName = fileText.substring(
|
fileText.indexOfAny(charArrayOf(';', '\n')),
|
||||||
"package".length,
|
).trim()
|
||||||
fileText.indexOfAny(charArrayOf(';', '\n')),
|
val projectFileName = packageName.replace('.', '/') + "/" + file.name
|
||||||
).trim()
|
addFileToProject(projectFileName, fileText)
|
||||||
val projectFileName = packageName.replace('.', '/') + "/" + file.name
|
} else {
|
||||||
addFileToProject(projectFileName, fileText)
|
configureByText(file.name, fileText)!!
|
||||||
} else {
|
}
|
||||||
|
}
|
||||||
|
file.extension == "gradle" -> {
|
||||||
|
val text = FileUtil.loadFile(file, true)
|
||||||
|
val fileText = text.replace("\$PLUGIN_VERSION", bundledRuntimeVersion())
|
||||||
configureByText(file.name, fileText)!!
|
configureByText(file.name, fileText)!!
|
||||||
}
|
}
|
||||||
|
else -> {
|
||||||
|
val filePath = file.relativeTo(srcDir).invariantSeparatorsPath
|
||||||
|
configureByFile(filePath)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
file.extension == "gradle" -> {
|
}.toList()
|
||||||
val text = FileUtil.loadFile(file, true)
|
|
||||||
val fileText = text.replace("\$PLUGIN_VERSION", bundledRuntimeVersion())
|
|
||||||
configureByText(file.name, fileText)!!
|
|
||||||
}
|
|
||||||
else -> {
|
|
||||||
val filePath = file.relativeTo(srcDir).invariantSeparatorsPath
|
|
||||||
configureByFile(filePath)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}.toList()
|
|
||||||
|
|
||||||
val codeStyleSettings = CodeStyle.getSettings(project)
|
val codeStyleSettings = CodeStyle.getSettings(project)
|
||||||
configureRegistryAndRun(options) {
|
configureRegistryAndRun(options) {
|
||||||
try {
|
try {
|
||||||
FormatSettingsUtil.createConfigurator(options, codeStyleSettings).configureSettings()
|
FormatSettingsUtil.createConfigurator(options, codeStyleSettings).configureSettings()
|
||||||
fixtureClasses.forEach { TestFixtureExtension.loadFixture(it, myFixture.module) }
|
fixtureClasses.forEach { TestFixtureExtension.loadFixture(it, myFixture.module) }
|
||||||
|
|
||||||
configExtra(psiFiles, options)
|
configExtra(psiFiles, options)
|
||||||
|
|
||||||
val presentation = runInspection(
|
val presentation = runInspection(
|
||||||
inspectionClass, project,
|
inspectionClass, project,
|
||||||
settings = settingsElement,
|
settings = settingsElement,
|
||||||
files = psiFiles.map { it.virtualFile!! }, withTestDir = inspectionsTestDir.path,
|
files = psiFiles.map { it.virtualFile!! }, withTestDir = inspectionsTestDir.path,
|
||||||
)
|
)
|
||||||
|
|
||||||
if (afterFiles.isNotEmpty()) {
|
if (afterFiles.isNotEmpty()) {
|
||||||
presentation.problemDescriptors.forEach { problem ->
|
presentation.problemDescriptors.forEach { problem ->
|
||||||
problem.fixes?.forEach {
|
problem.fixes?.forEach {
|
||||||
CommandProcessor.getInstance().executeCommand(
|
CommandProcessor.getInstance().executeCommand(
|
||||||
project,
|
project,
|
||||||
{
|
{
|
||||||
runWriteAction { it.applyFix(project, problem) }
|
runWriteAction { it.applyFix(project, problem) }
|
||||||
},
|
},
|
||||||
it.name, it.familyName,
|
it.name, it.familyName,
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (filePath in afterFiles) {
|
||||||
|
val kotlinFile = psiFiles.first { filePath.name == it.name + ".after" }
|
||||||
|
KotlinTestUtils.assertEqualsToFile(filePath, kotlinFile.text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (filePath in afterFiles) {
|
} finally {
|
||||||
val kotlinFile = psiFiles.first { filePath.name == it.name + ".after" }
|
codeStyleSettings.clearCodeStyleSettings()
|
||||||
KotlinTestUtils.assertEqualsToFile(filePath, kotlinFile.text)
|
fixtureClasses.forEach { TestFixtureExtension.unloadFixture(it) }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} finally {
|
|
||||||
codeStyleSettings.clearCodeStyleSettings()
|
|
||||||
if (configured) {
|
|
||||||
rollbackCompilerOptions(project, module)
|
|
||||||
}
|
|
||||||
fixtureClasses.forEach { TestFixtureExtension.unloadFixture(it) }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,8 +19,7 @@ import junit.framework.ComparisonFailure
|
|||||||
import junit.framework.TestCase
|
import junit.framework.TestCase
|
||||||
import org.jetbrains.kotlin.idea.test.DirectiveBasedActionUtils
|
import org.jetbrains.kotlin.idea.test.DirectiveBasedActionUtils
|
||||||
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
||||||
import org.jetbrains.kotlin.idea.test.configureCompilerOptions
|
import org.jetbrains.kotlin.idea.test.withCustomCompilerOptions
|
||||||
import org.jetbrains.kotlin.idea.test.rollbackCompilerOptions
|
|
||||||
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
|
||||||
@@ -80,11 +79,9 @@ abstract class AbstractLocalInspectionTest : KotlinLightCodeInsightFixtureTestCa
|
|||||||
val fileText = FileUtil.loadFile(mainFile, true)
|
val fileText = FileUtil.loadFile(mainFile, true)
|
||||||
TestCase.assertTrue("\"<caret>\" is missing in file \"$mainFile\"", fileText.contains("<caret>"))
|
TestCase.assertTrue("\"<caret>\" is missing in file \"$mainFile\"", fileText.contains("<caret>"))
|
||||||
|
|
||||||
val configured = configureCompilerOptions(fileText, project, module)
|
withCustomCompilerOptions(fileText, project, module) {
|
||||||
|
|
||||||
try {
|
|
||||||
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@withCustomCompilerOptions
|
||||||
|
|
||||||
if (file is KtFile && !InTextDirectivesUtils.isDirectiveDefined(fileText, "// SKIP_ERRORS_BEFORE")) {
|
if (file is KtFile && !InTextDirectivesUtils.isDirectiveDefined(fileText, "// SKIP_ERRORS_BEFORE")) {
|
||||||
DirectiveBasedActionUtils.checkForUnexpectedErrors(file as KtFile)
|
DirectiveBasedActionUtils.checkForUnexpectedErrors(file as KtFile)
|
||||||
@@ -119,10 +116,6 @@ abstract class AbstractLocalInspectionTest : KotlinLightCodeInsightFixtureTestCa
|
|||||||
if (file is KtFile && !InTextDirectivesUtils.isDirectiveDefined(fileText, "// SKIP_ERRORS_AFTER")) {
|
if (file is KtFile && !InTextDirectivesUtils.isDirectiveDefined(fileText, "// SKIP_ERRORS_AFTER")) {
|
||||||
DirectiveBasedActionUtils.checkForUnexpectedErrors(file as KtFile)
|
DirectiveBasedActionUtils.checkForUnexpectedErrors(file as KtFile)
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
if (configured) {
|
|
||||||
rollbackCompilerOptions(project, module)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,10 @@ import com.intellij.refactoring.util.CommonRefactoringUtil
|
|||||||
import com.intellij.testFramework.PlatformTestUtil
|
import com.intellij.testFramework.PlatformTestUtil
|
||||||
import junit.framework.ComparisonFailure
|
import junit.framework.ComparisonFailure
|
||||||
import junit.framework.TestCase
|
import junit.framework.TestCase
|
||||||
import org.jetbrains.kotlin.idea.test.*
|
import org.jetbrains.kotlin.idea.test.ConfigLibraryUtil
|
||||||
|
import org.jetbrains.kotlin.idea.test.DirectiveBasedActionUtils
|
||||||
|
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
||||||
|
import org.jetbrains.kotlin.idea.test.withCustomCompilerOptions
|
||||||
import org.jetbrains.kotlin.idea.util.application.executeCommand
|
import org.jetbrains.kotlin.idea.util.application.executeCommand
|
||||||
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
|
||||||
@@ -98,29 +101,26 @@ abstract class AbstractIntentionTest : KotlinLightCodeInsightFixtureTestCase() {
|
|||||||
val pathToFiles = mapOf(*(sourceFilePaths zip psiFiles).toTypedArray())
|
val pathToFiles = mapOf(*(sourceFilePaths zip psiFiles).toTypedArray())
|
||||||
|
|
||||||
val fileText = FileUtil.loadFile(mainFile, true)
|
val fileText = FileUtil.loadFile(mainFile, true)
|
||||||
val configured = configureCompilerOptions(fileText, project, module)
|
withCustomCompilerOptions(fileText, project, module) {
|
||||||
|
ConfigLibraryUtil.configureLibrariesByDirective(module, PlatformTestUtil.getCommunityPath(), fileText)
|
||||||
|
|
||||||
ConfigLibraryUtil.configureLibrariesByDirective(module, PlatformTestUtil.getCommunityPath(), fileText)
|
try {
|
||||||
|
TestCase.assertTrue("\"<caret>\" is missing in file \"$mainFile\"", fileText.contains("<caret>"))
|
||||||
|
|
||||||
try {
|
val minJavaVersion = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// MIN_JAVA_VERSION: ")
|
||||||
TestCase.assertTrue("\"<caret>\" is missing in file \"$mainFile\"", fileText.contains("<caret>"))
|
if (minJavaVersion != null && !SystemInfo.isJavaVersionAtLeast(minJavaVersion)) return@withCustomCompilerOptions
|
||||||
|
|
||||||
val minJavaVersion = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// MIN_JAVA_VERSION: ")
|
if (file is KtFile && !InTextDirectivesUtils.isDirectiveDefined(fileText, "// SKIP_ERRORS_BEFORE")) {
|
||||||
if (minJavaVersion != null && !SystemInfo.isJavaVersionAtLeast(minJavaVersion)) return
|
DirectiveBasedActionUtils.checkForUnexpectedErrors(file as KtFile)
|
||||||
|
}
|
||||||
|
|
||||||
if (file is KtFile && !InTextDirectivesUtils.isDirectiveDefined(fileText, "// SKIP_ERRORS_BEFORE")) {
|
doTestFor(mainFile.name, pathToFiles, intentionAction, fileText)
|
||||||
DirectiveBasedActionUtils.checkForUnexpectedErrors(file as KtFile)
|
|
||||||
}
|
|
||||||
|
|
||||||
doTestFor(mainFile.name, pathToFiles, intentionAction, fileText)
|
if (file is KtFile && !InTextDirectivesUtils.isDirectiveDefined(fileText, "// SKIP_ERRORS_AFTER")) {
|
||||||
|
DirectiveBasedActionUtils.checkForUnexpectedErrors(file as KtFile)
|
||||||
if (file is KtFile && !InTextDirectivesUtils.isDirectiveDefined(fileText, "// SKIP_ERRORS_AFTER")) {
|
}
|
||||||
DirectiveBasedActionUtils.checkForUnexpectedErrors(file as KtFile)
|
} finally {
|
||||||
}
|
ConfigLibraryUtil.unconfigureLibrariesByDirective(module, fileText)
|
||||||
} finally {
|
|
||||||
ConfigLibraryUtil.unconfigureLibrariesByDirective(module, fileText)
|
|
||||||
if (configured) {
|
|
||||||
rollbackCompilerOptions(project, module)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,10 @@ import com.intellij.testFramework.LightProjectDescriptor
|
|||||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
|
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
|
||||||
import com.intellij.util.PathUtil
|
import com.intellij.util.PathUtil
|
||||||
import org.jetbrains.kotlin.idea.KotlinLanguage
|
import org.jetbrains.kotlin.idea.KotlinLanguage
|
||||||
import org.jetbrains.kotlin.idea.test.*
|
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
|
||||||
|
import org.jetbrains.kotlin.idea.test.ProjectDescriptorWithStdlibSources
|
||||||
|
import org.jetbrains.kotlin.idea.test.SdkAndMockLibraryProjectDescriptor
|
||||||
|
import org.jetbrains.kotlin.idea.test.withCustomCompilerOptions
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
import org.jetbrains.kotlin.psi.KtFile
|
import org.jetbrains.kotlin.psi.KtFile
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.allChildren
|
import org.jetbrains.kotlin.psi.psiUtil.allChildren
|
||||||
@@ -50,9 +53,7 @@ abstract class AbstractParameterInfoTest : LightCodeInsightFixtureTestCase() {
|
|||||||
|
|
||||||
val file = myFixture.file as KtFile
|
val file = myFixture.file as KtFile
|
||||||
|
|
||||||
val configured = configureCompilerOptions(file.text, project, myFixture.module)
|
withCustomCompilerOptions(file.text, project, myFixture.module) {
|
||||||
|
|
||||||
try {
|
|
||||||
val lastChild = file.allChildren.filter { it !is PsiWhiteSpace }.last()
|
val lastChild = file.allChildren.filter { it !is PsiWhiteSpace }.last()
|
||||||
val expectedResultText = when (lastChild.node.elementType) {
|
val expectedResultText = when (lastChild.node.elementType) {
|
||||||
KtTokens.BLOCK_COMMENT -> lastChild.text.substring(2, lastChild.text.length - 2).trim()
|
KtTokens.BLOCK_COMMENT -> lastChild.text.substring(2, lastChild.text.length - 2).trim()
|
||||||
@@ -89,10 +90,6 @@ abstract class AbstractParameterInfoTest : LightCodeInsightFixtureTestCase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Assert.assertEquals(expectedResultText, parameterInfoUIContext.resultText)
|
Assert.assertEquals(expectedResultText, parameterInfoUIContext.resultText)
|
||||||
} finally {
|
|
||||||
if (configured) {
|
|
||||||
rollbackCompilerOptions(project, myFixture.module)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,10 @@ import com.intellij.testFramework.LightProjectDescriptor
|
|||||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
|
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
|
||||||
import com.intellij.util.PathUtil
|
import com.intellij.util.PathUtil
|
||||||
import org.jetbrains.kotlin.idea.KotlinLanguage
|
import org.jetbrains.kotlin.idea.KotlinLanguage
|
||||||
import org.jetbrains.kotlin.idea.test.*
|
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
|
||||||
|
import org.jetbrains.kotlin.idea.test.ProjectDescriptorWithStdlibSources
|
||||||
|
import org.jetbrains.kotlin.idea.test.SdkAndMockLibraryProjectDescriptor
|
||||||
|
import org.jetbrains.kotlin.idea.test.withCustomCompilerOptions
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
import org.jetbrains.kotlin.psi.KtFile
|
import org.jetbrains.kotlin.psi.KtFile
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.allChildren
|
import org.jetbrains.kotlin.psi.psiUtil.allChildren
|
||||||
@@ -50,9 +53,7 @@ abstract class AbstractParameterInfoTest : LightCodeInsightFixtureTestCase() {
|
|||||||
|
|
||||||
val file = myFixture.file as KtFile
|
val file = myFixture.file as KtFile
|
||||||
|
|
||||||
val configured = configureCompilerOptions(file.text, project, myFixture.module)
|
withCustomCompilerOptions(file.text, project, myFixture.module) {
|
||||||
|
|
||||||
try {
|
|
||||||
val lastChild = file.allChildren.filter { it !is PsiWhiteSpace }.last()
|
val lastChild = file.allChildren.filter { it !is PsiWhiteSpace }.last()
|
||||||
val expectedResultText = when (lastChild.node.elementType) {
|
val expectedResultText = when (lastChild.node.elementType) {
|
||||||
KtTokens.BLOCK_COMMENT -> lastChild.text.substring(2, lastChild.text.length - 2).trim()
|
KtTokens.BLOCK_COMMENT -> lastChild.text.substring(2, lastChild.text.length - 2).trim()
|
||||||
@@ -64,7 +65,7 @@ abstract class AbstractParameterInfoTest : LightCodeInsightFixtureTestCase() {
|
|||||||
|
|
||||||
val handlers = ShowParameterInfoHandler.getHandlers(project, KotlinLanguage.INSTANCE)!!
|
val handlers = ShowParameterInfoHandler.getHandlers(project, KotlinLanguage.INSTANCE)!!
|
||||||
val handler = handlers.firstOrNull { it.findElementForParameterInfo(context) != null }
|
val handler = handlers.firstOrNull { it.findElementForParameterInfo(context) != null }
|
||||||
?: error("Could not find parameter info handler")
|
?: error("Could not find parameter info handler")
|
||||||
|
|
||||||
val mockCreateParameterInfoContext = MockCreateParameterInfoContext(file, myFixture)
|
val mockCreateParameterInfoContext = MockCreateParameterInfoContext(file, myFixture)
|
||||||
val parameterOwner = handler.findElementForParameterInfo(mockCreateParameterInfoContext) as PsiElement
|
val parameterOwner = handler.findElementForParameterInfo(mockCreateParameterInfoContext) as PsiElement
|
||||||
@@ -89,10 +90,6 @@ abstract class AbstractParameterInfoTest : LightCodeInsightFixtureTestCase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Assert.assertEquals(expectedResultText, parameterInfoUIContext.resultText)
|
Assert.assertEquals(expectedResultText, parameterInfoUIContext.resultText)
|
||||||
} finally {
|
|
||||||
if (configured) {
|
|
||||||
rollbackCompilerOptions(project, myFixture.module)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,8 +31,7 @@ import org.jetbrains.kotlin.idea.KotlinFileType
|
|||||||
import org.jetbrains.kotlin.idea.quickfix.utils.findInspectionFile
|
import org.jetbrains.kotlin.idea.quickfix.utils.findInspectionFile
|
||||||
import org.jetbrains.kotlin.idea.test.DirectiveBasedActionUtils
|
import org.jetbrains.kotlin.idea.test.DirectiveBasedActionUtils
|
||||||
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
||||||
import org.jetbrains.kotlin.idea.test.configureCompilerOptions
|
import org.jetbrains.kotlin.idea.test.withCustomCompilerOptions
|
||||||
import org.jetbrains.kotlin.idea.test.rollbackCompilerOptions
|
|
||||||
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 org.jetbrains.kotlin.test.TestFiles
|
import org.jetbrains.kotlin.test.TestFiles
|
||||||
@@ -133,58 +132,67 @@ abstract class AbstractQuickFixMultiFileTest : KotlinLightCodeInsightFixtureTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
configureMultiFileTest(subFiles, beforeFile)
|
configureMultiFileTest(subFiles, beforeFile)
|
||||||
val configured = configureCompilerOptions(multiFileText, project, module)
|
withCustomCompilerOptions(multiFileText, project, module) {
|
||||||
|
CommandProcessor.getInstance().executeCommand(
|
||||||
|
project,
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
val psiFile = file
|
||||||
|
|
||||||
CommandProcessor.getInstance().executeCommand(project, {
|
val actionHint = ActionHint.parse(psiFile, beforeFile.content)
|
||||||
try {
|
val text = actionHint.expectedText
|
||||||
val psiFile = file
|
|
||||||
|
|
||||||
val actionHint = ActionHint.parse(psiFile, beforeFile.content)
|
val actionShouldBeAvailable = actionHint.shouldPresent()
|
||||||
val text = actionHint.expectedText
|
|
||||||
|
|
||||||
val actionShouldBeAvailable = actionHint.shouldPresent()
|
if (psiFile is KtFile) {
|
||||||
|
DirectiveBasedActionUtils.checkForUnexpectedErrors(psiFile)
|
||||||
if (psiFile is KtFile) {
|
|
||||||
DirectiveBasedActionUtils.checkForUnexpectedErrors(psiFile)
|
|
||||||
}
|
|
||||||
|
|
||||||
doAction(text, file, editor, actionShouldBeAvailable, getTestName(false), this::availableActions, myFixture::doHighlighting)
|
|
||||||
|
|
||||||
val actualText = file.text
|
|
||||||
val afterText = StringBuilder(actualText).insert(editor.caretModel.offset, "<caret>").toString()
|
|
||||||
|
|
||||||
if (actionShouldBeAvailable) {
|
|
||||||
TestCase.assertNotNull(".after file should exist", afterFile)
|
|
||||||
if (afterText != afterFile!!.content) {
|
|
||||||
val actualTestFile = StringBuilder()
|
|
||||||
if (multiFileText.startsWith("// LANGUAGE_VERSION")) {
|
|
||||||
actualTestFile.append(multiFileText.lineSequence().first())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
actualTestFile.append("// FILE: ").append(beforeFile.path).append("\n").append(beforeFile.content)
|
doAction(
|
||||||
for (file in subFiles) {
|
text,
|
||||||
actualTestFile.append("// FILE: ").append(file.path).append("\n").append(file.content)
|
file,
|
||||||
}
|
editor,
|
||||||
actualTestFile.append("// FILE: ").append(afterFile.path).append("\n").append(afterText)
|
actionShouldBeAvailable,
|
||||||
|
getTestName(false),
|
||||||
|
this::availableActions,
|
||||||
|
myFixture::doHighlighting,
|
||||||
|
)
|
||||||
|
|
||||||
KotlinTestUtils.assertEqualsToFile(File(beforeFileName), actualTestFile.toString())
|
val actualText = file.text
|
||||||
|
val afterText = StringBuilder(actualText).insert(editor.caretModel.offset, "<caret>").toString()
|
||||||
|
|
||||||
|
if (actionShouldBeAvailable) {
|
||||||
|
TestCase.assertNotNull(".after file should exist", afterFile)
|
||||||
|
if (afterText != afterFile!!.content) {
|
||||||
|
val actualTestFile = StringBuilder()
|
||||||
|
if (multiFileText.startsWith("// LANGUAGE_VERSION")) {
|
||||||
|
actualTestFile.append(multiFileText.lineSequence().first())
|
||||||
|
}
|
||||||
|
|
||||||
|
actualTestFile.append("// FILE: ").append(beforeFile.path).append("\n").append(beforeFile.content)
|
||||||
|
for (file in subFiles) {
|
||||||
|
actualTestFile.append("// FILE: ").append(file.path).append("\n").append(file.content)
|
||||||
|
}
|
||||||
|
actualTestFile.append("// FILE: ").append(afterFile.path).append("\n").append(afterText)
|
||||||
|
|
||||||
|
KotlinTestUtils.assertEqualsToFile(File(beforeFileName), actualTestFile.toString())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
TestCase.assertNull(".after file should not exist", afterFile)
|
||||||
|
}
|
||||||
|
} catch (e: ComparisonFailure) {
|
||||||
|
throw e
|
||||||
|
} catch (e: AssertionError) {
|
||||||
|
throw e
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
e.printStackTrace()
|
||||||
|
TestCase.fail(getTestName(true))
|
||||||
}
|
}
|
||||||
} else {
|
},
|
||||||
TestCase.assertNull(".after file should not exist", afterFile)
|
"", "",
|
||||||
}
|
)
|
||||||
} catch (e: ComparisonFailure) {
|
}
|
||||||
throw e
|
|
||||||
} catch (e: AssertionError) {
|
|
||||||
throw e
|
|
||||||
} catch (e: Throwable) {
|
|
||||||
e.printStackTrace()
|
|
||||||
TestCase.fail(getTestName(true))
|
|
||||||
} finally {
|
|
||||||
if (configured) {
|
|
||||||
rollbackCompilerOptions(project, myFixture.module)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, "", "")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun doTest(beforeFileName: String) {
|
private fun doTest(beforeFileName: String) {
|
||||||
@@ -205,57 +213,71 @@ abstract class AbstractQuickFixMultiFileTest : KotlinLightCodeInsightFixtureTest
|
|||||||
|
|
||||||
myFixture.configureByFiles(*testFiles.toTypedArray())
|
myFixture.configureByFiles(*testFiles.toTypedArray())
|
||||||
|
|
||||||
val configured = configureCompilerOptions(originalFileText, project, module)
|
withCustomCompilerOptions(originalFileText, project, module) {
|
||||||
|
CommandProcessor.getInstance().executeCommand(
|
||||||
CommandProcessor.getInstance().executeCommand(project, {
|
project,
|
||||||
try {
|
{
|
||||||
val psiFile = file
|
|
||||||
|
|
||||||
val actionHint = ActionHint.parse(psiFile, originalFileText)
|
|
||||||
val text = actionHint.expectedText
|
|
||||||
|
|
||||||
val actionShouldBeAvailable = actionHint.shouldPresent()
|
|
||||||
|
|
||||||
if (psiFile is KtFile) {
|
|
||||||
DirectiveBasedActionUtils.checkForUnexpectedErrors(psiFile)
|
|
||||||
}
|
|
||||||
|
|
||||||
doAction(text, file, editor, actionShouldBeAvailable, beforeFileName, this::availableActions, myFixture::doHighlighting)
|
|
||||||
|
|
||||||
if (actionShouldBeAvailable) {
|
|
||||||
val afterFilePath = beforeFileName.replace(".before.Main.", ".after.")
|
|
||||||
try {
|
try {
|
||||||
myFixture.checkResultByFile(mainFile.name.replace(".before.Main.", ".after."))
|
val psiFile = file
|
||||||
} catch (e: ComparisonFailure) {
|
|
||||||
KotlinTestUtils.assertEqualsToFile(File(afterFilePath), editor)
|
|
||||||
}
|
|
||||||
|
|
||||||
for (file in myFixture.file.containingDirectory.files) {
|
val actionHint = ActionHint.parse(psiFile, originalFileText)
|
||||||
val fileName = file.name
|
val text = actionHint.expectedText
|
||||||
if (fileName == myFixture.file.name || !fileName.startsWith(extraFileNamePrefix(myFixture.file.name))) continue
|
|
||||||
|
|
||||||
val extraFileFullPath = beforeFileName.replace(myFixture.file.name, fileName)
|
val actionShouldBeAvailable = actionHint.shouldPresent()
|
||||||
val afterFile = File(extraFileFullPath.replace(".before.", ".after."))
|
|
||||||
if (afterFile.exists()) {
|
if (psiFile is KtFile) {
|
||||||
KotlinTestUtils.assertEqualsToFile(afterFile, file.text)
|
DirectiveBasedActionUtils.checkForUnexpectedErrors(psiFile)
|
||||||
} else {
|
|
||||||
KotlinTestUtils.assertEqualsToFile(File(extraFileFullPath), file.text)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
doAction(
|
||||||
|
text,
|
||||||
|
file,
|
||||||
|
editor,
|
||||||
|
actionShouldBeAvailable,
|
||||||
|
beforeFileName,
|
||||||
|
this::availableActions,
|
||||||
|
myFixture::doHighlighting,
|
||||||
|
)
|
||||||
|
|
||||||
|
if (actionShouldBeAvailable) {
|
||||||
|
val afterFilePath = beforeFileName.replace(".before.Main.", ".after.")
|
||||||
|
try {
|
||||||
|
myFixture.checkResultByFile(mainFile.name.replace(".before.Main.", ".after."))
|
||||||
|
} catch (e: ComparisonFailure) {
|
||||||
|
KotlinTestUtils.assertEqualsToFile(File(afterFilePath), editor)
|
||||||
|
}
|
||||||
|
|
||||||
|
for (file in myFixture.file.containingDirectory.files) {
|
||||||
|
val fileName = file.name
|
||||||
|
if (fileName == myFixture.file.name || !fileName.startsWith(
|
||||||
|
extraFileNamePrefix(
|
||||||
|
myFixture.file
|
||||||
|
.name,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
) continue
|
||||||
|
|
||||||
|
val extraFileFullPath = beforeFileName.replace(myFixture.file.name, fileName)
|
||||||
|
val afterFile = File(extraFileFullPath.replace(".before.", ".after."))
|
||||||
|
if (afterFile.exists()) {
|
||||||
|
KotlinTestUtils.assertEqualsToFile(afterFile, file.text)
|
||||||
|
} else {
|
||||||
|
KotlinTestUtils.assertEqualsToFile(File(extraFileFullPath), file.text)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e: ComparisonFailure) {
|
||||||
|
throw e
|
||||||
|
} catch (e: AssertionError) {
|
||||||
|
throw e
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
e.printStackTrace()
|
||||||
|
TestCase.fail(getTestName(true))
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
} catch (e: ComparisonFailure) {
|
"", "",
|
||||||
throw e
|
)
|
||||||
} catch (e: AssertionError) {
|
}
|
||||||
throw e
|
|
||||||
} catch (e: Throwable) {
|
|
||||||
e.printStackTrace()
|
|
||||||
TestCase.fail(getTestName(true))
|
|
||||||
} finally {
|
|
||||||
if (configured) {
|
|
||||||
rollbackCompilerOptions(project, module)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, "", "")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private val availableActions: List<IntentionAction>
|
private val availableActions: List<IntentionAction>
|
||||||
|
|||||||
@@ -54,19 +54,15 @@ abstract class AbstractQuickFixTest : KotlinLightCodeInsightFixtureTestCase(), Q
|
|||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
protected fun doTest(beforeFileName: String) {
|
protected fun doTest(beforeFileName: String) {
|
||||||
val beforeFileText = FileUtil.loadFile(File(beforeFileName))
|
val beforeFileText = FileUtil.loadFile(File(beforeFileName))
|
||||||
val configured = configureCompilerOptions(beforeFileText, project, module)
|
withCustomCompilerOptions(beforeFileText, project, module) {
|
||||||
|
val inspections = parseInspectionsToEnable(beforeFileName, beforeFileText).toTypedArray()
|
||||||
|
try {
|
||||||
|
myFixture.enableInspections(*inspections)
|
||||||
|
|
||||||
val inspections = parseInspectionsToEnable(beforeFileName, beforeFileText).toTypedArray()
|
doKotlinQuickFixTest(beforeFileName)
|
||||||
|
checkForUnexpectedErrors()
|
||||||
try {
|
} finally {
|
||||||
myFixture.enableInspections(*inspections)
|
myFixture.disableInspections(*inspections)
|
||||||
|
|
||||||
doKotlinQuickFixTest(beforeFileName)
|
|
||||||
checkForUnexpectedErrors()
|
|
||||||
} finally {
|
|
||||||
myFixture.disableInspections(*inspections)
|
|
||||||
if (configured) {
|
|
||||||
rollbackCompilerOptions(project, module)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,8 +18,7 @@ import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture
|
|||||||
import junit.framework.TestCase
|
import junit.framework.TestCase
|
||||||
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
||||||
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
|
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
|
||||||
import org.jetbrains.kotlin.idea.test.configureCompilerOptions
|
import org.jetbrains.kotlin.idea.test.withCustomCompilerOptions
|
||||||
import org.jetbrains.kotlin.idea.test.rollbackCompilerOptions
|
|
||||||
import org.jetbrains.kotlin.idea.util.application.runWriteAction
|
import org.jetbrains.kotlin.idea.util.application.runWriteAction
|
||||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||||
@@ -41,13 +40,11 @@ abstract class AbstractInlineTest : KotlinLightCodeInsightFixtureTestCase() {
|
|||||||
val extraFilesToPsi = extraFiles.associateBy { fixture.configureByFile(it.name) }
|
val extraFilesToPsi = extraFiles.associateBy { fixture.configureByFile(it.name) }
|
||||||
val file = myFixture.configureByFile(fileName())
|
val file = myFixture.configureByFile(fileName())
|
||||||
|
|
||||||
val configured = configureCompilerOptions(file.text, project, module)
|
withCustomCompilerOptions(file.text, project, module) {
|
||||||
|
|
||||||
try {
|
|
||||||
val afterFileExists = afterFile.exists()
|
val afterFileExists = afterFile.exists()
|
||||||
|
|
||||||
val targetElement =
|
val targetElement =
|
||||||
TargetElementUtil.findTargetElement(myFixture.editor, ELEMENT_NAME_ACCEPTED or REFERENCED_ELEMENT_ACCEPTED) ?: return
|
TargetElementUtil.findTargetElement(myFixture.editor, ELEMENT_NAME_ACCEPTED or REFERENCED_ELEMENT_ACCEPTED) ?: return@withCustomCompilerOptions
|
||||||
|
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
val handler = Extensions.getExtensions(InlineActionHandler.EP_NAME).firstOrNull { it.canInlineElement(targetElement) }
|
val handler = Extensions.getExtensions(InlineActionHandler.EP_NAME).firstOrNull { it.canInlineElement(targetElement) }
|
||||||
@@ -74,10 +71,6 @@ abstract class AbstractInlineTest : KotlinLightCodeInsightFixtureTestCase() {
|
|||||||
} else {
|
} else {
|
||||||
TestCase.assertFalse("No refactoring handler available", afterFileExists)
|
TestCase.assertFalse("No refactoring handler available", afterFileExists)
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
if (configured) {
|
|
||||||
rollbackCompilerOptions(project, module)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+13
-15
@@ -336,24 +336,22 @@ abstract class AbstractExtractionTest : KotlinLightCodeInsightFixtureTestCase()
|
|||||||
val extraFilesToPsi = extraFiles.associateBy { fixture.configureByFile(it.name) }
|
val extraFilesToPsi = extraFiles.associateBy { fixture.configureByFile(it.name) }
|
||||||
val fileText = FileUtil.loadFile(File(path), true)
|
val fileText = FileUtil.loadFile(File(path), true)
|
||||||
|
|
||||||
val configured = configureCompilerOptions(fileText, project, module)
|
withCustomCompilerOptions(fileText, project, module) {
|
||||||
ConfigLibraryUtil.configureLibrariesByDirective(module, PlatformTestUtil.getCommunityPath(), fileText)
|
ConfigLibraryUtil.configureLibrariesByDirective(module, PlatformTestUtil.getCommunityPath(), fileText)
|
||||||
|
|
||||||
val addKotlinRuntime = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// WITH_RUNTIME") != null
|
|
||||||
if (addKotlinRuntime) {
|
|
||||||
ConfigLibraryUtil.configureKotlinRuntimeAndSdk(module, PluginTestCaseBase.mockJdk())
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
checkExtract(ExtractTestFiles(path, fixture.configureByFile(mainFileName), extraFilesToPsi), checkAdditionalAfterdata, action)
|
|
||||||
} finally {
|
|
||||||
ConfigLibraryUtil.unconfigureLibrariesByDirective(module, fileText)
|
|
||||||
|
|
||||||
|
val addKotlinRuntime = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// WITH_RUNTIME") != null
|
||||||
if (addKotlinRuntime) {
|
if (addKotlinRuntime) {
|
||||||
ConfigLibraryUtil.unConfigureKotlinRuntimeAndSdk(module, PluginTestCaseBase.mockJdk())
|
ConfigLibraryUtil.configureKotlinRuntimeAndSdk(module, PluginTestCaseBase.mockJdk())
|
||||||
}
|
}
|
||||||
if (configured) {
|
|
||||||
rollbackCompilerOptions(project, module)
|
try {
|
||||||
|
checkExtract(ExtractTestFiles(path, fixture.configureByFile(mainFileName), extraFilesToPsi), checkAdditionalAfterdata, action)
|
||||||
|
} finally {
|
||||||
|
ConfigLibraryUtil.unconfigureLibrariesByDirective(module, fileText)
|
||||||
|
|
||||||
|
if (addKotlinRuntime) {
|
||||||
|
ConfigLibraryUtil.unConfigureKotlinRuntimeAndSdk(module, PluginTestCaseBase.mockJdk())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,11 +11,9 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
|||||||
import org.jetbrains.kotlin.descriptors.VariableDescriptor
|
import org.jetbrains.kotlin.descriptors.VariableDescriptor
|
||||||
import org.jetbrains.kotlin.idea.KotlinFileType
|
import org.jetbrains.kotlin.idea.KotlinFileType
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
||||||
import org.jetbrains.kotlin.idea.util.getDataFlowAwareTypes
|
|
||||||
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
||||||
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
|
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
|
||||||
import org.jetbrains.kotlin.idea.test.configureCompilerOptions
|
import org.jetbrains.kotlin.idea.test.withCustomCompilerOptions
|
||||||
import org.jetbrains.kotlin.idea.test.rollbackCompilerOptions
|
|
||||||
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand
|
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
|
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
|
||||||
@@ -51,9 +49,7 @@ abstract class AbstractPartialBodyResolveTest : KotlinLightCodeInsightFixtureTes
|
|||||||
|
|
||||||
private fun dump(testPath: String, resolveMode: BodyResolveMode): String {
|
private fun dump(testPath: String, resolveMode: BodyResolveMode): String {
|
||||||
myFixture.configureByText(KotlinFileType.INSTANCE, File(testPath).readText())
|
myFixture.configureByText(KotlinFileType.INSTANCE, File(testPath).readText())
|
||||||
val configured = configureCompilerOptions(myFixture.file.text, project, module)
|
return withCustomCompilerOptions(myFixture.file.text, project, module) {
|
||||||
|
|
||||||
try {
|
|
||||||
val file = myFixture.file as KtFile
|
val file = myFixture.file as KtFile
|
||||||
val editor = myFixture.editor
|
val editor = myFixture.editor
|
||||||
val selectionModel = editor.selectionModel
|
val selectionModel = editor.selectionModel
|
||||||
@@ -121,11 +117,7 @@ abstract class AbstractPartialBodyResolveTest : KotlinLightCodeInsightFixtureTes
|
|||||||
Assert.assertEquals(target2.presentation(null), target1.presentation(null))
|
Assert.assertEquals(target2.presentation(null), target1.presentation(null))
|
||||||
Assert.assertEquals(type2.presentation(), type1.presentation())
|
Assert.assertEquals(type2.presentation(), type1.presentation())
|
||||||
|
|
||||||
return builder.toString()
|
builder.toString()
|
||||||
} finally {
|
|
||||||
if (configured) {
|
|
||||||
rollbackCompilerOptions(project, module)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user