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