[Testing] Remove duplicate logic, clean-up CheckerTestUtil
This commit is contained in:
@@ -67,9 +67,9 @@ class TextDiagnostic(
|
||||
return result
|
||||
}
|
||||
|
||||
fun asString(): String {
|
||||
fun asString(withNewInference: Boolean = true, renderParameters: Boolean = true): String {
|
||||
val result = StringBuilder()
|
||||
if (inferenceCompatibility.abbreviation != null) {
|
||||
if (withNewInference && inferenceCompatibility.abbreviation != null) {
|
||||
result.append(inferenceCompatibility.abbreviation)
|
||||
result.append(";")
|
||||
}
|
||||
@@ -78,9 +78,10 @@ class TextDiagnostic(
|
||||
result.append(":")
|
||||
}
|
||||
result.append(name)
|
||||
if (parameters != null) {
|
||||
|
||||
if (renderParameters && parameters != null) {
|
||||
result.append("(")
|
||||
result.append(StringUtil.join(parameters, { "\"$it\"" }, ", "))
|
||||
result.append(StringUtil.join(parameters, { "\"${it.replace('\n', ' ')}\"" }, ", "))
|
||||
result.append(")")
|
||||
}
|
||||
return result.toString()
|
||||
|
||||
@@ -44,7 +44,7 @@ object CheckerTestUtil {
|
||||
private const val IGNORE_DIAGNOSTIC_PARAMETER = "IGNORE"
|
||||
private const val INDIVIDUAL_DIAGNOSTIC = """(\w+;)?(\w+:)?(\w+)(?:\(((?:".*?")(?:,\s*".*?")*)\))?"""
|
||||
|
||||
private val rangeStartOrEndPattern = Pattern.compile("(<!$INDIVIDUAL_DIAGNOSTIC(,\\s*$INDIVIDUAL_DIAGNOSTIC)*!>)|(<!>)")
|
||||
internal val rangeStartOrEndPattern = Pattern.compile("(<!$INDIVIDUAL_DIAGNOSTIC(,\\s*$INDIVIDUAL_DIAGNOSTIC)*!>)|(<!>)")
|
||||
val individualDiagnosticPattern: Pattern = Pattern.compile(INDIVIDUAL_DIAGNOSTIC)
|
||||
|
||||
fun getDiagnosticsIncludingSyntaxErrors(
|
||||
@@ -328,6 +328,7 @@ object CheckerTestUtil {
|
||||
return false
|
||||
if (expected.parameters == null)
|
||||
return true
|
||||
|
||||
if (actual.parameters == null || expected.parameters.size != actual.parameters.size)
|
||||
return false
|
||||
|
||||
@@ -420,7 +421,7 @@ object CheckerTestUtil {
|
||||
psiFile,
|
||||
diagnostics,
|
||||
emptyMap(),
|
||||
com.intellij.util.Function { it.text },
|
||||
{ it.text },
|
||||
emptyList(),
|
||||
false,
|
||||
false
|
||||
@@ -430,12 +431,12 @@ object CheckerTestUtil {
|
||||
psiFile: PsiFile,
|
||||
diagnostics: Collection<ActualDiagnostic>,
|
||||
diagnosticToExpectedDiagnostic: Map<AbstractTestDiagnostic, TextDiagnostic>,
|
||||
getFileText: com.intellij.util.Function<PsiFile, String>,
|
||||
getFileText: (PsiFile) -> String,
|
||||
uncheckedDiagnostics: Collection<PositionalTextDiagnostic>,
|
||||
withNewInferenceDirective: Boolean,
|
||||
renderDiagnosticMessages: Boolean
|
||||
): StringBuffer {
|
||||
val text = getFileText.`fun`(psiFile)
|
||||
val text = getFileText(psiFile)
|
||||
val result = StringBuffer()
|
||||
val diagnosticsFiltered = diagnostics.filter { actualDiagnostic -> psiFile == actualDiagnostic.file }
|
||||
if (diagnosticsFiltered.isEmpty() && uncheckedDiagnostics.isEmpty()) {
|
||||
@@ -514,33 +515,15 @@ object CheckerTestUtil {
|
||||
|
||||
for (diagnostic in diagnostics) {
|
||||
val expectedDiagnostic = diagnosticToExpectedDiagnostic[diagnostic]
|
||||
if (expectedDiagnostic != null) {
|
||||
val actualTextDiagnostic = TextDiagnostic.asTextDiagnostic(diagnostic)
|
||||
val actualTextDiagnostic = TextDiagnostic.asTextDiagnostic(diagnostic)
|
||||
|
||||
if (expectedDiagnostic != null || !hasExplicitDefinitionOnlyOption(diagnostic)) {
|
||||
val shouldRenderParameters =
|
||||
renderDiagnosticMessages || expectedDiagnostic?.parameters != null
|
||||
|
||||
diagnosticsAsText.add(
|
||||
if (compareTextDiagnostic(expectedDiagnostic, actualTextDiagnostic))
|
||||
expectedDiagnostic.asString() else actualTextDiagnostic.asString()
|
||||
actualTextDiagnostic.asString(withNewInferenceDirective, shouldRenderParameters)
|
||||
)
|
||||
} else if (!hasExplicitDefinitionOnlyOption(diagnostic)) {
|
||||
val diagnosticText = StringBuilder()
|
||||
if (withNewInferenceDirective && diagnostic.inferenceCompatibility.abbreviation != null) {
|
||||
diagnosticText.append(diagnostic.inferenceCompatibility.abbreviation)
|
||||
diagnosticText.append(";")
|
||||
}
|
||||
if (diagnostic.platform != null) {
|
||||
diagnosticText.append(diagnostic.platform)
|
||||
diagnosticText.append(":")
|
||||
}
|
||||
diagnosticText.append(diagnostic.name)
|
||||
if (renderDiagnosticMessages) {
|
||||
val textDiagnostic = TextDiagnostic.asTextDiagnostic(diagnostic)
|
||||
if (textDiagnostic.parameters != null) {
|
||||
diagnosticText
|
||||
.append("(")
|
||||
.append(textDiagnostic.parameters.joinToString(", "))
|
||||
.append(")")
|
||||
}
|
||||
}
|
||||
diagnosticsAsText.add(diagnosticText.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.checkers.utils
|
||||
|
||||
import java.io.File
|
||||
|
||||
fun clearFileFromDiagnosticMarkup(file: File) {
|
||||
val text = file.readText()
|
||||
val cleanText = clearTextFromDiagnosticMarkup(text)
|
||||
file.writeText(cleanText)
|
||||
}
|
||||
|
||||
fun clearTextFromDiagnosticMarkup(text: String): String = CheckerTestUtil.rangeStartOrEndPattern.matcher(text).replaceAll("")
|
||||
@@ -330,7 +330,7 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava<TestModule, Tes
|
||||
ktFile,
|
||||
filteredDiagnostics,
|
||||
diagnosticToExpectedDiagnostic,
|
||||
com.intellij.util.Function { file -> file.text },
|
||||
{ file -> file.text },
|
||||
uncheckedDiagnostics,
|
||||
withNewInferenceDirective,
|
||||
renderDiagnosticMessages
|
||||
|
||||
@@ -226,8 +226,8 @@ fun case_19(b: Boolean) {
|
||||
}
|
||||
} else null
|
||||
|
||||
if (a != null && <!NI;DEBUG_INFO_SMARTCAST!>a<!>.B19 != null && <!NI;DEBUG_INFO_SMARTCAST!><!NI;DEBUG_INFO_SMARTCAST!>a<!>.B19<!>.C19 != null && <!NI;DEBUG_INFO_SMARTCAST!><!NI;DEBUG_INFO_SMARTCAST!><!NI;DEBUG_INFO_SMARTCAST!>a<!>.B19<!>.C19<!>.D19 != null && <!NI;DEBUG_INFO_SMARTCAST!><!NI;DEBUG_INFO_SMARTCAST!><!NI;DEBUG_INFO_SMARTCAST!><!NI;DEBUG_INFO_SMARTCAST!>a<!>.B19<!>.C19<!>.D19<!>.x == null) {
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Nothing? & kotlin.Number?")!><!NI;DEBUG_INFO_SMARTCAST!><!NI;DEBUG_INFO_SMARTCAST!><!NI;DEBUG_INFO_SMARTCAST!><!NI;DEBUG_INFO_SMARTCAST!>a<!>.B19<!>.C19<!>.D19<!>.x<!>
|
||||
if (a != null && <!DEBUG_INFO_SMARTCAST!>a<!>.B19 != null && <!DEBUG_INFO_SMARTCAST!><!DEBUG_INFO_SMARTCAST!>a<!>.B19<!>.C19 != null && <!DEBUG_INFO_SMARTCAST!><!DEBUG_INFO_SMARTCAST!><!DEBUG_INFO_SMARTCAST!>a<!>.B19<!>.C19<!>.D19 != null && <!DEBUG_INFO_SMARTCAST!><!DEBUG_INFO_SMARTCAST!><!DEBUG_INFO_SMARTCAST!><!DEBUG_INFO_SMARTCAST!>a<!>.B19<!>.C19<!>.D19<!>.x == null) {
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Nothing? & kotlin.Number?")!><!DEBUG_INFO_SMARTCAST!><!DEBUG_INFO_SMARTCAST!><!DEBUG_INFO_SMARTCAST!><!DEBUG_INFO_SMARTCAST!>a<!>.B19<!>.C19<!>.D19<!>.x<!>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -128,7 +128,7 @@ fun case_12(x: TypealiasString, y: TypealiasString) = <!DEBUG_INFO_EXPRESSION_TY
|
||||
fun case_13(x: otherpackage.EmptyClass13) =
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int")!>if (<!SENSELESS_COMPARISON!>x != null<!>) {
|
||||
1
|
||||
} else <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Nothing & otherpackage.EmptyClass13"), NI;DEBUG_INFO_SMARTCAST!>x<!><!>
|
||||
} else <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Nothing & otherpackage.EmptyClass13"), DEBUG_INFO_SMARTCAST!>x<!><!>
|
||||
|
||||
// TESTCASE NUMBER: 14
|
||||
class A14 {
|
||||
|
||||
Reference in New Issue
Block a user