Support test directive for rendering full diagnostic messages
New `RENDER_DIAGNOSTICS_MESSAGES` directive forces test system render full messages for all diagnostics that found in test file
This commit is contained in:
committed by
Dmitriy Novozhilov
parent
2866bd84a1
commit
68d7e51d32
@@ -411,6 +411,18 @@ public class CheckerTestUtil {
|
|||||||
@NotNull Function<PsiFile, String> getFileText,
|
@NotNull Function<PsiFile, String> getFileText,
|
||||||
@NotNull Collection<PositionalTextDiagnostic> uncheckedDiagnostics,
|
@NotNull Collection<PositionalTextDiagnostic> uncheckedDiagnostics,
|
||||||
boolean withNewInferenceDirective
|
boolean withNewInferenceDirective
|
||||||
|
) {
|
||||||
|
return addDiagnosticMarkersToText(psiFile, diagnostics, diagnosticToExpectedDiagnostic, getFileText, uncheckedDiagnostics, withNewInferenceDirective, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static StringBuffer addDiagnosticMarkersToText(
|
||||||
|
@NotNull PsiFile psiFile,
|
||||||
|
@NotNull Collection<ActualDiagnostic> diagnostics,
|
||||||
|
@NotNull Map<AbstractTestDiagnostic, TextDiagnostic> diagnosticToExpectedDiagnostic,
|
||||||
|
@NotNull Function<PsiFile, String> getFileText,
|
||||||
|
@NotNull Collection<PositionalTextDiagnostic> uncheckedDiagnostics,
|
||||||
|
boolean withNewInferenceDirective,
|
||||||
|
boolean renderDiagnosticMessages
|
||||||
) {
|
) {
|
||||||
String text = getFileText.fun(psiFile);
|
String text = getFileText.fun(psiFile);
|
||||||
StringBuffer result = new StringBuffer();
|
StringBuffer result = new StringBuffer();
|
||||||
@@ -433,7 +445,7 @@ public class CheckerTestUtil {
|
|||||||
opened.pop();
|
opened.pop();
|
||||||
}
|
}
|
||||||
while (currentDescriptor != null && i == currentDescriptor.start) {
|
while (currentDescriptor != null && i == currentDescriptor.start) {
|
||||||
openDiagnosticsString(result, currentDescriptor, diagnosticToExpectedDiagnostic, withNewInferenceDirective);
|
openDiagnosticsString(result, currentDescriptor, diagnosticToExpectedDiagnostic, withNewInferenceDirective, renderDiagnosticMessages);
|
||||||
if (currentDescriptor.getEnd() == i) {
|
if (currentDescriptor.getEnd() == i) {
|
||||||
closeDiagnosticString(result);
|
closeDiagnosticString(result);
|
||||||
}
|
}
|
||||||
@@ -453,7 +465,7 @@ public class CheckerTestUtil {
|
|||||||
if (currentDescriptor != null) {
|
if (currentDescriptor != null) {
|
||||||
assert currentDescriptor.start == text.length();
|
assert currentDescriptor.start == text.length();
|
||||||
assert currentDescriptor.end == text.length();
|
assert currentDescriptor.end == text.length();
|
||||||
openDiagnosticsString(result, currentDescriptor, diagnosticToExpectedDiagnostic, withNewInferenceDirective);
|
openDiagnosticsString(result, currentDescriptor, diagnosticToExpectedDiagnostic, withNewInferenceDirective, renderDiagnosticMessages);
|
||||||
opened.push(currentDescriptor);
|
opened.push(currentDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -471,7 +483,8 @@ public class CheckerTestUtil {
|
|||||||
StringBuffer result,
|
StringBuffer result,
|
||||||
AbstractDiagnosticDescriptor currentDescriptor,
|
AbstractDiagnosticDescriptor currentDescriptor,
|
||||||
Map<AbstractTestDiagnostic, TextDiagnostic> diagnosticToExpectedDiagnostic,
|
Map<AbstractTestDiagnostic, TextDiagnostic> diagnosticToExpectedDiagnostic,
|
||||||
boolean withNewInferenceDirective
|
boolean withNewInferenceDirective,
|
||||||
|
boolean renderDiagnosticMessages
|
||||||
) {
|
) {
|
||||||
result.append("<!");
|
result.append("<!");
|
||||||
if (currentDescriptor instanceof TextDiagnosticDescriptor) {
|
if (currentDescriptor instanceof TextDiagnosticDescriptor) {
|
||||||
@@ -502,6 +515,14 @@ public class CheckerTestUtil {
|
|||||||
result.append(":");
|
result.append(":");
|
||||||
}
|
}
|
||||||
result.append(diagnostic.getName());
|
result.append(diagnostic.getName());
|
||||||
|
if (renderDiagnosticMessages) {
|
||||||
|
TextDiagnostic textDiagnostic = TextDiagnostic.asTextDiagnostic(diagnostic);
|
||||||
|
if (textDiagnostic.getParameters() != null) {
|
||||||
|
result.append("(")
|
||||||
|
.append(String.join(", ", textDiagnostic.getParameters()))
|
||||||
|
.append(")");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (iterator.hasNext()) {
|
if (iterator.hasNext()) {
|
||||||
result.append(", ");
|
result.append(", ");
|
||||||
|
|||||||
+8
@@ -97,3 +97,11 @@ Note that if this directive is present, the NEWER_VERSION_IN_SINCE_KOTLIN diagno
|
|||||||
#### Usage:
|
#### Usage:
|
||||||
|
|
||||||
// !API_VERSION: 1.0
|
// !API_VERSION: 1.0
|
||||||
|
|
||||||
|
### 6. RENDER_DIAGNOSTICS_MESSAGES
|
||||||
|
|
||||||
|
This directive forces *Diagnostic printer* prints parametrized diagnostics with all parameters.
|
||||||
|
|
||||||
|
#### Usage:
|
||||||
|
|
||||||
|
// !RENDER_DIAGNOSTICS_MESSAGES
|
||||||
|
|||||||
@@ -140,6 +140,7 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava<TestModule, Tes
|
|||||||
val dynamicCallDescriptors: List<DeclarationDescriptor> = ArrayList()
|
val dynamicCallDescriptors: List<DeclarationDescriptor> = ArrayList()
|
||||||
val withNewInferenceDirective: Boolean
|
val withNewInferenceDirective: Boolean
|
||||||
val newInferenceEnabled: Boolean
|
val newInferenceEnabled: Boolean
|
||||||
|
val renderDiagnosticMessages: Boolean
|
||||||
|
|
||||||
init {
|
init {
|
||||||
this.declareCheckType = CHECK_TYPE_DIRECTIVE in directives
|
this.declareCheckType = CHECK_TYPE_DIRECTIVE in directives
|
||||||
@@ -162,6 +163,7 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava<TestModule, Tes
|
|||||||
this.clearText = CheckerTestUtil.parseDiagnosedRanges(addExtras(expectedText), diagnosedRanges)
|
this.clearText = CheckerTestUtil.parseDiagnosedRanges(addExtras(expectedText), diagnosedRanges)
|
||||||
this.createKtFile = lazy { TestCheckerUtil.createCheckAndReturnPsiFile(fileName, clearText, project) }
|
this.createKtFile = lazy { TestCheckerUtil.createCheckAndReturnPsiFile(fileName, clearText, project) }
|
||||||
}
|
}
|
||||||
|
this.renderDiagnosticMessages = RENDER_DIAGNOSTICS_MESSAGES in directives
|
||||||
}
|
}
|
||||||
|
|
||||||
val ktFile: KtFile? by createKtFile
|
val ktFile: KtFile? by createKtFile
|
||||||
@@ -302,7 +304,8 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava<TestModule, Tes
|
|||||||
diagnosticToExpectedDiagnostic,
|
diagnosticToExpectedDiagnostic,
|
||||||
{ file -> file.text },
|
{ file -> file.text },
|
||||||
uncheckedDiagnostics,
|
uncheckedDiagnostics,
|
||||||
withNewInferenceDirective
|
withNewInferenceDirective,
|
||||||
|
renderDiagnosticMessages
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -375,6 +378,8 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava<TestModule, Tes
|
|||||||
// Change it to "true" to load diagnostics for old inference to test new inference (ignore diagnostics with <NI; prefix)
|
// Change it to "true" to load diagnostics for old inference to test new inference (ignore diagnostics with <NI; prefix)
|
||||||
val USE_OLD_INFERENCE_DIAGNOSTICS_FOR_NI = false
|
val USE_OLD_INFERENCE_DIAGNOSTICS_FOR_NI = false
|
||||||
|
|
||||||
|
val RENDER_DIAGNOSTICS_MESSAGES = "RENDER_DIAGNOSTICS_MESSAGES"
|
||||||
|
|
||||||
private fun parseDiagnosticFilterDirective(
|
private fun parseDiagnosticFilterDirective(
|
||||||
directiveMap: Map<String, String>,
|
directiveMap: Map<String, String>,
|
||||||
allowUnderscoreUsage: Boolean
|
allowUnderscoreUsage: Boolean
|
||||||
|
|||||||
Reference in New Issue
Block a user