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:
Dmitriy Novozhilov
2018-09-24 13:51:36 +03:00
committed by Dmitriy Novozhilov
parent 2866bd84a1
commit 68d7e51d32
3 changed files with 38 additions and 4 deletions
@@ -411,6 +411,18 @@ public class CheckerTestUtil {
@NotNull Function<PsiFile, String> getFileText,
@NotNull Collection<PositionalTextDiagnostic> uncheckedDiagnostics,
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);
StringBuffer result = new StringBuffer();
@@ -433,7 +445,7 @@ public class CheckerTestUtil {
opened.pop();
}
while (currentDescriptor != null && i == currentDescriptor.start) {
openDiagnosticsString(result, currentDescriptor, diagnosticToExpectedDiagnostic, withNewInferenceDirective);
openDiagnosticsString(result, currentDescriptor, diagnosticToExpectedDiagnostic, withNewInferenceDirective, renderDiagnosticMessages);
if (currentDescriptor.getEnd() == i) {
closeDiagnosticString(result);
}
@@ -453,7 +465,7 @@ public class CheckerTestUtil {
if (currentDescriptor != null) {
assert currentDescriptor.start == text.length();
assert currentDescriptor.end == text.length();
openDiagnosticsString(result, currentDescriptor, diagnosticToExpectedDiagnostic, withNewInferenceDirective);
openDiagnosticsString(result, currentDescriptor, diagnosticToExpectedDiagnostic, withNewInferenceDirective, renderDiagnosticMessages);
opened.push(currentDescriptor);
}
@@ -471,7 +483,8 @@ public class CheckerTestUtil {
StringBuffer result,
AbstractDiagnosticDescriptor currentDescriptor,
Map<AbstractTestDiagnostic, TextDiagnostic> diagnosticToExpectedDiagnostic,
boolean withNewInferenceDirective
boolean withNewInferenceDirective,
boolean renderDiagnosticMessages
) {
result.append("<!");
if (currentDescriptor instanceof TextDiagnosticDescriptor) {
@@ -502,6 +515,14 @@ public class CheckerTestUtil {
result.append(":");
}
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()) {
result.append(", ");
+8
View File
@@ -97,3 +97,11 @@ Note that if this directive is present, the NEWER_VERSION_IN_SINCE_KOTLIN diagno
#### Usage:
// !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 withNewInferenceDirective: Boolean
val newInferenceEnabled: Boolean
val renderDiagnosticMessages: Boolean
init {
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.createKtFile = lazy { TestCheckerUtil.createCheckAndReturnPsiFile(fileName, clearText, project) }
}
this.renderDiagnosticMessages = RENDER_DIAGNOSTICS_MESSAGES in directives
}
val ktFile: KtFile? by createKtFile
@@ -302,7 +304,8 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava<TestModule, Tes
diagnosticToExpectedDiagnostic,
{ file -> file.text },
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)
val USE_OLD_INFERENCE_DIAGNOSTICS_FOR_NI = false
val RENDER_DIAGNOSTICS_MESSAGES = "RENDER_DIAGNOSTICS_MESSAGES"
private fun parseDiagnosticFilterDirective(
directiveMap: Map<String, String>,
allowUnderscoreUsage: Boolean