[FIR-TEST] Run fir test in diagnostic test if fir testdata is missing
This commit is contained in:
+31
-19
@@ -15,7 +15,10 @@ import org.jetbrains.kotlin.TestsCompilerError
|
||||
import org.jetbrains.kotlin.analyzer.AnalysisResult
|
||||
import org.jetbrains.kotlin.analyzer.common.CommonResolverForModuleFactory
|
||||
import org.jetbrains.kotlin.builtins.jvm.JvmBuiltIns
|
||||
import org.jetbrains.kotlin.cli.common.messages.*
|
||||
import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport
|
||||
import org.jetbrains.kotlin.cli.common.messages.GroupingMessageCollector
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageRenderer
|
||||
import org.jetbrains.kotlin.cli.common.messages.PrintingMessageCollector
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.NoScopeRecordCliBindingTrace
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM
|
||||
import org.jetbrains.kotlin.config.*
|
||||
@@ -33,6 +36,7 @@ import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticFactory
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticUtils
|
||||
import org.jetbrains.kotlin.diagnostics.Errors.*
|
||||
import org.jetbrains.kotlin.fir.AbstractFirOldFrontendDiagnosticsTest
|
||||
import org.jetbrains.kotlin.frontend.java.di.createContainerForLazyResolveWithJava
|
||||
import org.jetbrains.kotlin.frontend.java.di.initJvmBuiltInsForTopDownAnalysis
|
||||
import org.jetbrains.kotlin.incremental.components.ExpectActualTracker
|
||||
@@ -82,6 +86,10 @@ abstract class AbstractDiagnosticsTest : BaseDiagnosticsTest() {
|
||||
}
|
||||
}
|
||||
|
||||
protected open fun shouldValidateFirTestData(testDataFile: File): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
private fun analyzeAndCheckUnhandled(testDataFile: File, files: List<TestFile>) {
|
||||
val groupedByModule = files.groupBy(TestFile::module)
|
||||
|
||||
@@ -242,34 +250,38 @@ abstract class AbstractDiagnosticsTest : BaseDiagnosticsTest() {
|
||||
performAdditionalChecksAfterDiagnostics(
|
||||
testDataFile, files, groupedByModule, modules, moduleBindings, languageVersionSettingsByModule
|
||||
)
|
||||
checkOriginalAndFirTestdataIdentity(testDataFile)
|
||||
}
|
||||
|
||||
private class DiagnosticsFullTextMessageCollector : MessageCollector {
|
||||
|
||||
|
||||
override fun clear() {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation?) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun hasErrors(): Boolean {
|
||||
TODO("Not yet implemented")
|
||||
if (shouldValidateFirTestData(testDataFile)) {
|
||||
checkFirTestdata(testDataFile, files)
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkOriginalAndFirTestdataIdentity(testDataFile: File) {
|
||||
private fun checkFirTestdata(testDataFile: File, files: List<TestFile>) {
|
||||
val firTestDataFile = File(testDataFile.absolutePath.replace(".kt", ".fir.kt"))
|
||||
if (!firTestDataFile.exists()) return
|
||||
val firFailFile = File(testDataFile.absolutePath.replace(".kt", ".fir.fail"))
|
||||
when {
|
||||
firFailFile.exists() -> return
|
||||
firTestDataFile.exists() -> checkOriginalAndFirTestdataIdentity(testDataFile, firTestDataFile)
|
||||
else -> runFirTestAndGenerateTestData(testDataFile, firTestDataFile, files)
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkOriginalAndFirTestdataIdentity(testDataFile: File, firTestDataFile: File) {
|
||||
val originalTestData = loadTestDataWithoutDiagnostics(testDataFile)
|
||||
val firTestData = loadTestDataWithoutDiagnostics(firTestDataFile)
|
||||
val message = "Original and fir test data doesn't identical. Please, add changes from ${testDataFile.name} to ${firTestDataFile.name}"
|
||||
TestCase.assertEquals(message, originalTestData, firTestData)
|
||||
}
|
||||
|
||||
private fun runFirTestAndGenerateTestData(testDataFile: File, firTestDataFile: File, files: List<TestFile>) {
|
||||
val testRunner = object : AbstractFirOldFrontendDiagnosticsTest() {
|
||||
init {
|
||||
environment = this@AbstractDiagnosticsTest.environment
|
||||
}
|
||||
}
|
||||
FileUtil.copy(testDataFile, firTestDataFile)
|
||||
testRunner.analyzeAndCheckUnhandled(firTestDataFile, files)
|
||||
}
|
||||
|
||||
private fun StringBuilder.cleanupInferenceDiagnostics(): String = replace(Regex("NI;([\\S]*), OI;\\1([,!])")) { it.groupValues[1] + it.groupValues[2] }
|
||||
|
||||
protected open fun getExpectedDiagnosticsFile(testDataFile: File): File {
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* 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
|
||||
|
||||
import java.io.File
|
||||
|
||||
abstract class AbstractDiagnosticsTestWithFirValidation : AbstractDiagnosticsTest() {
|
||||
override fun shouldValidateFirTestData(testDataFile: File): Boolean {
|
||||
val path = testDataFile.absolutePath
|
||||
return !path.endsWith(".kts") && !path.contains("codegen")
|
||||
}
|
||||
}
|
||||
-17
@@ -1,17 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* 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;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.test.ConfigurationKind;
|
||||
|
||||
public abstract class AbstractDiagnosticsTestWithStdLib extends AbstractDiagnosticsTest {
|
||||
@NotNull
|
||||
@Override
|
||||
protected ConfigurationKind getConfigurationKind() {
|
||||
return ConfigurationKind.NO_KOTLIN_REFLECT;
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* 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
|
||||
|
||||
import org.jetbrains.kotlin.test.ConfigurationKind
|
||||
import java.io.File
|
||||
|
||||
abstract class AbstractDiagnosticsTestWithStdLib : AbstractDiagnosticsTest() {
|
||||
override fun getConfigurationKind(): ConfigurationKind {
|
||||
return ConfigurationKind.NO_KOTLIN_REFLECT
|
||||
}
|
||||
|
||||
override fun shouldValidateFirTestData(testDataFile: File): Boolean {
|
||||
val path = testDataFile.absolutePath
|
||||
return !path.endsWith(".kts") && !path.contains("coroutines")
|
||||
}
|
||||
}
|
||||
+253
-253
File diff suppressed because it is too large
Load Diff
@@ -65,7 +65,7 @@ fun main(args: Array<String>) {
|
||||
val excludedFirTestdataPattern = "^(.+)\\.fir\\.kts?\$"
|
||||
|
||||
testGroup("compiler/tests", "compiler/testData") {
|
||||
testClass<AbstractDiagnosticsTest> {
|
||||
testClass<AbstractDiagnosticsTestWithFirValidation>(suiteTestClassName = "DiagnosticsTestGenerated") {
|
||||
model("diagnostics/tests", pattern = "^(.*)\\.kts?$", excludedPattern = excludedFirTestdataPattern)
|
||||
model("codegen/box/diagnostics")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user