Add ability to reuse one diagnostic test file for old and new inference
This commit is contained in:
+9
-5
@@ -140,13 +140,17 @@ abstract class AbstractDiagnosticsTest : BaseDiagnosticsTest() {
|
||||
}
|
||||
|
||||
var exceptionFromDescriptorValidation: Throwable? = null
|
||||
val originalTestFile = testDataFile.readText()
|
||||
try {
|
||||
val expectedFile = if (InTextDirectivesUtils.isDirectiveDefined(testDataFile.readText(), "// JAVAC_EXPECTED_FILE")
|
||||
&& environment.configuration.getBoolean(JVMConfigurationKeys.USE_JAVAC)) {
|
||||
File(FileUtil.getNameWithoutExtension(testDataFile.absolutePath) + ".javac.txt")
|
||||
} else {
|
||||
File(FileUtil.getNameWithoutExtension(testDataFile.absolutePath) + ".txt")
|
||||
val isJavacExpectedFile = InTextDirectivesUtils.isDirectiveDefined(originalTestFile, "// JAVAC_EXPECTED_FILE")
|
||||
&& environment.configuration.getBoolean(JVMConfigurationKeys.USE_JAVAC)
|
||||
|
||||
val postfix = when {
|
||||
isJavacExpectedFile -> ".javac.txt"
|
||||
files.all { it.withNewInferenceDirective && it.newInferenceEnabled } -> ".ni.txt"
|
||||
else -> ".txt"
|
||||
}
|
||||
val expectedFile = File(FileUtil.getNameWithoutExtension(testDataFile.absolutePath) + postfix)
|
||||
validateAndCompareDescriptorWithFile(expectedFile, files, modules)
|
||||
}
|
||||
catch (e: Throwable) {
|
||||
|
||||
@@ -130,6 +130,8 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava<TestModule, Tes
|
||||
val checkLazyLog: Boolean
|
||||
private val markDynamicCalls: Boolean
|
||||
val dynamicCallDescriptors: List<DeclarationDescriptor> = ArrayList()
|
||||
val withNewInferenceDirective: Boolean
|
||||
val newInferenceEnabled: Boolean
|
||||
|
||||
init {
|
||||
this.declareCheckType = CHECK_TYPE_DIRECTIVE in directives
|
||||
@@ -138,6 +140,8 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava<TestModule, Tes
|
||||
this.checkLazyLog = CHECK_LAZY_LOG_DIRECTIVE in directives || CHECK_LAZY_LOG_DEFAULT
|
||||
this.declareFlexibleType = EXPLICIT_FLEXIBLE_TYPES_DIRECTIVE in directives
|
||||
this.markDynamicCalls = MARK_DYNAMIC_CALLS_DIRECTIVE in directives
|
||||
this.withNewInferenceDirective = WITH_NEW_INFERENCE_DIRECTIVE in directives
|
||||
this.newInferenceEnabled = (customLanguageVersionSettings ?: LanguageVersionSettingsImpl.DEFAULT).supportsFeature(LanguageFeature.NewInference)
|
||||
if (fileName.endsWith(".java")) {
|
||||
// TODO: check there are no syntax errors in .java sources
|
||||
this.createKtFile = lazyOf(null)
|
||||
@@ -213,13 +217,16 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava<TestModule, Tes
|
||||
computeJvmSignatureDiagnostics(bindingContext)
|
||||
|
||||
val ok = booleanArrayOf(true)
|
||||
val withNewInference = newInferenceEnabled && withNewInferenceDirective
|
||||
val diagnostics = ContainerUtil.filter(
|
||||
CheckerTestUtil.getDiagnosticsIncludingSyntaxErrors(
|
||||
bindingContext, implementingModulesBindings, ktFile, markDynamicCalls, dynamicCallDescriptors
|
||||
bindingContext, implementingModulesBindings, ktFile, markDynamicCalls, dynamicCallDescriptors, withNewInference
|
||||
) + jvmSignatureDiagnostics,
|
||||
{ whatDiagnosticsToConsider.value(it.diagnostic) }
|
||||
)
|
||||
|
||||
val uncheckedDiagnostics = mutableListOf<PositionalTextDiagnostic>()
|
||||
|
||||
val diagnosticToExpectedDiagnostic = CheckerTestUtil.diagnosticsDiff(diagnosedRanges, diagnostics, object : CheckerTestUtil.DiagnosticDiffCallbacks {
|
||||
override fun missingDiagnostic(diagnostic: CheckerTestUtil.TextDiagnostic, expectedStart: Int, expectedEnd: Int) {
|
||||
val message = "Missing " + diagnostic.description + DiagnosticUtils.atLocation(ktFile, TextRange(expectedStart, expectedEnd))
|
||||
@@ -245,10 +252,18 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava<TestModule, Tes
|
||||
System.err.println(message)
|
||||
ok[0] = false
|
||||
}
|
||||
|
||||
override fun uncheckedDiagnostic(diagnostic: CheckerTestUtil.TextDiagnostic, expectedStart: Int, expectedEnd: Int) {
|
||||
uncheckedDiagnostics.add(PositionalTextDiagnostic(diagnostic, expectedStart, expectedEnd))
|
||||
}
|
||||
|
||||
override fun shouldUseDiagnosticsForNI(): Boolean = withNewInference
|
||||
|
||||
override fun isWithNewInferenceDirective(): Boolean = withNewInferenceDirective
|
||||
})
|
||||
|
||||
actualText.append(
|
||||
CheckerTestUtil.addDiagnosticMarkersToText(ktFile, diagnostics, diagnosticToExpectedDiagnostic, { file -> file.text })
|
||||
actualText.append(CheckerTestUtil.addDiagnosticMarkersToText(
|
||||
ktFile, diagnostics, diagnosticToExpectedDiagnostic, { file -> file.text }, uncheckedDiagnostics, withNewInferenceDirective)
|
||||
)
|
||||
|
||||
stripExtras(actualText)
|
||||
@@ -262,7 +277,8 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava<TestModule, Tes
|
||||
for (declaration in declarations) {
|
||||
val diagnostics = getJvmSignatureDiagnostics(declaration, bindingContext.diagnostics,
|
||||
GlobalSearchScope.allScope(project)) ?: continue
|
||||
jvmSignatureDiagnostics.addAll(diagnostics.forElement(declaration).map { ActualDiagnostic(it, null) })
|
||||
val withNewInference = (customLanguageVersionSettings ?: LanguageVersionSettingsImpl.DEFAULT).supportsFeature(LanguageFeature.NewInference)
|
||||
jvmSignatureDiagnostics.addAll(diagnostics.forElement(declaration).map { ActualDiagnostic(it, null, withNewInference) })
|
||||
}
|
||||
return jvmSignatureDiagnostics
|
||||
}
|
||||
@@ -306,6 +322,8 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava<TestModule, Tes
|
||||
|
||||
val MARK_DYNAMIC_CALLS_DIRECTIVE = "MARK_DYNAMIC_CALLS"
|
||||
|
||||
val WITH_NEW_INFERENCE_DIRECTIVE = "WITH_NEW_INFERENCE"
|
||||
|
||||
private fun parseDiagnosticFilterDirective(directiveMap: Map<String, String>, allowUnderscoreUsage: Boolean): Condition<Diagnostic> {
|
||||
val directives = directiveMap[DIAGNOSTICS_DIRECTIVE]
|
||||
val initialCondition =
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -79,7 +79,7 @@ import java.util.regex.Pattern;
|
||||
import static org.jetbrains.kotlin.checkers.CompilerTestLanguageVersionSettingsKt.parseLanguageVersionSettings;
|
||||
import static org.jetbrains.kotlin.cli.common.output.outputUtils.OutputUtilsKt.writeAllTo;
|
||||
import static org.jetbrains.kotlin.codegen.CodegenTestUtil.*;
|
||||
import static org.jetbrains.kotlin.codegen.TestUtilsKt.*;
|
||||
import static org.jetbrains.kotlin.codegen.TestUtilsKt.extractUrls;
|
||||
import static org.jetbrains.kotlin.test.KotlinTestUtils.getAnnotationsJar;
|
||||
import static org.jetbrains.kotlin.test.clientserver.TestProcessServerKt.getBoxMethodOrNull;
|
||||
import static org.jetbrains.kotlin.test.clientserver.TestProcessServerKt.getGeneratedClass;
|
||||
|
||||
Reference in New Issue
Block a user