TypeAccessibilityChecker: add logs for tests
This commit is contained in:
@@ -178,18 +178,23 @@ private tailrec fun TypeAccessibilityChecker.findAndApplyExistingClasses(element
|
|||||||
else findAndApplyExistingClasses(newExistingClasses)
|
else findAndApplyExistingClasses(newExistingClasses)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showUnknownTypesDialog(project: Project, declarationsWithNonExistentClasses: Collection<KtNamedDeclaration>): Boolean =
|
private fun showUnknownTypesDialog(project: Project, declarationsWithNonExistentClasses: Collection<KtNamedDeclaration>): Boolean {
|
||||||
declarationsWithNonExistentClasses.isEmpty() || showOkNoDialog(
|
if (declarationsWithNonExistentClasses.isEmpty()) return true
|
||||||
|
val message = StringUtil.escapeXmlEntities(
|
||||||
|
declarationsWithNonExistentClasses.joinToString(
|
||||||
|
prefix = "These declarations cannot be transformed:\n",
|
||||||
|
separator = "\n",
|
||||||
|
transform = ::getExpressionShortText
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
TypeAccessibilityChecker.testLog?.append("$message\n")
|
||||||
|
return ApplicationManager.getApplication().isUnitTestMode || showOkNoDialog(
|
||||||
"Unknown types",
|
"Unknown types",
|
||||||
StringUtil.escapeXmlEntities(
|
message,
|
||||||
declarationsWithNonExistentClasses.joinToString(
|
|
||||||
prefix = "These declarations cannot be transformed:\n",
|
|
||||||
separator = "\n",
|
|
||||||
transform = ::getExpressionShortText
|
|
||||||
)
|
|
||||||
),
|
|
||||||
project
|
project
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
private fun showUnknownTypesError(element: KtNamedDeclaration) {
|
private fun showUnknownTypesError(element: KtNamedDeclaration) {
|
||||||
element.findExistingEditor()?.let { editor ->
|
element.findExistingEditor()?.let { editor ->
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.idea.quickfix.expectactual
|
|||||||
|
|
||||||
import com.intellij.openapi.module.Module
|
import com.intellij.openapi.module.Module
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
|
import org.jetbrains.annotations.TestOnly
|
||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.psi.KtNamedDeclaration
|
import org.jetbrains.kotlin.psi.KtNamedDeclaration
|
||||||
@@ -33,5 +34,9 @@ interface TypeAccessibilityChecker {
|
|||||||
targetModule: Module,
|
targetModule: Module,
|
||||||
existingFqNames: Collection<String> = emptyList()
|
existingFqNames: Collection<String> = emptyList()
|
||||||
): TypeAccessibilityChecker = TypeAccessibilityCheckerImpl(project, targetModule, existingFqNames)
|
): TypeAccessibilityChecker = TypeAccessibilityCheckerImpl(project, targetModule, existingFqNames)
|
||||||
|
|
||||||
|
@get:TestOnly
|
||||||
|
@set:TestOnly
|
||||||
|
var testLog: StringBuilder? = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -14,6 +14,7 @@ import junit.framework.ComparisonFailure
|
|||||||
import junit.framework.TestCase
|
import junit.framework.TestCase
|
||||||
import org.jetbrains.kotlin.idea.inspections.findExistingEditor
|
import org.jetbrains.kotlin.idea.inspections.findExistingEditor
|
||||||
import org.jetbrains.kotlin.idea.multiplatform.setupMppProjectFromDirStructure
|
import org.jetbrains.kotlin.idea.multiplatform.setupMppProjectFromDirStructure
|
||||||
|
import org.jetbrains.kotlin.idea.quickfix.expectactual.TypeAccessibilityChecker
|
||||||
import org.jetbrains.kotlin.idea.stubs.AbstractMultiModuleTest
|
import org.jetbrains.kotlin.idea.stubs.AbstractMultiModuleTest
|
||||||
import org.jetbrains.kotlin.idea.test.DirectiveBasedActionUtils
|
import org.jetbrains.kotlin.idea.test.DirectiveBasedActionUtils
|
||||||
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
|
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
|
||||||
@@ -54,10 +55,16 @@ abstract class AbstractQuickFixMultiModuleTest : AbstractMultiModuleTest(), Quic
|
|||||||
expectedErrorMessage = InTextDirectivesUtils.findListWithPrefixes(actionFileText, "// SHOULD_FAIL_WITH: ")
|
expectedErrorMessage = InTextDirectivesUtils.findListWithPrefixes(actionFileText, "// SHOULD_FAIL_WITH: ")
|
||||||
.joinToString(separator = "\n")
|
.joinToString(separator = "\n")
|
||||||
|
|
||||||
AbstractQuickFixMultiFileTest.doAction(
|
TypeAccessibilityChecker.testLog = StringBuilder()
|
||||||
text, file, editor, actionShouldBeAvailable, actionFileName, this::availableActions, this::doHighlighting,
|
val log = try {
|
||||||
InTextDirectivesUtils.isDirectiveDefined(actionFile.text, "// SHOULD_BE_AVAILABLE_AFTER_EXECUTION")
|
AbstractQuickFixMultiFileTest.doAction(
|
||||||
)
|
text, file, editor, actionShouldBeAvailable, actionFileName, this::availableActions, this::doHighlighting,
|
||||||
|
InTextDirectivesUtils.isDirectiveDefined(actionFile.text, "// SHOULD_BE_AVAILABLE_AFTER_EXECUTION")
|
||||||
|
)
|
||||||
|
TypeAccessibilityChecker.testLog.toString()
|
||||||
|
} finally {
|
||||||
|
TypeAccessibilityChecker.testLog = null
|
||||||
|
}
|
||||||
|
|
||||||
if (actionFile is KtFile) {
|
if (actionFile is KtFile) {
|
||||||
DirectiveBasedActionUtils.checkForUnexpectedErrors(actionFile)
|
DirectiveBasedActionUtils.checkForUnexpectedErrors(actionFile)
|
||||||
@@ -66,7 +73,15 @@ abstract class AbstractQuickFixMultiModuleTest : AbstractMultiModuleTest(), Quic
|
|||||||
if (actionShouldBeAvailable) {
|
if (actionShouldBeAvailable) {
|
||||||
compareToExpected(dirPath)
|
compareToExpected(dirPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
UsefulTestCase.assertEmpty(expectedErrorMessage)
|
UsefulTestCase.assertEmpty(expectedErrorMessage)
|
||||||
|
val logFile = File("${dirPath}log.log")
|
||||||
|
if (log.isNotEmpty()) {
|
||||||
|
KotlinTestUtils.assertEqualsToFile(logFile, log)
|
||||||
|
} else {
|
||||||
|
TestCase.assertFalse(logFile.exists())
|
||||||
|
}
|
||||||
|
|
||||||
} catch (e: ComparisonFailure) {
|
} catch (e: ComparisonFailure) {
|
||||||
throw e
|
throw e
|
||||||
} catch (e: AssertionError) {
|
} catch (e: AssertionError) {
|
||||||
|
|||||||
Reference in New Issue
Block a user