Improve test framework for diagnostic tests with NI

Mark with `NI;` or `OI;` only diagnostics that are specific for concrete inference
This commit is contained in:
Mikhail Zarechenskiy
2017-11-20 09:16:09 +03:00
parent bd4d847943
commit 81b3fefa58
3 changed files with 193 additions and 144 deletions
@@ -225,15 +225,22 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava<TestModule, Tes
val withNewInference = newInferenceEnabled && withNewInferenceDirective && !USE_OLD_INFERENCE_DIAGNOSTICS_FOR_NI
val diagnostics = ContainerUtil.filter(
CheckerTestUtil.getDiagnosticsIncludingSyntaxErrors(
bindingContext, implementingModulesBindings, ktFile, markDynamicCalls, dynamicCallDescriptors, withNewInference
bindingContext, implementingModulesBindings, ktFile, markDynamicCalls, dynamicCallDescriptors, newInferenceEnabled
) + jvmSignatureDiagnostics,
{ whatDiagnosticsToConsider.value(it.diagnostic) }
)
val uncheckedDiagnostics = mutableListOf<PositionalTextDiagnostic>()
val inferenceCompatibilityOfTest = asInferenceCompatibility(withNewInference)
val invertedInferenceCompatibilityOfTest = asInferenceCompatibility(!withNewInference)
val diagnosticToExpectedDiagnostic = CheckerTestUtil.diagnosticsDiff(diagnosedRanges, diagnostics, object : CheckerTestUtil.DiagnosticDiffCallbacks {
override fun missingDiagnostic(diagnostic: CheckerTestUtil.TextDiagnostic, expectedStart: Int, expectedEnd: Int) {
if (withNewInferenceDirective && diagnostic.inferenceCompatibility != inferenceCompatibilityOfTest) {
updateUncheckedDiagnostics(diagnostic, expectedStart, expectedEnd)
return
}
val message = "Missing " + diagnostic.description + DiagnosticUtils.atLocation(ktFile, TextRange(expectedStart, expectedEnd))
System.err.println(message)
ok[0] = false
@@ -253,18 +260,20 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava<TestModule, Tes
}
override fun unexpectedDiagnostic(diagnostic: CheckerTestUtil.TextDiagnostic, actualStart: Int, actualEnd: Int) {
if (withNewInferenceDirective && diagnostic.inferenceCompatibility != inferenceCompatibilityOfTest) {
updateUncheckedDiagnostics(diagnostic, actualStart, actualEnd)
return
}
val message = "Unexpected ${diagnostic.description}${DiagnosticUtils.atLocation(ktFile, TextRange(actualStart, actualEnd))}"
System.err.println(message)
ok[0] = false
}
override fun uncheckedDiagnostic(diagnostic: CheckerTestUtil.TextDiagnostic, expectedStart: Int, expectedEnd: Int) {
uncheckedDiagnostics.add(PositionalTextDiagnostic(diagnostic, expectedStart, expectedEnd))
fun updateUncheckedDiagnostics(diagnostic: CheckerTestUtil.TextDiagnostic, start: Int, end: Int) {
diagnostic.enhanceInferenceCompatibility(invertedInferenceCompatibilityOfTest)
uncheckedDiagnostics.add(PositionalTextDiagnostic(diagnostic, start, end))
}
override fun shouldUseDiagnosticsForNI(): Boolean = withNewInference
override fun isWithNewInferenceDirective(): Boolean = withNewInferenceDirective
})
actualText.append(CheckerTestUtil.addDiagnosticMarkersToText(
@@ -276,6 +285,13 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava<TestModule, Tes
return ok[0]
}
private fun asInferenceCompatibility(isNewInference: Boolean): CheckerTestUtil.TextDiagnostic.InferenceCompatibility {
return if (isNewInference)
CheckerTestUtil.TextDiagnostic.InferenceCompatibility.NEW
else
CheckerTestUtil.TextDiagnostic.InferenceCompatibility.OLD
}
private fun computeJvmSignatureDiagnostics(bindingContext: BindingContext): Set<ActualDiagnostic> {
val jvmSignatureDiagnostics = HashSet<ActualDiagnostic>()
val declarations = PsiTreeUtil.findChildrenOfType(ktFile, KtDeclaration::class.java)
@@ -105,7 +105,7 @@ public class CheckerTestUtilTest extends KotlinTestWithEnvironment {
DiagnosticData unused = diagnostics.get(2);
String unusedDiagnostic = asTextDiagnostic(unused, "i");
DiagnosedRange range = asDiagnosticRange(unused, unusedDiagnostic);
doTest(new TheTest(wrongParameters(unusedDiagnostic, "UNUSED_VARIABLE(a)", unused.startOffset, unused.endOffset)) {
doTest(new TheTest(wrongParameters(unusedDiagnostic, "OI;UNUSED_VARIABLE(a)", unused.startOffset, unused.endOffset)) {
@Override
protected void makeTestData(List<ActualDiagnostic> diagnostics, List<DiagnosedRange> diagnosedRanges) {
diagnosedRanges.set(unused.rangeIndex, range);
@@ -118,7 +118,7 @@ public class CheckerTestUtilTest extends KotlinTestWithEnvironment {
String unusedDiagnostic = asTextDiagnostic(unresolvedReference, "i");
String toManyArguments = asTextDiagnostic(diagnostics.get(7));
DiagnosedRange range = asDiagnosticRange(unresolvedReference, unusedDiagnostic, toManyArguments);
doTest(new TheTest(wrongParameters(unusedDiagnostic, "UNRESOLVED_REFERENCE(xx)", unresolvedReference.startOffset, unresolvedReference.endOffset)) {
doTest(new TheTest(wrongParameters(unusedDiagnostic, "OI;UNRESOLVED_REFERENCE(xx)", unresolvedReference.startOffset, unresolvedReference.endOffset)) {
@Override
protected void makeTestData(List<ActualDiagnostic> diagnostics, List<DiagnosedRange> diagnosedRanges) {
diagnosedRanges.set(unresolvedReference.rangeIndex, range);
@@ -181,20 +181,6 @@ public class CheckerTestUtilTest extends KotlinTestWithEnvironment {
public void unexpectedDiagnostic(CheckerTestUtil.TextDiagnostic diagnostic, int actualStart, int actualEnd) {
actualMessages.add(unexpected(diagnostic.getDescription(), actualStart, actualEnd));
}
@Override
public void uncheckedDiagnostic(CheckerTestUtil.TextDiagnostic diagnostic, int expectedStart, int expectedEnd) {
}
@Override
public boolean shouldUseDiagnosticsForNI() {
return false;
}
@Override
public boolean isWithNewInferenceDirective() {
return false;
}
});
assertEquals(listToString(expectedMessages), listToString(actualMessages));