[Infrastructure] Assert dumps don't exist without directive
#KT-58697 Fixed
This commit is contained in:
committed by
Space Team
parent
42f6eb4eb4
commit
5e83350576
+7
-3
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.test.backend.handlers
|
||||
|
||||
import org.jetbrains.kotlin.codegen.DefaultParameterValueSubstitutor
|
||||
import org.jetbrains.kotlin.codegen.getClassFiles
|
||||
import org.jetbrains.kotlin.test.Assertions
|
||||
import org.jetbrains.kotlin.test.directives.AsmLikeInstructionListingDirectives
|
||||
import org.jetbrains.kotlin.test.directives.AsmLikeInstructionListingDirectives.CHECK_ASM_LIKE_INSTRUCTIONS
|
||||
import org.jetbrains.kotlin.test.directives.AsmLikeInstructionListingDirectives.CURIOUS_ABOUT
|
||||
@@ -387,8 +388,6 @@ class AsmLikeInstructionListingHandler(testServices: TestServices) : JvmBinaryAr
|
||||
}
|
||||
|
||||
override fun processAfterAllModules(someAssertionWasFailed: Boolean) {
|
||||
if (baseDumper.isEmpty()) return
|
||||
|
||||
val irDifference = IR_DIFFERENCE in testServices.moduleStructure.allDirectives
|
||||
val firDifference = FIR_DIFFERENCE in testServices.moduleStructure.allDirectives
|
||||
val inlineScopesDifference = INLINE_SCOPES_DIFFERENCE in testServices.moduleStructure.allDirectives
|
||||
@@ -409,8 +408,13 @@ class AsmLikeInstructionListingHandler(testServices: TestServices) : JvmBinaryAr
|
||||
|
||||
val testDataFile = testServices.moduleStructure.originalTestDataFiles.first()
|
||||
val file = testDataFile.withExtension(extension)
|
||||
assertions.assertEqualsToFile(file, baseDumper.generateResultingDump())
|
||||
|
||||
if (baseDumper.isEmpty()) {
|
||||
assertions.assertFileDoesntExist(file, CHECK_ASM_LIKE_INSTRUCTIONS)
|
||||
return
|
||||
}
|
||||
|
||||
assertions.assertEqualsToFile(file, baseDumper.generateResultingDump())
|
||||
|
||||
val noIrDump = testDataFile.withExtension(DUMP_EXTENSION)
|
||||
val irDump = testDataFile.withExtension(IR_DUMP_EXTENSION)
|
||||
|
||||
+17
-5
@@ -9,9 +9,10 @@ import org.jetbrains.kotlin.codegen.BytecodeListingTextCollectingVisitor
|
||||
import org.jetbrains.kotlin.test.directives.CodegenTestDirectives
|
||||
import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.CHECK_BYTECODE_LISTING
|
||||
import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.DONT_SORT_DECLARATIONS
|
||||
import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.DUMP_IR
|
||||
import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.IGNORE_ANNOTATIONS
|
||||
import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.WITH_SIGNATURES
|
||||
import org.jetbrains.kotlin.test.directives.FirDiagnosticsDirectives.FIR_IDENTICAL
|
||||
import org.jetbrains.kotlin.test.directives.FirDiagnosticsDirectives.FIR_DUMP
|
||||
import org.jetbrains.kotlin.test.directives.model.DirectivesContainer
|
||||
import org.jetbrains.kotlin.test.model.BinaryArtifacts
|
||||
import org.jetbrains.kotlin.test.model.FrontendKinds
|
||||
@@ -21,8 +22,6 @@ import org.jetbrains.kotlin.test.services.defaultsProvider
|
||||
import org.jetbrains.kotlin.test.services.moduleStructure
|
||||
import org.jetbrains.kotlin.test.utils.MultiModuleInfoDumper
|
||||
import org.jetbrains.kotlin.test.utils.withExtension
|
||||
import org.jetbrains.kotlin.test.utils.withSuffixAndExtension
|
||||
import java.io.File
|
||||
|
||||
class BytecodeListingHandler(testServices: TestServices) : JvmBinaryArtifactHandler(testServices) {
|
||||
override val directiveContainers: List<DirectivesContainer>
|
||||
@@ -30,7 +29,12 @@ class BytecodeListingHandler(testServices: TestServices) : JvmBinaryArtifactHand
|
||||
|
||||
private val multiModuleInfoDumper = MultiModuleInfoDumper()
|
||||
|
||||
private var irDumpEnabled = false
|
||||
private var firDumpEnabled = false
|
||||
|
||||
override fun processModule(module: TestModule, info: BinaryArtifacts.Jvm) {
|
||||
irDumpEnabled = irDumpEnabled || DUMP_IR in module.directives
|
||||
firDumpEnabled = firDumpEnabled || FIR_DUMP in module.directives
|
||||
if (CHECK_BYTECODE_LISTING !in module.directives) return
|
||||
val dump = BytecodeListingTextCollectingVisitor.getText(
|
||||
info.classFileFactory,
|
||||
@@ -43,8 +47,6 @@ class BytecodeListingHandler(testServices: TestServices) : JvmBinaryArtifactHand
|
||||
}
|
||||
|
||||
override fun processAfterAllModules(someAssertionWasFailed: Boolean) {
|
||||
if (multiModuleInfoDumper.isEmpty()) return
|
||||
|
||||
val sourceFile = testServices.moduleStructure.originalTestDataFiles.first()
|
||||
val defaultTxtFile = sourceFile.withExtension(".txt")
|
||||
val irTxtFile = sourceFile.withExtension(".ir.txt")
|
||||
@@ -64,6 +66,16 @@ class BytecodeListingHandler(testServices: TestServices) : JvmBinaryArtifactHand
|
||||
else -> defaultTxtFile
|
||||
}
|
||||
|
||||
if (multiModuleInfoDumper.isEmpty()) {
|
||||
if (!irDumpEnabled && actualFile == irTxtFile ||
|
||||
!firDumpEnabled && actualFile == firTxtFile ||
|
||||
actualFile == defaultTxtFile
|
||||
) {
|
||||
assertions.assertFileDoesntExist(actualFile, CHECK_BYTECODE_LISTING)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
assertions.assertEqualsToFile(actualFile, multiModuleInfoDumper.generateResultingDump())
|
||||
|
||||
if (actualFile != goldenFile) {
|
||||
|
||||
+12
-3
@@ -14,9 +14,11 @@ import org.jetbrains.kotlin.diagnostics.Severity
|
||||
import org.jetbrains.kotlin.diagnostics.impl.BaseDiagnosticsCollector
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.RootDiagnosticRendererFactory
|
||||
import org.jetbrains.kotlin.test.Assertions
|
||||
import org.jetbrains.kotlin.test.FirParser
|
||||
import org.jetbrains.kotlin.test.directives.DiagnosticsDirectives
|
||||
import org.jetbrains.kotlin.test.directives.DiagnosticsDirectives.RENDER_ALL_DIAGNOSTICS_FULL_TEXT
|
||||
import org.jetbrains.kotlin.test.directives.FirDiagnosticsDirectives
|
||||
import org.jetbrains.kotlin.test.directives.model.Directive
|
||||
import org.jetbrains.kotlin.test.directives.model.singleOrZeroValue
|
||||
import org.jetbrains.kotlin.test.frontend.fir.handlers.FirDiagnosticCodeMetaInfo
|
||||
import org.jetbrains.kotlin.test.frontend.fir.handlers.toMetaInfos
|
||||
@@ -61,7 +63,7 @@ fun BinaryArtifactHandler<*>.checkFullDiagnosticRender() {
|
||||
val moduleStructure = testServices.moduleStructure
|
||||
var needToVerifyDiagnostics = false
|
||||
for (module in moduleStructure.modules) {
|
||||
if (DiagnosticsDirectives.RENDER_ALL_DIAGNOSTICS_FULL_TEXT !in module.directives) continue
|
||||
if (RENDER_ALL_DIAGNOSTICS_FULL_TEXT !in module.directives) continue
|
||||
needToVerifyDiagnostics = true
|
||||
val reportedDiagnostics = mutableListOf<String>()
|
||||
for (testFile in module.files) {
|
||||
@@ -89,11 +91,14 @@ fun BinaryArtifactHandler<*>.checkFullDiagnosticRender() {
|
||||
}
|
||||
}
|
||||
|
||||
val expectedFile = File(FileUtil.getNameWithoutExtension(moduleStructure.originalTestDataFiles.first().absolutePath) + ".diag.txt")
|
||||
if (needToVerifyDiagnostics) {
|
||||
testServices.assertions.assertEqualsToFile(
|
||||
File(FileUtil.getNameWithoutExtension(moduleStructure.originalTestDataFiles.first().absolutePath) + ".diag.txt"),
|
||||
expectedFile,
|
||||
dumper.generateResultingDump()
|
||||
)
|
||||
} else {
|
||||
testServices.assertions.assertFileDoesntExist(expectedFile, RENDER_ALL_DIAGNOSTICS_FULL_TEXT)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,3 +106,7 @@ private fun renderDiagnosticMessage(fileName: String, severity: Severity, messag
|
||||
val severityString = AnalyzerWithCompilerReport.convertSeverity(severity).toString().toLowerCaseAsciiOnly()
|
||||
return "/${fileName}:$line:$column: $severityString: $message"
|
||||
}
|
||||
|
||||
fun Assertions.assertFileDoesntExist(file: File, directive: Directive) {
|
||||
assertFileDoesntExist(file) { "Dump file detected but no '$directive' directive specified or nothing to dump." }
|
||||
}
|
||||
+4
-1
@@ -186,7 +186,10 @@ class IrMangledNameAndSignatureDumpHandler(
|
||||
}
|
||||
|
||||
override fun processAfterAllModules(someAssertionWasFailed: Boolean) {
|
||||
if (dumper.isEmpty()) return
|
||||
if (dumper.isEmpty()) {
|
||||
assertions.assertFileDoesntExist(expectedFile, DUMP_SIGNATURES)
|
||||
return
|
||||
}
|
||||
val frontendKind = testServices.defaultsProvider.defaultFrontend
|
||||
val muteDirectives = listOfNotNull(
|
||||
MUTE_SIGNATURE_COMPARISON_K2.takeIf { frontendKind == FrontendKinds.FIR },
|
||||
|
||||
+6
-3
@@ -21,7 +21,6 @@ import org.jetbrains.kotlin.test.directives.model.DirectivesContainer
|
||||
import org.jetbrains.kotlin.test.model.AfterAnalysisChecker
|
||||
import org.jetbrains.kotlin.test.model.BackendKind
|
||||
import org.jetbrains.kotlin.test.model.TestModule
|
||||
import org.jetbrains.kotlin.test.services.ServiceRegistrationData
|
||||
import org.jetbrains.kotlin.test.services.TestServices
|
||||
import org.jetbrains.kotlin.test.services.moduleStructure
|
||||
import org.jetbrains.kotlin.test.utils.MultiModuleInfoDumper
|
||||
@@ -64,11 +63,15 @@ class IrPrettyKotlinDumpHandler(
|
||||
}
|
||||
|
||||
override fun processAfterAllModules(someAssertionWasFailed: Boolean) {
|
||||
if (dumper.isEmpty()) return
|
||||
val moduleStructure = testServices.moduleStructure
|
||||
val extension = computeDumpExtension(moduleStructure.modules.first(), DUMP_EXTENSION)
|
||||
val expectedFile = moduleStructure.originalTestDataFiles.first().withExtension(extension)
|
||||
assertions.assertEqualsToFile(expectedFile, dumper.generateResultingDump())
|
||||
|
||||
if (dumper.isEmpty()) {
|
||||
assertions.assertFileDoesntExist(expectedFile, DUMP_KT_IR)
|
||||
} else {
|
||||
assertions.assertEqualsToFile(expectedFile, dumper.generateResultingDump())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-2
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.ir.visitors.acceptVoid
|
||||
import org.jetbrains.kotlin.test.Constructor
|
||||
import org.jetbrains.kotlin.test.backend.ir.IrBackendInput
|
||||
import org.jetbrains.kotlin.test.directives.CodegenTestDirectives
|
||||
import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.DUMP_SOURCE_RANGES_IR
|
||||
import org.jetbrains.kotlin.test.directives.FirDiagnosticsDirectives
|
||||
import org.jetbrains.kotlin.test.directives.model.DirectivesContainer
|
||||
import org.jetbrains.kotlin.test.model.AfterAnalysisChecker
|
||||
@@ -47,7 +48,7 @@ class IrSourceRangesDumpHandler(
|
||||
get() = DUMP_EXTENSION
|
||||
|
||||
override fun shouldRun(): Boolean {
|
||||
return CodegenTestDirectives.DUMP_SOURCE_RANGES_IR in testServices.moduleStructure.allDirectives
|
||||
return DUMP_SOURCE_RANGES_IR in testServices.moduleStructure.allDirectives
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +56,7 @@ class IrSourceRangesDumpHandler(
|
||||
private val buildersForSeparateFileDumps: MutableMap<File, StringBuilder> = mutableMapOf()
|
||||
|
||||
override fun processModule(module: TestModule, info: IrBackendInput) {
|
||||
if (CodegenTestDirectives.DUMP_SOURCE_RANGES_IR !in module.directives) return
|
||||
if (DUMP_SOURCE_RANGES_IR !in module.directives) return
|
||||
val builder = baseDumper.builderForModule(module.name)
|
||||
for (irFile in info.irModuleFragment.files) {
|
||||
builder.append(irFile.dumpWithSourceLocations(irFile.fileEntry))
|
||||
@@ -122,6 +123,8 @@ class IrSourceRangesDumpHandler(
|
||||
private fun checkOneExpectedFile(expectedFile: File, actualDump: String) {
|
||||
if (actualDump.isNotEmpty()) {
|
||||
assertions.assertEqualsToFile(expectedFile, actualDump)
|
||||
} else {
|
||||
assertions.assertFileDoesntExist(expectedFile, DUMP_SOURCE_RANGES_IR)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+9
-1
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.test.Constructor
|
||||
import org.jetbrains.kotlin.test.backend.ir.IrBackendInput
|
||||
import org.jetbrains.kotlin.test.directives.CodegenTestDirectives
|
||||
import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.CHECK_BYTECODE_LISTING
|
||||
import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.DUMP_EXTERNAL_CLASS
|
||||
import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.DUMP_IR
|
||||
import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.EXTERNAL_FILE
|
||||
@@ -42,6 +43,7 @@ class IrTextDumpHandler(
|
||||
) : AbstractIrHandler(testServices, artifactKind) {
|
||||
companion object {
|
||||
const val DUMP_EXTENSION = "ir.txt"
|
||||
const val DUMP_EXTENSION2 = "ir2.txt"
|
||||
|
||||
fun computeDumpExtension(module: TestModule, defaultExtension: String, ignoreFirIdentical: Boolean = false): String {
|
||||
return if (
|
||||
@@ -85,7 +87,11 @@ class IrTextDumpHandler(
|
||||
private val baseDumper = MultiModuleInfoDumper()
|
||||
private val buildersForSeparateFileDumps: MutableMap<File, StringBuilder> = mutableMapOf()
|
||||
|
||||
private var byteCodeListingEnabled = false
|
||||
|
||||
override fun processModule(module: TestModule, info: IrBackendInput) {
|
||||
byteCodeListingEnabled = byteCodeListingEnabled || CHECK_BYTECODE_LISTING in module.directives
|
||||
|
||||
if (DUMP_IR !in module.directives) return
|
||||
|
||||
val irBuiltins = info.irModuleFragment.irBuiltins
|
||||
@@ -149,11 +155,13 @@ class IrTextDumpHandler(
|
||||
private fun checkOneExpectedFile(expectedFile: File, actualDump: String) {
|
||||
if (actualDump.isNotEmpty()) {
|
||||
assertions.assertEqualsToFile(expectedFile, actualDump)
|
||||
} else {
|
||||
assertions.assertFileDoesntExist(expectedFile, DUMP_IR)
|
||||
}
|
||||
}
|
||||
|
||||
private fun TestModule.getDumpExtension(ignoreFirIdentical: Boolean = false): String {
|
||||
return computeDumpExtension(this, DUMP_EXTENSION, ignoreFirIdentical)
|
||||
return computeDumpExtension(this, if (byteCodeListingEnabled) DUMP_EXTENSION2 else DUMP_EXTENSION, ignoreFirIdentical)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-2
@@ -66,8 +66,6 @@ class SMAPDumpHandler(testServices: TestServices) : JvmBinaryArtifactHandler(tes
|
||||
}
|
||||
|
||||
override fun processAfterAllModules(someAssertionWasFailed: Boolean) {
|
||||
if (dumper.isEmpty()) return
|
||||
|
||||
val separateDumpEnabled = separateDumpsEnabled()
|
||||
val isSeparateCompilation = isSeparateCompilation()
|
||||
|
||||
@@ -83,6 +81,12 @@ class SMAPDumpHandler(testServices: TestServices) : JvmBinaryArtifactHandler(tes
|
||||
if (testServices.moduleStructure.modules.first().frontendKind == FrontendKinds.FIR && firExpectedFile.exists())
|
||||
firExpectedFile
|
||||
else testDataFile.withExtension(extension)
|
||||
|
||||
if (dumper.isEmpty()) {
|
||||
assertions.assertFileDoesntExist(expectedFile, DUMP_SMAP)
|
||||
return
|
||||
}
|
||||
|
||||
assertions.assertEqualsToFile(expectedFile, dumper.generateResultingDump())
|
||||
|
||||
if (separateDumpEnabled && isSeparateCompilation) {
|
||||
|
||||
+10
-3
@@ -11,11 +11,15 @@ import org.jetbrains.kotlin.cli.common.messages.MessageRenderer
|
||||
import org.jetbrains.kotlin.cli.common.messages.PrintingMessageCollector
|
||||
import org.jetbrains.kotlin.diagnostics.GenericDiagnostics
|
||||
import org.jetbrains.kotlin.diagnostics.UnboundDiagnostic
|
||||
import org.jetbrains.kotlin.test.backend.handlers.assertFileDoesntExist
|
||||
import org.jetbrains.kotlin.test.directives.DiagnosticsDirectives
|
||||
import org.jetbrains.kotlin.test.directives.DiagnosticsDirectives.RENDER_ALL_DIAGNOSTICS_FULL_TEXT
|
||||
import org.jetbrains.kotlin.test.directives.DiagnosticsDirectives.RENDER_DIAGNOSTICS_FULL_TEXT
|
||||
import org.jetbrains.kotlin.test.directives.model.DirectivesContainer
|
||||
import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontendOutputArtifact
|
||||
import org.jetbrains.kotlin.test.model.TestModule
|
||||
import org.jetbrains.kotlin.test.services.TestServices
|
||||
import org.jetbrains.kotlin.test.services.assertions
|
||||
import org.jetbrains.kotlin.test.services.diagnosticsService
|
||||
import org.jetbrains.kotlin.test.services.moduleStructure
|
||||
import org.jetbrains.kotlin.test.utils.MultiModuleInfoDumper
|
||||
@@ -33,16 +37,19 @@ class DiagnosticMessagesTextHandler(
|
||||
private val dumper: MultiModuleInfoDumper = MultiModuleInfoDumper(moduleHeaderTemplate = "// -- Module: <%s> --")
|
||||
|
||||
override fun processAfterAllModules(someAssertionWasFailed: Boolean) {
|
||||
if (dumper.isEmpty()) return
|
||||
val resultDump = dumper.generateResultingDump()
|
||||
val testDataFile = testServices.moduleStructure.originalTestDataFiles.first()
|
||||
val expectedFile = testDataFile.withExtension(".diag.txt")
|
||||
|
||||
if (dumper.isEmpty()) {
|
||||
assertions.assertFileDoesntExist(expectedFile, RENDER_DIAGNOSTICS_FULL_TEXT)
|
||||
return
|
||||
}
|
||||
assertions.assertEqualsToFile(expectedFile, resultDump)
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalStdlibApi::class)
|
||||
override fun processModule(module: TestModule, info: ClassicFrontendOutputArtifact) {
|
||||
if (DiagnosticsDirectives.RENDER_DIAGNOSTICS_FULL_TEXT !in module.directives) return
|
||||
if (RENDER_DIAGNOSTICS_FULL_TEXT !in module.directives) return
|
||||
|
||||
val diagnosticsFullTextByteArrayStream = ByteArrayOutputStream()
|
||||
val diagnosticsFullTextPrintStream = PrintStream(diagnosticsFullTextByteArrayStream)
|
||||
|
||||
+10
-4
@@ -6,8 +6,10 @@
|
||||
package org.jetbrains.kotlin.test.frontend.fir.handlers
|
||||
|
||||
import org.jetbrains.kotlin.fir.resolve.dfa.cfg.FirControlFlowGraphRenderVisitor
|
||||
import org.jetbrains.kotlin.test.backend.handlers.assertFileDoesntExist
|
||||
import org.jetbrains.kotlin.test.directives.DumpCfgOption
|
||||
import org.jetbrains.kotlin.test.directives.FirDiagnosticsDirectives
|
||||
import org.jetbrains.kotlin.test.directives.FirDiagnosticsDirectives.DUMP_CFG
|
||||
import org.jetbrains.kotlin.test.directives.model.DirectivesContainer
|
||||
import org.jetbrains.kotlin.test.frontend.fir.FirOutputArtifact
|
||||
import org.jetbrains.kotlin.test.model.TestModule
|
||||
@@ -23,8 +25,8 @@ class FirCfgDumpHandler(testServices: TestServices) : FirAnalysisHandler(testSer
|
||||
private var alreadyDumped: Boolean = false
|
||||
|
||||
override fun processModule(module: TestModule, info: FirOutputArtifact) {
|
||||
if (alreadyDumped || FirDiagnosticsDirectives.DUMP_CFG !in module.directives) return
|
||||
val options = module.directives[FirDiagnosticsDirectives.DUMP_CFG].map { it.uppercase() }
|
||||
if (alreadyDumped || DUMP_CFG !in module.directives) return
|
||||
val options = module.directives[DUMP_CFG].map { it.uppercase() }
|
||||
|
||||
val file = info.mainFirFiles.values.first()
|
||||
val renderLevels = DumpCfgOption.LEVELS in options
|
||||
@@ -34,9 +36,13 @@ class FirCfgDumpHandler(testServices: TestServices) : FirAnalysisHandler(testSer
|
||||
}
|
||||
|
||||
override fun processAfterAllModules(someAssertionWasFailed: Boolean) {
|
||||
if (!alreadyDumped) return
|
||||
val testDataFile = testServices.moduleStructure.originalTestDataFiles.first()
|
||||
val expectedFile = testDataFile.parentFile.resolve("${testDataFile.nameWithoutFirExtension}.dot")
|
||||
assertions.assertEqualsToFile(expectedFile, builder.toString())
|
||||
|
||||
if (!alreadyDumped) {
|
||||
assertions.assertFileDoesntExist(expectedFile, DUMP_CFG)
|
||||
} else {
|
||||
assertions.assertEqualsToFile(expectedFile, builder.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+8
-3
@@ -46,6 +46,7 @@ import org.jetbrains.kotlin.psi.KtQualifiedExpression
|
||||
import org.jetbrains.kotlin.resolve.AnalyzingUtils
|
||||
import org.jetbrains.kotlin.test.Constructor
|
||||
import org.jetbrains.kotlin.test.FirParser
|
||||
import org.jetbrains.kotlin.test.backend.handlers.assertFileDoesntExist
|
||||
import org.jetbrains.kotlin.test.directives.AdditionalFilesDirectives
|
||||
import org.jetbrains.kotlin.test.directives.DiagnosticsDirectives
|
||||
import org.jetbrains.kotlin.test.directives.FirDiagnosticsDirectives
|
||||
@@ -68,11 +69,15 @@ class FullDiagnosticsRenderer(private val directive: SimpleDirective) {
|
||||
private val dumper: MultiModuleInfoDumper = MultiModuleInfoDumper(moduleHeaderTemplate = "// -- Module: <%s> --")
|
||||
|
||||
fun assertCollectedDiagnostics(testServices: TestServices, expectedExtension: String) {
|
||||
if (directive !in testServices.moduleStructure.allDirectives) {
|
||||
return
|
||||
}
|
||||
val testDataFile = testServices.moduleStructure.originalTestDataFiles.first()
|
||||
val expectedFile = testDataFile.parentFile.resolve("${testDataFile.nameWithoutExtension.removeSuffix(".fir")}$expectedExtension")
|
||||
|
||||
if (directive !in testServices.moduleStructure.allDirectives) {
|
||||
if (DiagnosticsDirectives.RENDER_ALL_DIAGNOSTICS_FULL_TEXT !in testServices.moduleStructure.allDirectives) {
|
||||
testServices.assertions.assertFileDoesntExist(expectedFile, directive)
|
||||
}
|
||||
return
|
||||
}
|
||||
if (dumper.isEmpty() && !expectedFile.exists()) {
|
||||
return
|
||||
}
|
||||
|
||||
+13
-4
@@ -16,6 +16,8 @@ import org.jetbrains.kotlin.fir.renderer.FirPackageDirectiveRenderer
|
||||
import org.jetbrains.kotlin.fir.renderer.FirRenderer
|
||||
import org.jetbrains.kotlin.fir.renderer.FirSymbolRendererWithStaticFlag
|
||||
import org.jetbrains.kotlin.fir.symbols.lazyDeclarationResolver
|
||||
import org.jetbrains.kotlin.test.backend.handlers.assertFileDoesntExist
|
||||
import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.CHECK_BYTECODE_LISTING
|
||||
import org.jetbrains.kotlin.test.directives.FirDiagnosticsDirectives
|
||||
import org.jetbrains.kotlin.test.directives.model.DirectivesContainer
|
||||
import org.jetbrains.kotlin.test.frontend.fir.FirOutputArtifact
|
||||
@@ -28,6 +30,7 @@ class FirDumpHandler(
|
||||
testServices: TestServices
|
||||
) : FirAnalysisHandler(testServices) {
|
||||
private val dumper: MultiModuleInfoDumper = MultiModuleInfoDumper()
|
||||
private var byteCodeListingEnabled = false
|
||||
|
||||
override val directiveContainers: List<DirectivesContainer>
|
||||
get() = listOf(FirDiagnosticsDirectives)
|
||||
@@ -35,6 +38,7 @@ class FirDumpHandler(
|
||||
override fun processModule(module: TestModule, info: FirOutputArtifact) {
|
||||
for (part in info.partsForDependsOnModules) {
|
||||
val currentModule = part.module
|
||||
byteCodeListingEnabled = byteCodeListingEnabled || CHECK_BYTECODE_LISTING in module.directives
|
||||
if (FirDiagnosticsDirectives.FIR_DUMP !in currentModule.directives) return
|
||||
val builderForModule = dumper.builderForModule(currentModule)
|
||||
val firFiles = info.mainFirFiles
|
||||
@@ -59,12 +63,17 @@ class FirDumpHandler(
|
||||
}
|
||||
|
||||
override fun processAfterAllModules(someAssertionWasFailed: Boolean) {
|
||||
if (dumper.isEmpty()) return
|
||||
// TODO: change according to multiple testdata files
|
||||
val testDataFile = testServices.moduleStructure.originalTestDataFiles.first()
|
||||
val expectedFile = testDataFile.parentFile.resolve("${testDataFile.nameWithoutFirExtension}.fir.txt")
|
||||
val actualText = dumper.generateResultingDump()
|
||||
assertions.assertEqualsToFile(expectedFile, actualText, message = { "Content is not equal" })
|
||||
val extension = if (byteCodeListingEnabled) ".fir2.txt" else ".fir.txt"
|
||||
val expectedFile = testDataFile.parentFile.resolve("${testDataFile.nameWithoutFirExtension}$extension")
|
||||
|
||||
if (dumper.isEmpty()) {
|
||||
assertions.assertFileDoesntExist(expectedFile, FirDiagnosticsDirectives.FIR_DUMP)
|
||||
} else {
|
||||
val actualText = dumper.generateResultingDump()
|
||||
assertions.assertEqualsToFile(expectedFile, actualText, message = { "Content is not equal" })
|
||||
}
|
||||
}
|
||||
|
||||
private class FirClassMemberRendererWithGeneratedDeclarations(val session: FirSession) : FirClassMemberRenderer() {
|
||||
|
||||
+9
-8
@@ -6,11 +6,7 @@
|
||||
package org.jetbrains.kotlin.test.frontend.fir.handlers
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirCallableDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin
|
||||
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
||||
import org.jetbrains.kotlin.fir.declarations.hiddenEverywhereBesideSuperCallsStatus
|
||||
import org.jetbrains.kotlin.fir.declarations.isHiddenToOvercomeSignatureClash
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.render
|
||||
import org.jetbrains.kotlin.fir.renderer.FirRenderer
|
||||
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
||||
@@ -25,7 +21,9 @@ import org.jetbrains.kotlin.fir.symbols.lazyDeclarationResolver
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.test.backend.handlers.assertFileDoesntExist
|
||||
import org.jetbrains.kotlin.test.directives.FirDiagnosticsDirectives
|
||||
import org.jetbrains.kotlin.test.directives.FirDiagnosticsDirectives.SCOPE_DUMP
|
||||
import org.jetbrains.kotlin.test.directives.model.DirectivesContainer
|
||||
import org.jetbrains.kotlin.test.frontend.fir.FirOutputArtifact
|
||||
import org.jetbrains.kotlin.test.model.TestModule
|
||||
@@ -46,7 +44,7 @@ class FirScopeDumpHandler(testServices: TestServices) : FirAnalysisHandler(testS
|
||||
override fun processModule(module: TestModule, info: FirOutputArtifact) {
|
||||
for (part in info.partsForDependsOnModules) {
|
||||
val currentModule = part.module
|
||||
val fqNamesWithNames = currentModule.directives[FirDiagnosticsDirectives.SCOPE_DUMP]
|
||||
val fqNamesWithNames = currentModule.directives[SCOPE_DUMP]
|
||||
if (fqNamesWithNames.isEmpty()) return
|
||||
val printer = SmartPrinter(dumper.builderForModule(currentModule), indent = " ")
|
||||
for (fqNameWithNames in fqNamesWithNames) {
|
||||
@@ -158,9 +156,12 @@ class FirScopeDumpHandler(testServices: TestServices) : FirAnalysisHandler(testS
|
||||
}
|
||||
|
||||
override fun processAfterAllModules(someAssertionWasFailed: Boolean) {
|
||||
if (dumper.isEmpty()) return
|
||||
val expectedFile = testServices.moduleStructure.originalTestDataFiles.first().withExtension(".overrides.txt")
|
||||
val actualDump = dumper.generateResultingDump()
|
||||
assertions.assertEqualsToFile(expectedFile, actualDump)
|
||||
if (dumper.isEmpty()) {
|
||||
assertions.assertFileDoesntExist(expectedFile, SCOPE_DUMP)
|
||||
} else {
|
||||
assertions.assertEqualsToFile(expectedFile, actualDump)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,8 +15,6 @@ import java.io.IOException
|
||||
import org.junit.jupiter.api.Assertions as JUnit5PlatformAssertions
|
||||
|
||||
object JUnit5Assertions : AssertionsService() {
|
||||
val isTeamCityBuild: Boolean = System.getenv("TEAMCITY_VERSION") != null
|
||||
|
||||
override fun assertEqualsToFile(expectedFile: File, actual: String, sanitizer: (String) -> String, message: () -> String) {
|
||||
assertEqualsToFile(
|
||||
expectedFile,
|
||||
|
||||
Reference in New Issue
Block a user