Don't forget to rollback configured compiler options in IDE tests
This commit is contained in:
+6
-2
@@ -13,6 +13,7 @@ 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.configureCompilerOptions
|
||||||
|
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
|
||||||
@@ -30,11 +31,11 @@ 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 configured = configureCompilerOptions(fileText, project, module)
|
||||||
try {
|
try {
|
||||||
val fileText = FileUtil.loadFile(File(testPath))
|
|
||||||
assertTrue("\"<caret>\" is missing in file \"$testPath\"", fileText.contains("<caret>"));
|
assertTrue("\"<caret>\" is missing in file \"$testPath\"", fileText.contains("<caret>"));
|
||||||
|
|
||||||
configureCompilerOptions(fileText, project, module)
|
|
||||||
|
|
||||||
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)
|
||||||
@@ -71,6 +72,9 @@ abstract class AbstractCompletionHandlerTest(private val defaultCompletionType:
|
|||||||
|
|
||||||
doTestWithTextLoaded(completionType, invocationCount, lookupString, itemText, tailText, completionChar, File(testPath).name + ".after")
|
doTestWithTextLoaded(completionType, invocationCount, lookupString, itemText, tailText, completionChar, File(testPath).name + ".after")
|
||||||
} finally {
|
} finally {
|
||||||
|
if (configured) {
|
||||||
|
rollbackCompilerOptions(project, module)
|
||||||
|
}
|
||||||
CodeStyle.dropTemporarySettings(project)
|
CodeStyle.dropTemporarySettings(project)
|
||||||
tearDownFixture()
|
tearDownFixture()
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-3
@@ -11,6 +11,7 @@ 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.configureCompilerOptions
|
||||||
|
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
|
||||||
|
|
||||||
@@ -24,13 +25,19 @@ abstract class AbstractCompletionWeigherTest(val completionType: CompletionType,
|
|||||||
|
|
||||||
val text = myFixture.editor.document.text
|
val text = myFixture.editor.document.text
|
||||||
|
|
||||||
configureCompilerOptions(text, project, module)
|
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.isEmpty())
|
Assert.assertTrue("""Some items should be defined with "// ORDER:" directive""", !items.isEmpty())
|
||||||
|
|
||||||
myFixture.complete(completionType, InTextDirectivesUtils.getPrefixedInt(text, "// INVOCATION_COUNT:") ?: 1)
|
try {
|
||||||
myFixture.assertPreferredCompletionItems(InTextDirectivesUtils.getPrefixedInt(text, "// SELECTED:") ?: 0, *items)
|
myFixture.complete(completionType, InTextDirectivesUtils.getPrefixedInt(text, "// INVOCATION_COUNT:") ?: 1)
|
||||||
|
myFixture.assertPreferredCompletionItems(InTextDirectivesUtils.getPrefixedInt(text, "// SELECTED:") ?: 0, *items)
|
||||||
|
} finally {
|
||||||
|
if (configured) {
|
||||||
|
rollbackCompilerOptions(project, module)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,10 +15,7 @@ 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.SdkAndMockLibraryProjectDescriptor
|
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.configureCompilerOptions
|
|
||||||
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
|
||||||
@@ -53,43 +50,49 @@ abstract class AbstractParameterInfoTest : LightCodeInsightFixtureTestCase() {
|
|||||||
|
|
||||||
val file = myFixture.file as KtFile
|
val file = myFixture.file as KtFile
|
||||||
|
|
||||||
configureCompilerOptions(file.text, project, myFixture.module)
|
val configured = configureCompilerOptions(file.text, project, myFixture.module)
|
||||||
|
|
||||||
val lastChild = file.allChildren.filter { it !is PsiWhiteSpace }.last()
|
try {
|
||||||
val expectedResultText = when (lastChild.node.elementType) {
|
val lastChild = file.allChildren.filter { it !is PsiWhiteSpace }.last()
|
||||||
KtTokens.BLOCK_COMMENT -> lastChild.text.substring(2, lastChild.text.length - 2).trim()
|
val expectedResultText = when (lastChild.node.elementType) {
|
||||||
KtTokens.EOL_COMMENT -> lastChild.text.substring(2).trim()
|
KtTokens.BLOCK_COMMENT -> lastChild.text.substring(2, lastChild.text.length - 2).trim()
|
||||||
else -> error("Unexpected last file child")
|
KtTokens.EOL_COMMENT -> lastChild.text.substring(2).trim()
|
||||||
|
else -> error("Unexpected last file child")
|
||||||
|
}
|
||||||
|
|
||||||
|
val context = ShowParameterInfoContext(editor, project, file, editor.caretModel.offset, -1, true)
|
||||||
|
|
||||||
|
val handlers = ShowParameterInfoHandler.getHandlers(project, KotlinLanguage.INSTANCE)!!
|
||||||
|
val handler = handlers.firstOrNull { it.findElementForParameterInfo(context) != null }
|
||||||
|
?: error("Could not find parameter info handler")
|
||||||
|
|
||||||
|
val mockCreateParameterInfoContext = MockCreateParameterInfoContext(file, myFixture)
|
||||||
|
val parameterOwner = handler.findElementForParameterInfo(mockCreateParameterInfoContext) as PsiElement
|
||||||
|
|
||||||
|
val textToType = InTextDirectivesUtils.findStringWithPrefixes(file.text, "// TYPE:")
|
||||||
|
if (textToType != null) {
|
||||||
|
myFixture.type(textToType)
|
||||||
|
PsiDocumentManager.getInstance(project).commitAllDocuments()
|
||||||
|
}
|
||||||
|
|
||||||
|
//to update current parameter index
|
||||||
|
val updateContext = MockUpdateParameterInfoContext(file, myFixture)
|
||||||
|
val elementForUpdating = handler.findElementForUpdatingParameterInfo(updateContext)
|
||||||
|
if (elementForUpdating != null) {
|
||||||
|
handler.updateParameterInfo(elementForUpdating, updateContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
val parameterInfoUIContext = MockParameterInfoUIContext(parameterOwner, updateContext.currentParameter)
|
||||||
|
|
||||||
|
mockCreateParameterInfoContext.itemsToShow?.forEach {
|
||||||
|
handler.updateUI(it, parameterInfoUIContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.assertEquals(expectedResultText, parameterInfoUIContext.resultText)
|
||||||
|
} finally {
|
||||||
|
if (configured) {
|
||||||
|
rollbackCompilerOptions(project, myFixture.module)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val context = ShowParameterInfoContext(editor, project, file, editor.caretModel.offset, -1, true)
|
|
||||||
|
|
||||||
val handlers = ShowParameterInfoHandler.getHandlers(project, KotlinLanguage.INSTANCE)!!
|
|
||||||
val handler = handlers.firstOrNull { it.findElementForParameterInfo(context) != null }
|
|
||||||
?: error("Could not find parameter info handler")
|
|
||||||
|
|
||||||
val mockCreateParameterInfoContext = MockCreateParameterInfoContext(file, myFixture)
|
|
||||||
val parameterOwner = handler.findElementForParameterInfo(mockCreateParameterInfoContext) as PsiElement
|
|
||||||
|
|
||||||
val textToType = InTextDirectivesUtils.findStringWithPrefixes(file.text, "// TYPE:")
|
|
||||||
if (textToType != null) {
|
|
||||||
myFixture.type(textToType)
|
|
||||||
PsiDocumentManager.getInstance(project).commitAllDocuments()
|
|
||||||
}
|
|
||||||
|
|
||||||
//to update current parameter index
|
|
||||||
val updateContext = MockUpdateParameterInfoContext(file, myFixture)
|
|
||||||
val elementForUpdating = handler.findElementForUpdatingParameterInfo(updateContext)
|
|
||||||
if (elementForUpdating != null) {
|
|
||||||
handler.updateParameterInfo(elementForUpdating, updateContext)
|
|
||||||
}
|
|
||||||
|
|
||||||
val parameterInfoUIContext = MockParameterInfoUIContext(parameterOwner, updateContext.currentParameter)
|
|
||||||
|
|
||||||
mockCreateParameterInfoContext.itemsToShow?.forEach {
|
|
||||||
handler.updateUI(it, parameterInfoUIContext)
|
|
||||||
}
|
|
||||||
|
|
||||||
Assert.assertEquals(expectedResultText, parameterInfoUIContext.resultText)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ 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.configureCompilerOptions
|
||||||
|
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
|
||||||
@@ -40,37 +41,43 @@ abstract class AbstractInlineTest : KotlinLightCodeInsightFixtureTestCase() {
|
|||||||
val extraFilesToPsi = extraFiles.associateBy { fixture.configureByFile(path.replace(mainFileName, it.name)) }
|
val extraFilesToPsi = extraFiles.associateBy { fixture.configureByFile(path.replace(mainFileName, it.name)) }
|
||||||
val file = myFixture.configureByFile(path)
|
val file = myFixture.configureByFile(path)
|
||||||
|
|
||||||
configureCompilerOptions(file.text, project, module)
|
val configured = configureCompilerOptions(file.text, project, module)
|
||||||
|
|
||||||
val afterFileExists = afterFile.exists()
|
try {
|
||||||
|
val afterFileExists = afterFile.exists()
|
||||||
|
|
||||||
val targetElement = TargetElementUtil.findTargetElement(myFixture.editor, ELEMENT_NAME_ACCEPTED or REFERENCED_ELEMENT_ACCEPTED)!!
|
val targetElement = TargetElementUtil.findTargetElement(myFixture.editor, ELEMENT_NAME_ACCEPTED or REFERENCED_ELEMENT_ACCEPTED)!!
|
||||||
val handler = Extensions.getExtensions(InlineActionHandler.EP_NAME).firstOrNull { it.canInlineElement(targetElement) }
|
val handler = Extensions.getExtensions(InlineActionHandler.EP_NAME).firstOrNull { it.canInlineElement(targetElement) }
|
||||||
val expectedErrors = InTextDirectivesUtils.findLinesWithPrefixesRemoved(myFixture.file.text, "// ERROR: ")
|
val expectedErrors = InTextDirectivesUtils.findLinesWithPrefixesRemoved(myFixture.file.text, "// ERROR: ")
|
||||||
if (handler != null) {
|
if (handler != null) {
|
||||||
try {
|
try {
|
||||||
runWriteAction { handler.inlineElement(myFixture.project, myFixture.editor, targetElement) }
|
runWriteAction { handler.inlineElement(myFixture.project, myFixture.editor, targetElement) }
|
||||||
|
|
||||||
UsefulTestCase.assertEmpty(expectedErrors)
|
UsefulTestCase.assertEmpty(expectedErrors)
|
||||||
KotlinTestUtils.assertEqualsToFile(afterFile, file.text)
|
KotlinTestUtils.assertEqualsToFile(afterFile, file.text)
|
||||||
for ((extraPsiFile, extraFile) in extraFilesToPsi) {
|
for ((extraPsiFile, extraFile) in extraFilesToPsi) {
|
||||||
KotlinTestUtils.assertEqualsToFile(File("${extraFile.path}.after"), extraPsiFile.text)
|
KotlinTestUtils.assertEqualsToFile(File("${extraFile.path}.after"), extraPsiFile.text)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (e: CommonRefactoringUtil.RefactoringErrorHintException) {
|
||||||
|
TestCase.assertFalse("Refactoring not available: ${e.message}", afterFileExists)
|
||||||
|
TestCase.assertEquals("Expected errors", 1, expectedErrors.size)
|
||||||
|
TestCase.assertEquals("Error message", expectedErrors[0].replace("\\n", "\n"), e.message)
|
||||||
|
}
|
||||||
|
catch (e: BaseRefactoringProcessor.ConflictsInTestsException) {
|
||||||
|
TestCase.assertFalse("Conflicts: ${e.message}", afterFileExists)
|
||||||
|
TestCase.assertEquals("Expected errors", 1, expectedErrors.size)
|
||||||
|
TestCase.assertEquals("Error message", expectedErrors[0].replace("\\n", "\n"), e.message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (e: CommonRefactoringUtil.RefactoringErrorHintException) {
|
else {
|
||||||
TestCase.assertFalse("Refactoring not available: ${e.message}", afterFileExists)
|
TestCase.assertFalse("No refactoring handler available", afterFileExists)
|
||||||
TestCase.assertEquals("Expected errors", 1, expectedErrors.size)
|
|
||||||
TestCase.assertEquals("Error message", expectedErrors[0].replace("\\n", "\n"), e.message)
|
|
||||||
}
|
}
|
||||||
catch (e: BaseRefactoringProcessor.ConflictsInTestsException) {
|
} finally {
|
||||||
TestCase.assertFalse("Conflicts: ${e.message}", afterFileExists)
|
if (configured) {
|
||||||
TestCase.assertEquals("Expected errors", 1, expectedErrors.size)
|
rollbackCompilerOptions(project, module)
|
||||||
TestCase.assertEquals("Error message", expectedErrors[0].replace("\\n", "\n"), e.message)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
TestCase.assertFalse("No refactoring handler available", afterFileExists)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getProjectDescriptor() = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE
|
override fun getProjectDescriptor() = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE
|
||||||
|
|||||||
Reference in New Issue
Block a user