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.test.CompilerTestDirectives
|
||||
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
||||
import org.jetbrains.kotlin.idea.test.configureCompilerOptions
|
||||
import org.jetbrains.kotlin.idea.test.rollbackCompilerOptions
|
||||
import org.jetbrains.kotlin.idea.test.withCustomCompilerOptions
|
||||
import org.jetbrains.kotlin.platform.TargetPlatform
|
||||
import java.io.File
|
||||
|
||||
@@ -30,27 +29,24 @@ abstract class KotlinFixtureCompletionBaseTestCase : KotlinLightCodeInsightFixtu
|
||||
setUpFixture(testPath)
|
||||
|
||||
val fileText = FileUtil.loadFile(File(testPath), true)
|
||||
val configured = configureCompilerOptions(fileText, project, module)
|
||||
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)) {
|
||||
myFixture.doHighlighting()
|
||||
testCompletion(
|
||||
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 {
|
||||
if (configured) {
|
||||
rollbackCompilerOptions(project, module)
|
||||
}
|
||||
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.core.formatter.KotlinCodeStyleSettings
|
||||
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
|
||||
import org.jetbrains.kotlin.idea.test.configureCompilerOptions
|
||||
import org.jetbrains.kotlin.idea.test.rollbackCompilerOptions
|
||||
import org.jetbrains.kotlin.idea.test.withCustomCompilerOptions
|
||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.indexOfOrNull
|
||||
import java.io.File
|
||||
@@ -36,51 +35,48 @@ abstract class AbstractCompletionHandlerTest(private val defaultCompletionType:
|
||||
val tempSettings = CodeStyle.getSettings(project).clone()
|
||||
CodeStyle.setTemporarySettings(project, tempSettings)
|
||||
val fileText = FileUtil.loadFile(File(testPath))
|
||||
val configured = configureCompilerOptions(fileText, project, module)
|
||||
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 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 completionType = ExpectedCompletionUtils.getCompletionType(fileText) ?: defaultCompletionType
|
||||
|
||||
val kotlinStyleSettings = KotlinCodeStyleSettings.getInstance(project)
|
||||
val commonStyleSettings = CodeStyle.getLanguageSettings(file)
|
||||
for (line in InTextDirectivesUtils.findLinesWithPrefixesRemoved(fileText, CODE_STYLE_SETTING_PREFIX)) {
|
||||
val index = line.indexOfOrNull('=') ?: error("Invalid code style setting '$line': '=' expected")
|
||||
val settingName = line.substring(0, index).trim()
|
||||
val settingValue = line.substring(index + 1).trim()
|
||||
val (field, settings) = try {
|
||||
kotlinStyleSettings::class.java.getField(settingName) to kotlinStyleSettings
|
||||
} catch (e: NoSuchFieldException) {
|
||||
commonStyleSettings::class.java.getField(settingName) to commonStyleSettings
|
||||
}
|
||||
when (field.type.name) {
|
||||
"boolean" -> field.setBoolean(settings, settingValue.toBoolean())
|
||||
"int" -> field.setInt(settings, settingValue.toInt())
|
||||
else -> error("Unsupported setting type: ${field.type}")
|
||||
val kotlinStyleSettings = KotlinCodeStyleSettings.getInstance(project)
|
||||
val commonStyleSettings = CodeStyle.getLanguageSettings(file)
|
||||
for (line in InTextDirectivesUtils.findLinesWithPrefixesRemoved(fileText, CODE_STYLE_SETTING_PREFIX)) {
|
||||
val index = line.indexOfOrNull('=') ?: error("Invalid code style setting '$line': '=' expected")
|
||||
val settingName = line.substring(0, index).trim()
|
||||
val settingValue = line.substring(index + 1).trim()
|
||||
val (field, settings) = try {
|
||||
kotlinStyleSettings::class.java.getField(settingName) to kotlinStyleSettings
|
||||
} catch (e: NoSuchFieldException) {
|
||||
commonStyleSettings::class.java.getField(settingName) to commonStyleSettings
|
||||
}
|
||||
when (field.type.name) {
|
||||
"boolean" -> field.setBoolean(settings, settingValue.toBoolean())
|
||||
"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 {
|
||||
if (configured) {
|
||||
rollbackCompilerOptions(project, module)
|
||||
}
|
||||
CodeStyle.dropTemporarySettings(project)
|
||||
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.test.KotlinLightCodeInsightFixtureTestCase
|
||||
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
|
||||
import org.jetbrains.kotlin.idea.test.configureCompilerOptions
|
||||
import org.jetbrains.kotlin.idea.test.rollbackCompilerOptions
|
||||
import org.jetbrains.kotlin.idea.test.withCustomCompilerOptions
|
||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||
import org.junit.Assert
|
||||
|
||||
@@ -26,18 +25,12 @@ abstract class AbstractCompletionWeigherTest(val completionType: CompletionType,
|
||||
|
||||
val text = myFixture.editor.document.text
|
||||
|
||||
val configured = configureCompilerOptions(text, project, module)
|
||||
|
||||
val items = InTextDirectivesUtils.findArrayWithPrefixes(text, "// ORDER:")
|
||||
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.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 {
|
||||
const val LANGUAGE_VERSION_DIRECTIVE = "LANGUAGE_VERSION:"
|
||||
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)
|
||||
}
|
||||
|
||||
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 {
|
||||
val version = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// $LANGUAGE_VERSION_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)
|
||||
|
||||
val facetSettings = KotlinFacet.get(module)!!.configuration.settings
|
||||
|
||||
+31
-34
@@ -5,7 +5,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.perf
|
||||
|
||||
import org.jetbrains.kotlin.idea.completion.test.handlers.CompletionHandlerTestBase
|
||||
import com.intellij.application.options.CodeStyle
|
||||
import com.intellij.codeInsight.completion.CompletionType
|
||||
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.LOOKUP_STRING_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.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
|
||||
import org.jetbrains.kotlin.idea.test.configureCompilerOptions
|
||||
import org.jetbrains.kotlin.idea.test.rollbackCompilerOptions
|
||||
import org.jetbrains.kotlin.idea.test.withCustomCompilerOptions
|
||||
import org.jetbrains.kotlin.idea.testFramework.commitAllDocuments
|
||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.indexOfOrNull
|
||||
@@ -62,44 +61,42 @@ abstract class AbstractPerformanceCompletionHandlerTests(
|
||||
|
||||
val tempSettings = CodeStyle.getSettings(project).clone()
|
||||
CodeStyle.setTemporarySettings(project, tempSettings)
|
||||
val fileText = FileUtil.loadFile(File(testPath))
|
||||
val configured = configureCompilerOptions(fileText, project, module)
|
||||
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 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 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 completionType = ExpectedCompletionUtils.getCompletionType(fileText) ?: defaultCompletionType
|
||||
|
||||
val kotlinStyleSettings = KotlinCodeStyleSettings.getInstance(project)
|
||||
val commonStyleSettings = CodeStyle.getLanguageSettings(file)
|
||||
for (line in InTextDirectivesUtils.findLinesWithPrefixesRemoved(fileText, CODE_STYLE_SETTING_PREFIX)) {
|
||||
val index = line.indexOfOrNull('=') ?: error("Invalid code style setting '$line': '=' expected")
|
||||
val settingName = line.substring(0, index).trim()
|
||||
val settingValue = line.substring(index + 1).trim()
|
||||
val (field, settings) = try {
|
||||
kotlinStyleSettings::class.java.getField(settingName) to kotlinStyleSettings
|
||||
} catch (e: NoSuchFieldException) {
|
||||
commonStyleSettings::class.java.getField(settingName) to commonStyleSettings
|
||||
}
|
||||
when (field.type.name) {
|
||||
"boolean" -> field.setBoolean(settings, settingValue.toBoolean())
|
||||
"int" -> field.setInt(settings, settingValue.toInt())
|
||||
else -> error("Unsupported setting type: ${field.type}")
|
||||
val kotlinStyleSettings = KotlinCodeStyleSettings.getInstance(project)
|
||||
val commonStyleSettings = CodeStyle.getLanguageSettings(file)
|
||||
for (line in InTextDirectivesUtils.findLinesWithPrefixesRemoved(fileText, CODE_STYLE_SETTING_PREFIX)) {
|
||||
val index = line.indexOfOrNull('=') ?: error("Invalid code style setting '$line': '=' expected")
|
||||
val settingName = line.substring(0, index).trim()
|
||||
val settingValue = line.substring(index + 1).trim()
|
||||
val (field, settings) = try {
|
||||
kotlinStyleSettings::class.java.getField(settingName) to kotlinStyleSettings
|
||||
} catch (e: NoSuchFieldException) {
|
||||
commonStyleSettings::class.java.getField(settingName) to commonStyleSettings
|
||||
}
|
||||
when (field.type.name) {
|
||||
"boolean" -> field.setBoolean(settings, settingValue.toBoolean())
|
||||
"int" -> field.setInt(settings, settingValue.toInt())
|
||||
else -> error("Unsupported setting type: ${field.type}")
|
||||
}
|
||||
}
|
||||
|
||||
doPerfTestWithTextLoaded(
|
||||
testPath, completionType, invocationCount, lookupString, itemText, tailText, completionChars,
|
||||
)
|
||||
}
|
||||
|
||||
doPerfTestWithTextLoaded(
|
||||
testPath, completionType, invocationCount, lookupString, itemText, tailText, completionChars
|
||||
)
|
||||
} finally {
|
||||
if (configured) {
|
||||
rollbackCompilerOptions(project, module)
|
||||
}
|
||||
CodeStyle.dropTemporarySettings(project)
|
||||
tearDownFixture()
|
||||
}
|
||||
|
||||
@@ -7,8 +7,7 @@ package org.jetbrains.kotlin.checkers
|
||||
|
||||
import com.intellij.rt.execution.junit.FileComparisonFailure
|
||||
import org.jetbrains.kotlin.idea.fir.FirResolution
|
||||
import org.jetbrains.kotlin.idea.test.configureCompilerOptions
|
||||
import org.jetbrains.kotlin.idea.test.rollbackCompilerOptions
|
||||
import org.jetbrains.kotlin.idea.test.withCustomCompilerOptions
|
||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||
import java.io.File
|
||||
|
||||
@@ -29,21 +28,18 @@ abstract class AbstractFirPsiCheckerTest : AbstractPsiCheckerTest() {
|
||||
checkWeakWarnings: Boolean
|
||||
): Long {
|
||||
val file = file
|
||||
val configured = configureCompilerOptions(file.text, project, module)
|
||||
val doComparison = InTextDirectivesUtils.isDirectiveDefined(myFixture.file.text, "FIR_COMPARISON")
|
||||
return try {
|
||||
myFixture.checkHighlighting(checkWarnings, checkInfos, checkWeakWarnings)
|
||||
} catch (e: FileComparisonFailure) {
|
||||
if (doComparison) {
|
||||
// Even this is very partial check (only error compatibility, no warnings / infos)
|
||||
throw FileComparisonFailure(e.message, e.expected, e.actual, File(e.filePath).absolutePath)
|
||||
} else {
|
||||
// Here we just check that we haven't crashed due to exception
|
||||
0
|
||||
}
|
||||
} finally {
|
||||
if (configured) {
|
||||
rollbackCompilerOptions(project, module)
|
||||
return withCustomCompilerOptions(file.text, project, module) {
|
||||
val doComparison = InTextDirectivesUtils.isDirectiveDefined(myFixture.file.text, "FIR_COMPARISON")
|
||||
try {
|
||||
myFixture.checkHighlighting(checkWarnings, checkInfos, checkWeakWarnings)
|
||||
} catch (e: FileComparisonFailure) {
|
||||
if (doComparison) {
|
||||
// Even this is very partial check (only error compatibility, no warnings / infos)
|
||||
throw FileComparisonFailure(e.message, e.expected, e.actual, File(e.filePath).absolutePath)
|
||||
} else {
|
||||
// Here we just check that we haven't crashed due to exception
|
||||
0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,20 +62,19 @@ public abstract class AbstractPsiCheckerTest extends KotlinLightCodeInsightFixtu
|
||||
|
||||
protected long checkHighlighting(boolean checkWarnings, boolean checkInfos, boolean checkWeakWarnings) {
|
||||
PsiFile file = getFile();
|
||||
boolean configured = KotlinLightCodeInsightFixtureTestCaseKt.configureCompilerOptions(file.getText(), getProject(), getModule());
|
||||
try {
|
||||
if (file instanceof KtFile && ((KtFile) file).isScript() && myFixture instanceof JavaCodeInsightTestFixtureImpl) {
|
||||
((JavaCodeInsightTestFixtureImpl) myFixture).canChangeDocumentDuringHighlighting(true);
|
||||
}
|
||||
return myFixture.checkHighlighting(checkWarnings, checkInfos, checkWeakWarnings);
|
||||
}
|
||||
catch (FileComparisonFailure e) {
|
||||
throw new FileComparisonFailure(e.getMessage(), e.getExpected(), e.getActual(), new File(e.getFilePath()).getAbsolutePath());
|
||||
} finally {
|
||||
if (configured) {
|
||||
KotlinLightCodeInsightFixtureTestCaseKt.rollbackCompilerOptions(getProject(), getModule());
|
||||
}
|
||||
}
|
||||
return KotlinLightCodeInsightFixtureTestCaseKt
|
||||
.withCustomCompilerOptions(file.getText(), getProject(), getModule(), () -> {
|
||||
try {
|
||||
if (file instanceof KtFile && ((KtFile) file).isScript() && myFixture instanceof JavaCodeInsightTestFixtureImpl) {
|
||||
((JavaCodeInsightTestFixtureImpl) myFixture).canChangeDocumentDuringHighlighting(true);
|
||||
}
|
||||
return myFixture.checkHighlighting(checkWarnings, checkInfos, checkWeakWarnings);
|
||||
}
|
||||
catch (FileComparisonFailure e) {
|
||||
throw new FileComparisonFailure(e.getMessage(), e.getExpected(), e.getActual(),
|
||||
new File(e.getFilePath()).getAbsolutePath());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void checkResolveToDescriptor() {
|
||||
|
||||
@@ -18,7 +18,10 @@ import org.jdom.input.SAXBuilder
|
||||
import org.jetbrains.kotlin.formatter.FormatSettingsUtil
|
||||
import org.jetbrains.kotlin.idea.core.script.isScriptChangesNotifierDisabled
|
||||
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.versions.bundledRuntimeVersion
|
||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||
@@ -63,95 +66,93 @@ abstract class AbstractInspectionTest : KotlinLightCodeInsightFixtureTestCase()
|
||||
|
||||
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 srcDir = inspectionsTestDir.parentFile!!
|
||||
val settingsFile = File(inspectionsTestDir, "settings.xml")
|
||||
val settingsElement = if (settingsFile.exists()) {
|
||||
(SAXBuilder().build(settingsFile) as Document).rootElement
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
val settingsFile = File(inspectionsTestDir, "settings.xml")
|
||||
val settingsElement = if (settingsFile.exists()) {
|
||||
(SAXBuilder().build(settingsFile) as Document).rootElement
|
||||
} else {
|
||||
null
|
||||
}
|
||||
with(myFixture) {
|
||||
testDataPath = "${KotlinTestUtils.getHomeDirectory()}/$srcDir"
|
||||
|
||||
with(myFixture) {
|
||||
testDataPath = "${KotlinTestUtils.getHomeDirectory()}/$srcDir"
|
||||
|
||||
val afterFiles = srcDir.listFiles { it -> it.name == "inspectionData" }?.single()?.listFiles { it -> it.extension == "after" }
|
||||
?: emptyArray()
|
||||
val psiFiles = srcDir.walkTopDown().onEnter { it.name != "inspectionData" }.mapNotNull { file ->
|
||||
when {
|
||||
file.isDirectory -> null
|
||||
file.extension == "kt" -> {
|
||||
val text = FileUtil.loadFile(file, true)
|
||||
val fileText =
|
||||
if (text.lines().any { it.startsWith("package") })
|
||||
text
|
||||
else
|
||||
"package ${file.nameWithoutExtension};$text"
|
||||
if (forceUsePackageFolder) {
|
||||
val packageName = fileText.substring(
|
||||
"package".length,
|
||||
fileText.indexOfAny(charArrayOf(';', '\n')),
|
||||
).trim()
|
||||
val projectFileName = packageName.replace('.', '/') + "/" + file.name
|
||||
addFileToProject(projectFileName, fileText)
|
||||
} else {
|
||||
val afterFiles =
|
||||
srcDir.listFiles { it -> it.name == "inspectionData" }?.single()?.listFiles { it -> it.extension == "after" }
|
||||
?: emptyArray()
|
||||
val psiFiles = srcDir.walkTopDown().onEnter { it.name != "inspectionData" }.mapNotNull { file ->
|
||||
when {
|
||||
file.isDirectory -> null
|
||||
file.extension == "kt" -> {
|
||||
val text = FileUtil.loadFile(file, true)
|
||||
val fileText =
|
||||
if (text.lines().any { it.startsWith("package") })
|
||||
text
|
||||
else
|
||||
"package ${file.nameWithoutExtension};$text"
|
||||
if (forceUsePackageFolder) {
|
||||
val packageName = fileText.substring(
|
||||
"package".length,
|
||||
fileText.indexOfAny(charArrayOf(';', '\n')),
|
||||
).trim()
|
||||
val projectFileName = packageName.replace('.', '/') + "/" + file.name
|
||||
addFileToProject(projectFileName, fileText)
|
||||
} else {
|
||||
configureByText(file.name, fileText)!!
|
||||
}
|
||||
}
|
||||
file.extension == "gradle" -> {
|
||||
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)
|
||||
}
|
||||
}
|
||||
file.extension == "gradle" -> {
|
||||
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()
|
||||
}.toList()
|
||||
|
||||
val codeStyleSettings = CodeStyle.getSettings(project)
|
||||
configureRegistryAndRun(options) {
|
||||
try {
|
||||
FormatSettingsUtil.createConfigurator(options, codeStyleSettings).configureSettings()
|
||||
fixtureClasses.forEach { TestFixtureExtension.loadFixture(it, myFixture.module) }
|
||||
val codeStyleSettings = CodeStyle.getSettings(project)
|
||||
configureRegistryAndRun(options) {
|
||||
try {
|
||||
FormatSettingsUtil.createConfigurator(options, codeStyleSettings).configureSettings()
|
||||
fixtureClasses.forEach { TestFixtureExtension.loadFixture(it, myFixture.module) }
|
||||
|
||||
configExtra(psiFiles, options)
|
||||
configExtra(psiFiles, options)
|
||||
|
||||
val presentation = runInspection(
|
||||
inspectionClass, project,
|
||||
settings = settingsElement,
|
||||
files = psiFiles.map { it.virtualFile!! }, withTestDir = inspectionsTestDir.path,
|
||||
)
|
||||
val presentation = runInspection(
|
||||
inspectionClass, project,
|
||||
settings = settingsElement,
|
||||
files = psiFiles.map { it.virtualFile!! }, withTestDir = inspectionsTestDir.path,
|
||||
)
|
||||
|
||||
if (afterFiles.isNotEmpty()) {
|
||||
presentation.problemDescriptors.forEach { problem ->
|
||||
problem.fixes?.forEach {
|
||||
CommandProcessor.getInstance().executeCommand(
|
||||
project,
|
||||
{
|
||||
runWriteAction { it.applyFix(project, problem) }
|
||||
},
|
||||
it.name, it.familyName,
|
||||
)
|
||||
if (afterFiles.isNotEmpty()) {
|
||||
presentation.problemDescriptors.forEach { problem ->
|
||||
problem.fixes?.forEach {
|
||||
CommandProcessor.getInstance().executeCommand(
|
||||
project,
|
||||
{
|
||||
runWriteAction { it.applyFix(project, problem) }
|
||||
},
|
||||
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) {
|
||||
val kotlinFile = psiFiles.first { filePath.name == it.name + ".after" }
|
||||
KotlinTestUtils.assertEqualsToFile(filePath, kotlinFile.text)
|
||||
}
|
||||
} finally {
|
||||
codeStyleSettings.clearCodeStyleSettings()
|
||||
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 org.jetbrains.kotlin.idea.test.DirectiveBasedActionUtils
|
||||
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
||||
import org.jetbrains.kotlin.idea.test.configureCompilerOptions
|
||||
import org.jetbrains.kotlin.idea.test.rollbackCompilerOptions
|
||||
import org.jetbrains.kotlin.idea.test.withCustomCompilerOptions
|
||||
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||
@@ -80,11 +79,9 @@ abstract class AbstractLocalInspectionTest : KotlinLightCodeInsightFixtureTestCa
|
||||
val fileText = FileUtil.loadFile(mainFile, true)
|
||||
TestCase.assertTrue("\"<caret>\" is missing in file \"$mainFile\"", fileText.contains("<caret>"))
|
||||
|
||||
val configured = configureCompilerOptions(fileText, project, module)
|
||||
|
||||
try {
|
||||
withCustomCompilerOptions(fileText, project, module) {
|
||||
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")) {
|
||||
DirectiveBasedActionUtils.checkForUnexpectedErrors(file as KtFile)
|
||||
@@ -119,10 +116,6 @@ abstract class AbstractLocalInspectionTest : KotlinLightCodeInsightFixtureTestCa
|
||||
if (file is KtFile && !InTextDirectivesUtils.isDirectiveDefined(fileText, "// SKIP_ERRORS_AFTER")) {
|
||||
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 junit.framework.ComparisonFailure
|
||||
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.executeWriteCommand
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
@@ -98,29 +101,26 @@ abstract class AbstractIntentionTest : KotlinLightCodeInsightFixtureTestCase() {
|
||||
val pathToFiles = mapOf(*(sourceFilePaths zip psiFiles).toTypedArray())
|
||||
|
||||
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 {
|
||||
TestCase.assertTrue("\"<caret>\" is missing in file \"$mainFile\"", fileText.contains("<caret>"))
|
||||
val minJavaVersion = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// MIN_JAVA_VERSION: ")
|
||||
if (minJavaVersion != null && !SystemInfo.isJavaVersionAtLeast(minJavaVersion)) return@withCustomCompilerOptions
|
||||
|
||||
val minJavaVersion = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// MIN_JAVA_VERSION: ")
|
||||
if (minJavaVersion != null && !SystemInfo.isJavaVersionAtLeast(minJavaVersion)) return
|
||||
if (file is KtFile && !InTextDirectivesUtils.isDirectiveDefined(fileText, "// SKIP_ERRORS_BEFORE")) {
|
||||
DirectiveBasedActionUtils.checkForUnexpectedErrors(file as KtFile)
|
||||
}
|
||||
|
||||
if (file is KtFile && !InTextDirectivesUtils.isDirectiveDefined(fileText, "// SKIP_ERRORS_BEFORE")) {
|
||||
DirectiveBasedActionUtils.checkForUnexpectedErrors(file as KtFile)
|
||||
}
|
||||
doTestFor(mainFile.name, pathToFiles, intentionAction, fileText)
|
||||
|
||||
doTestFor(mainFile.name, pathToFiles, intentionAction, fileText)
|
||||
|
||||
if (file is KtFile && !InTextDirectivesUtils.isDirectiveDefined(fileText, "// SKIP_ERRORS_AFTER")) {
|
||||
DirectiveBasedActionUtils.checkForUnexpectedErrors(file as KtFile)
|
||||
}
|
||||
} finally {
|
||||
ConfigLibraryUtil.unconfigureLibrariesByDirective(module, fileText)
|
||||
if (configured) {
|
||||
rollbackCompilerOptions(project, module)
|
||||
if (file is KtFile && !InTextDirectivesUtils.isDirectiveDefined(fileText, "// SKIP_ERRORS_AFTER")) {
|
||||
DirectiveBasedActionUtils.checkForUnexpectedErrors(file as KtFile)
|
||||
}
|
||||
} finally {
|
||||
ConfigLibraryUtil.unconfigureLibrariesByDirective(module, fileText)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,10 @@ import com.intellij.testFramework.LightProjectDescriptor
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
|
||||
import com.intellij.util.PathUtil
|
||||
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.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.psiUtil.allChildren
|
||||
@@ -50,9 +53,7 @@ abstract class AbstractParameterInfoTest : LightCodeInsightFixtureTestCase() {
|
||||
|
||||
val file = myFixture.file as KtFile
|
||||
|
||||
val configured = configureCompilerOptions(file.text, project, myFixture.module)
|
||||
|
||||
try {
|
||||
withCustomCompilerOptions(file.text, project, myFixture.module) {
|
||||
val lastChild = file.allChildren.filter { it !is PsiWhiteSpace }.last()
|
||||
val expectedResultText = when (lastChild.node.elementType) {
|
||||
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)
|
||||
} 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.util.PathUtil
|
||||
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.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.psiUtil.allChildren
|
||||
@@ -50,9 +53,7 @@ abstract class AbstractParameterInfoTest : LightCodeInsightFixtureTestCase() {
|
||||
|
||||
val file = myFixture.file as KtFile
|
||||
|
||||
val configured = configureCompilerOptions(file.text, project, myFixture.module)
|
||||
|
||||
try {
|
||||
withCustomCompilerOptions(file.text, project, myFixture.module) {
|
||||
val lastChild = file.allChildren.filter { it !is PsiWhiteSpace }.last()
|
||||
val expectedResultText = when (lastChild.node.elementType) {
|
||||
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 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 parameterOwner = handler.findElementForParameterInfo(mockCreateParameterInfoContext) as PsiElement
|
||||
@@ -89,10 +90,6 @@ abstract class AbstractParameterInfoTest : LightCodeInsightFixtureTestCase() {
|
||||
}
|
||||
|
||||
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.test.DirectiveBasedActionUtils
|
||||
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
||||
import org.jetbrains.kotlin.idea.test.configureCompilerOptions
|
||||
import org.jetbrains.kotlin.idea.test.rollbackCompilerOptions
|
||||
import org.jetbrains.kotlin.idea.test.withCustomCompilerOptions
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.TestFiles
|
||||
@@ -133,58 +132,67 @@ abstract class AbstractQuickFixMultiFileTest : KotlinLightCodeInsightFixtureTest
|
||||
}
|
||||
|
||||
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, {
|
||||
try {
|
||||
val psiFile = file
|
||||
val actionHint = ActionHint.parse(psiFile, beforeFile.content)
|
||||
val text = actionHint.expectedText
|
||||
|
||||
val actionHint = ActionHint.parse(psiFile, beforeFile.content)
|
||||
val text = actionHint.expectedText
|
||||
val actionShouldBeAvailable = actionHint.shouldPresent()
|
||||
|
||||
val actionShouldBeAvailable = actionHint.shouldPresent()
|
||||
|
||||
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())
|
||||
if (psiFile is KtFile) {
|
||||
DirectiveBasedActionUtils.checkForUnexpectedErrors(psiFile)
|
||||
}
|
||||
|
||||
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)
|
||||
doAction(
|
||||
text,
|
||||
file,
|
||||
editor,
|
||||
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) {
|
||||
@@ -205,57 +213,71 @@ abstract class AbstractQuickFixMultiFileTest : KotlinLightCodeInsightFixtureTest
|
||||
|
||||
myFixture.configureByFiles(*testFiles.toTypedArray())
|
||||
|
||||
val configured = configureCompilerOptions(originalFileText, project, module)
|
||||
|
||||
CommandProcessor.getInstance().executeCommand(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.")
|
||||
withCustomCompilerOptions(originalFileText, project, module) {
|
||||
CommandProcessor.getInstance().executeCommand(
|
||||
project,
|
||||
{
|
||||
try {
|
||||
myFixture.checkResultByFile(mainFile.name.replace(".before.Main.", ".after."))
|
||||
} catch (e: ComparisonFailure) {
|
||||
KotlinTestUtils.assertEqualsToFile(File(afterFilePath), editor)
|
||||
}
|
||||
val psiFile = file
|
||||
|
||||
for (file in myFixture.file.containingDirectory.files) {
|
||||
val fileName = file.name
|
||||
if (fileName == myFixture.file.name || !fileName.startsWith(extraFileNamePrefix(myFixture.file.name))) continue
|
||||
val actionHint = ActionHint.parse(psiFile, originalFileText)
|
||||
val text = actionHint.expectedText
|
||||
|
||||
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)
|
||||
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 {
|
||||
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>
|
||||
|
||||
@@ -54,19 +54,15 @@ abstract class AbstractQuickFixTest : KotlinLightCodeInsightFixtureTestCase(), Q
|
||||
@Throws(Exception::class)
|
||||
protected fun doTest(beforeFileName: String) {
|
||||
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()
|
||||
|
||||
try {
|
||||
myFixture.enableInspections(*inspections)
|
||||
|
||||
doKotlinQuickFixTest(beforeFileName)
|
||||
checkForUnexpectedErrors()
|
||||
} finally {
|
||||
myFixture.disableInspections(*inspections)
|
||||
if (configured) {
|
||||
rollbackCompilerOptions(project, module)
|
||||
doKotlinQuickFixTest(beforeFileName)
|
||||
checkForUnexpectedErrors()
|
||||
} finally {
|
||||
myFixture.disableInspections(*inspections)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,7 @@ import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture
|
||||
import junit.framework.TestCase
|
||||
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
||||
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
|
||||
import org.jetbrains.kotlin.idea.test.configureCompilerOptions
|
||||
import org.jetbrains.kotlin.idea.test.rollbackCompilerOptions
|
||||
import org.jetbrains.kotlin.idea.test.withCustomCompilerOptions
|
||||
import org.jetbrains.kotlin.idea.util.application.runWriteAction
|
||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
@@ -41,13 +40,11 @@ abstract class AbstractInlineTest : KotlinLightCodeInsightFixtureTestCase() {
|
||||
val extraFilesToPsi = extraFiles.associateBy { fixture.configureByFile(it.name) }
|
||||
val file = myFixture.configureByFile(fileName())
|
||||
|
||||
val configured = configureCompilerOptions(file.text, project, module)
|
||||
|
||||
try {
|
||||
withCustomCompilerOptions(file.text, project, module) {
|
||||
val afterFileExists = afterFile.exists()
|
||||
|
||||
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")
|
||||
val handler = Extensions.getExtensions(InlineActionHandler.EP_NAME).firstOrNull { it.canInlineElement(targetElement) }
|
||||
@@ -74,10 +71,6 @@ abstract class AbstractInlineTest : KotlinLightCodeInsightFixtureTestCase() {
|
||||
} else {
|
||||
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 fileText = FileUtil.loadFile(File(path), true)
|
||||
|
||||
val configured = configureCompilerOptions(fileText, project, module)
|
||||
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)
|
||||
withCustomCompilerOptions(fileText, project, module) {
|
||||
ConfigLibraryUtil.configureLibrariesByDirective(module, PlatformTestUtil.getCommunityPath(), fileText)
|
||||
|
||||
val addKotlinRuntime = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// WITH_RUNTIME") != null
|
||||
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.idea.KotlinFileType
|
||||
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.KotlinWithJdkAndRuntimeLightProjectDescriptor
|
||||
import org.jetbrains.kotlin.idea.test.configureCompilerOptions
|
||||
import org.jetbrains.kotlin.idea.test.rollbackCompilerOptions
|
||||
import org.jetbrains.kotlin.idea.test.withCustomCompilerOptions
|
||||
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
|
||||
@@ -51,9 +49,7 @@ abstract class AbstractPartialBodyResolveTest : KotlinLightCodeInsightFixtureTes
|
||||
|
||||
private fun dump(testPath: String, resolveMode: BodyResolveMode): String {
|
||||
myFixture.configureByText(KotlinFileType.INSTANCE, File(testPath).readText())
|
||||
val configured = configureCompilerOptions(myFixture.file.text, project, module)
|
||||
|
||||
try {
|
||||
return withCustomCompilerOptions(myFixture.file.text, project, module) {
|
||||
val file = myFixture.file as KtFile
|
||||
val editor = myFixture.editor
|
||||
val selectionModel = editor.selectionModel
|
||||
@@ -121,11 +117,7 @@ abstract class AbstractPartialBodyResolveTest : KotlinLightCodeInsightFixtureTes
|
||||
Assert.assertEquals(target2.presentation(null), target1.presentation(null))
|
||||
Assert.assertEquals(type2.presentation(), type1.presentation())
|
||||
|
||||
return builder.toString()
|
||||
} finally {
|
||||
if (configured) {
|
||||
rollbackCompilerOptions(project, module)
|
||||
}
|
||||
builder.toString()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user