[FIR] Add the new test set to render diagnostics from IR const evaluator
This commit is contained in:
-6
@@ -25,12 +25,6 @@ public class DiagnosticsTestWithJvmIrBackendGenerated extends AbstractDiagnostic
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithJvmBackend"), Pattern.compile("^(.+)\\.kts?$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), TargetBackend.JVM_IR, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("exceptionFromInterpreter.kt")
|
||||
public void testExceptionFromInterpreter() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithJvmBackend/exceptionFromInterpreter.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("indirectInlineCycle.kt")
|
||||
public void testIndirectInlineCycle() throws Exception {
|
||||
|
||||
+8
-1
@@ -7,8 +7,10 @@ package org.jetbrains.kotlin.test.backend.ir
|
||||
|
||||
import org.jetbrains.kotlin.test.FirParser
|
||||
import org.jetbrains.kotlin.test.backend.handlers.AbstractIrHandler
|
||||
import org.jetbrains.kotlin.test.directives.DiagnosticsDirectives
|
||||
import org.jetbrains.kotlin.test.directives.FirDiagnosticsDirectives
|
||||
import org.jetbrains.kotlin.test.directives.model.singleOrZeroValue
|
||||
import org.jetbrains.kotlin.test.frontend.fir.handlers.FullDiagnosticsRenderer
|
||||
import org.jetbrains.kotlin.test.frontend.fir.handlers.diagnosticCodeMetaInfos
|
||||
import org.jetbrains.kotlin.test.model.TestModule
|
||||
import org.jetbrains.kotlin.test.services.*
|
||||
@@ -20,6 +22,8 @@ class IrDiagnosticsHandler(testServices: TestServices) : AbstractIrHandler(testS
|
||||
private val diagnosticsService: DiagnosticsService
|
||||
get() = testServices.diagnosticsService
|
||||
|
||||
private val fullDiagnosticsRenderer = FullDiagnosticsRenderer(DiagnosticsDirectives.RENDER_IR_DIAGNOSTICS_FULL_TEXT)
|
||||
|
||||
override fun processModule(module: TestModule, info: IrBackendInput) {
|
||||
val diagnosticsByFilePath = info.diagnosticReporter.diagnosticsByFilePath
|
||||
for (currentModule in testServices.moduleStructure.modules) {
|
||||
@@ -34,10 +38,13 @@ class IrDiagnosticsHandler(testServices: TestServices) : AbstractIrHandler(testS
|
||||
lightTreeEnabled, lightTreeComparingModeEnabled
|
||||
)
|
||||
globalMetadataInfoHandler.addMetadataInfosForFile(file, diagnosticsMetadataInfos)
|
||||
fullDiagnosticsRenderer.storeFullDiagnosticRender(module, diagnostics, file)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun processAfterAllModules(someAssertionWasFailed: Boolean) {}
|
||||
override fun processAfterAllModules(someAssertionWasFailed: Boolean) {
|
||||
fullDiagnosticsRenderer.assertCollectedDiagnostics(testServices, ".fir.ir.diag.txt")
|
||||
}
|
||||
}
|
||||
+4
@@ -92,4 +92,8 @@ object DiagnosticsDirectives : SimpleDirectivesContainer() {
|
||||
val RENDER_ALL_DIAGNOSTICS_FULL_TEXT by directive(
|
||||
description = "Render both frontend and backend diagnostic texts to .diag.txt"
|
||||
)
|
||||
|
||||
val RENDER_IR_DIAGNOSTICS_FULL_TEXT by directive(
|
||||
description = "Render IR diagnostic texts to .ir.diag.txt"
|
||||
)
|
||||
}
|
||||
|
||||
+29
-20
@@ -44,6 +44,7 @@ import org.jetbrains.kotlin.test.directives.DiagnosticsDirectives
|
||||
import org.jetbrains.kotlin.test.directives.FirDiagnosticsDirectives
|
||||
import org.jetbrains.kotlin.test.directives.LanguageSettingsDirectives
|
||||
import org.jetbrains.kotlin.test.directives.model.DirectivesContainer
|
||||
import org.jetbrains.kotlin.test.directives.model.SimpleDirective
|
||||
import org.jetbrains.kotlin.test.directives.model.singleValue
|
||||
import org.jetbrains.kotlin.test.frontend.fir.FirOutputArtifact
|
||||
import org.jetbrains.kotlin.test.model.TestFile
|
||||
@@ -55,6 +56,31 @@ import org.jetbrains.kotlin.test.utils.MultiModuleInfoDumper
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
import org.jetbrains.kotlin.util.capitalizeDecapitalize.toLowerCaseAsciiOnly
|
||||
|
||||
class FullDiagnosticsRenderer(private val directive: SimpleDirective) {
|
||||
private val dumper: MultiModuleInfoDumper = MultiModuleInfoDumper(moduleHeaderTemplate = "// -- Module: <%s> --")
|
||||
|
||||
fun assertCollectedDiagnostics(testServices: TestServices, expectedExtension: String) {
|
||||
if (dumper.isEmpty()) return
|
||||
val resultDump = dumper.generateResultingDump()
|
||||
val testDataFile = testServices.moduleStructure.originalTestDataFiles.first()
|
||||
val expectedFile = testDataFile.parentFile.resolve("${testDataFile.nameWithoutExtension.removeSuffix(".fir")}$expectedExtension")
|
||||
testServices.assertions.assertEqualsToFile(expectedFile, resultDump)
|
||||
}
|
||||
|
||||
fun storeFullDiagnosticRender(module: TestModule, diagnostics: List<KtDiagnostic>, file: TestFile) {
|
||||
if (directive !in module.directives) return
|
||||
if (diagnostics.isEmpty()) return
|
||||
|
||||
val reportedDiagnostics = diagnostics.sortedBy { it.textRanges.first().startOffset }.map {
|
||||
val severity = AnalyzerWithCompilerReport.convertSeverity(it.severity).toString().toLowerCaseAsciiOnly()
|
||||
val message = RootDiagnosticRendererFactory(it).render(it)
|
||||
"/${file.name}:${it.textRanges.first()}: $severity: $message"
|
||||
}
|
||||
|
||||
dumper.builderForModule(module).appendLine(reportedDiagnostics.joinToString(separator = "\n\n"))
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(SymbolInternals::class)
|
||||
class FirDiagnosticsHandler(testServices: TestServices) : FirAnalysisHandler(testServices) {
|
||||
private val globalMetadataInfoHandler: GlobalMetadataInfoHandler
|
||||
@@ -69,14 +95,10 @@ class FirDiagnosticsHandler(testServices: TestServices) : FirAnalysisHandler(tes
|
||||
override val additionalServices: List<ServiceRegistrationData> =
|
||||
listOf(service(::DiagnosticsService))
|
||||
|
||||
private val dumper: MultiModuleInfoDumper = MultiModuleInfoDumper(moduleHeaderTemplate = "// -- Module: <%s> --")
|
||||
private val fullDiagnosticsRenderer = FullDiagnosticsRenderer(DiagnosticsDirectives.RENDER_DIAGNOSTICS_FULL_TEXT)
|
||||
|
||||
override fun processAfterAllModules(someAssertionWasFailed: Boolean) {
|
||||
if (dumper.isEmpty()) return
|
||||
val resultDump = dumper.generateResultingDump()
|
||||
val testDataFile = testServices.moduleStructure.originalTestDataFiles.first()
|
||||
val expectedFile = testDataFile.parentFile.resolve("${testDataFile.nameWithoutFirExtension}.fir.diag.txt")
|
||||
assertions.assertEqualsToFile(expectedFile, resultDump)
|
||||
fullDiagnosticsRenderer.assertCollectedDiagnostics(testServices, ".fir.diag.txt")
|
||||
}
|
||||
|
||||
override fun processModule(module: TestModule, info: FirOutputArtifact) {
|
||||
@@ -109,7 +131,7 @@ class FirDiagnosticsHandler(testServices: TestServices) : FirAnalysisHandler(tes
|
||||
globalMetadataInfoHandler.addMetadataInfosForFile(file, diagnosticsMetadataInfos)
|
||||
collectSyntaxDiagnostics(currentModule, file, firFile, lightTreeEnabled, lightTreeComparingModeEnabled, forceRenderArguments)
|
||||
collectDebugInfoDiagnostics(currentModule, file, firFile, lightTreeEnabled, lightTreeComparingModeEnabled)
|
||||
checkFullDiagnosticRender(module, diagnostics, file)
|
||||
fullDiagnosticsRenderer.storeFullDiagnosticRender(module, diagnostics, file)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -340,19 +362,6 @@ class FirDiagnosticsHandler(testServices: TestServices) : FirAnalysisHandler(tes
|
||||
is FirCallableSymbol<*> -> callableId.asFqNameForDebugInfo().toUnsafe()
|
||||
else -> null
|
||||
}
|
||||
|
||||
private fun checkFullDiagnosticRender(module: TestModule, diagnostics: List<KtDiagnostic>, file: TestFile) {
|
||||
if (DiagnosticsDirectives.RENDER_DIAGNOSTICS_FULL_TEXT !in module.directives) return
|
||||
if (diagnostics.isEmpty()) return
|
||||
|
||||
val reportedDiagnostics = diagnostics.sortedBy { it.textRanges.first().startOffset }.map {
|
||||
val severity = AnalyzerWithCompilerReport.convertSeverity(it.severity).toString().toLowerCaseAsciiOnly()
|
||||
val message = RootDiagnosticRendererFactory(it).render(it)
|
||||
"/${file.name}:${it.textRanges.first()}: $severity: $message"
|
||||
}
|
||||
|
||||
dumper.builderForModule(module).appendLine(reportedDiagnostics.joinToString(separator = "\n\n"))
|
||||
}
|
||||
}
|
||||
|
||||
fun List<KtDiagnostic>.diagnosticCodeMetaInfos(
|
||||
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2010-2023 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.test.runners.ir
|
||||
|
||||
import org.jetbrains.kotlin.test.FirParser
|
||||
import org.jetbrains.kotlin.test.TargetBackend
|
||||
import org.jetbrains.kotlin.test.backend.ir.IrDiagnosticsHandler
|
||||
import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder
|
||||
import org.jetbrains.kotlin.test.builders.irHandlersStep
|
||||
import org.jetbrains.kotlin.test.directives.configureFirParser
|
||||
import org.jetbrains.kotlin.test.frontend.fir.Fir2IrResultsConverter
|
||||
import org.jetbrains.kotlin.test.runners.AbstractKotlinCompilerWithTargetBackendTest
|
||||
import org.jetbrains.kotlin.test.runners.baseFirDiagnosticTestConfiguration
|
||||
|
||||
abstract class AbstractFirWithInterpreterDiagnosticsTest(val parser: FirParser) : AbstractKotlinCompilerWithTargetBackendTest(TargetBackend.JVM_IR) {
|
||||
override fun TestConfigurationBuilder.configuration() {
|
||||
configureFirParser(parser)
|
||||
baseFirDiagnosticTestConfiguration()
|
||||
|
||||
facadeStep(::Fir2IrResultsConverter)
|
||||
irHandlersStep {
|
||||
useHandlers(
|
||||
::IrDiagnosticsHandler
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
open class AbstractFirPsiWithInterpreterDiagnosticsTest : AbstractFirWithInterpreterDiagnosticsTest(FirParser.Psi)
|
||||
|
||||
open class AbstractFirLightTreeWithInterpreterDiagnosticsTest : AbstractFirWithInterpreterDiagnosticsTest(FirParser.LightTree)
|
||||
Reference in New Issue
Block a user