diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/HandlerUtils.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/HandlerUtils.kt index da741fd0140..e5820a14ed1 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/HandlerUtils.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/HandlerUtils.kt @@ -23,6 +23,7 @@ import org.jetbrains.kotlin.test.frontend.fir.handlers.toMetaInfos import org.jetbrains.kotlin.test.model.BinaryArtifactHandler import org.jetbrains.kotlin.test.model.TestModule import org.jetbrains.kotlin.test.services.* +import org.jetbrains.kotlin.test.utils.MultiModuleInfoDumper import org.jetbrains.kotlin.util.capitalizeDecapitalize.toLowerCaseAsciiOnly import java.io.File @@ -55,35 +56,45 @@ fun BinaryArtifactHandler<*>.reportKtDiagnostics(module: TestModule, ktDiagnosti processModule(module) } -fun BinaryArtifactHandler<*>.checkFullDiagnosticRender(module: TestModule) { - if (DiagnosticsDirectives.RENDER_ALL_DIAGNOSTICS_FULL_TEXT !in module.directives) return - - val reportedDiagnostics = mutableListOf() - for (testFile in module.files) { - val finder = - SequentialPositionFinder(testServices.sourceFileProvider.getContentOfSourceFile(testFile).byteInputStream().reader()) - for (metaInfo in testServices.globalMetadataInfoHandler.getReportedMetaInfosForFile(testFile).sortedBy { it.start }) { - when (metaInfo) { - is DiagnosticCodeMetaInfo -> metaInfo.diagnostic.let { - val message = DefaultErrorMessages.render(it) - val position = DiagnosticUtils.getLineAndColumnRange(it.psiFile, it.textRanges).start - reportedDiagnostics += - renderDiagnosticMessage(it.psiFile.name, it.severity, message, position.line, position.column) - } - is FirDiagnosticCodeMetaInfo -> metaInfo.diagnostic.let { - val message = RootDiagnosticRendererFactory(it).render(it) - val position = finder.findNextPosition(DiagnosticUtils.firstRange(it.textRanges).startOffset, false) - reportedDiagnostics += - renderDiagnosticMessage(testFile.relativePath, it.severity, message, position.line, position.column) +fun BinaryArtifactHandler<*>.checkFullDiagnosticRender() { + val dumper = MultiModuleInfoDumper() + val moduleStructure = testServices.moduleStructure + var needToVerifyDiagnostics = false + for (module in moduleStructure.modules) { + if (DiagnosticsDirectives.RENDER_ALL_DIAGNOSTICS_FULL_TEXT !in module.directives) continue + needToVerifyDiagnostics = true + val reportedDiagnostics = mutableListOf() + for (testFile in module.files) { + val finder = + SequentialPositionFinder(testServices.sourceFileProvider.getContentOfSourceFile(testFile).byteInputStream().reader()) + for (metaInfo in testServices.globalMetadataInfoHandler.getReportedMetaInfosForFile(testFile).sortedBy { it.start }) { + when (metaInfo) { + is DiagnosticCodeMetaInfo -> metaInfo.diagnostic.let { + val message = DefaultErrorMessages.render(it) + val position = DiagnosticUtils.getLineAndColumnRange(it.psiFile, it.textRanges).start + reportedDiagnostics += + renderDiagnosticMessage(it.psiFile.name, it.severity, message, position.line, position.column) + } + is FirDiagnosticCodeMetaInfo -> metaInfo.diagnostic.let { + val message = RootDiagnosticRendererFactory(it).render(it) + val position = finder.findNextPosition(DiagnosticUtils.firstRange(it.textRanges).startOffset, false) + reportedDiagnostics += + renderDiagnosticMessage(testFile.relativePath, it.severity, message, position.line, position.column) + } } } } + if (reportedDiagnostics.isNotEmpty()) { + reportedDiagnostics.joinTo(dumper.builderForModule(module), separator = "\n\n", postfix = "\n") + } } - testServices.assertions.assertEqualsToFile( - File(FileUtil.getNameWithoutExtension(module.files.first().originalFile.absolutePath) + ".diag.txt"), - reportedDiagnostics.joinToString(separator = "\n\n", postfix = "\n") - ) + if (needToVerifyDiagnostics) { + testServices.assertions.assertEqualsToFile( + File(FileUtil.getNameWithoutExtension(moduleStructure.originalTestDataFiles.first().absolutePath) + ".diag.txt"), + dumper.generateResultingDump() + ) + } } private fun renderDiagnosticMessage(fileName: String, severity: Severity, message: String?, line: Int, column: Int): String { diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/JvmBackendDiagnosticsHandler.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/JvmBackendDiagnosticsHandler.kt index 5654156a94c..b39fa5c9d59 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/JvmBackendDiagnosticsHandler.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/JvmBackendDiagnosticsHandler.kt @@ -23,10 +23,11 @@ class JvmBackendDiagnosticsHandler(testServices: TestServices) : JvmBinaryArtifa override fun processModule(module: TestModule, info: BinaryArtifacts.Jvm) { reportDiagnostics(module, info) reportKtDiagnostics(module, info) - checkFullDiagnosticRender(module) } - override fun processAfterAllModules(someAssertionWasFailed: Boolean) {} + override fun processAfterAllModules(someAssertionWasFailed: Boolean) { + checkFullDiagnosticRender() + } private fun reportDiagnostics(module: TestModule, info: BinaryArtifacts.Jvm) { val testFiles = module.files.associateBy { "/${it.name}" } diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/handlers/JsBackendDiagnosticsHandler.kt b/js/js.tests/test/org/jetbrains/kotlin/js/test/handlers/JsBackendDiagnosticsHandler.kt index b5cd9fbadc4..262f687c440 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/handlers/JsBackendDiagnosticsHandler.kt +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/handlers/JsBackendDiagnosticsHandler.kt @@ -15,8 +15,9 @@ import org.jetbrains.kotlin.test.services.* class JsBackendDiagnosticsHandler(testServices: TestServices) : KlibArtifactHandler(testServices) { override fun processModule(module: TestModule, info: BinaryArtifacts.KLib) { reportKtDiagnostics(module, info.reporter) - checkFullDiagnosticRender(module) } - override fun processAfterAllModules(someAssertionWasFailed: Boolean) {} + override fun processAfterAllModules(someAssertionWasFailed: Boolean) { + checkFullDiagnosticRender() + } }