From dff5799c58daa2322217200fe48fa56ed3345e2f Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Thu, 24 Nov 2022 10:44:55 +0200 Subject: [PATCH] [Test] Don't create separate .fir.txt file in BytecodeListingHandler if not necessary --- .../explicitBackingFieldsInJava.fir.txt | 13 -------- .../handlers/BytecodeListingHandler.kt | 30 ++++++++++++------- 2 files changed, 20 insertions(+), 23 deletions(-) delete mode 100644 compiler/fir/fir2ir/testData/codegen/bytecodeListing/properties/backingField/explicitBackingFieldsInJava.fir.txt diff --git a/compiler/fir/fir2ir/testData/codegen/bytecodeListing/properties/backingField/explicitBackingFieldsInJava.fir.txt b/compiler/fir/fir2ir/testData/codegen/bytecodeListing/properties/backingField/explicitBackingFieldsInJava.fir.txt deleted file mode 100644 index e26c962c97d..00000000000 --- a/compiler/fir/fir2ir/testData/codegen/bytecodeListing/properties/backingField/explicitBackingFieldsInJava.fir.txt +++ /dev/null @@ -1,13 +0,0 @@ -@kotlin.Metadata -public final class AC { - // source: 'AC.kt' - private final field number: int - public method (): void - public final @org.jetbrains.annotations.NotNull method getNumber(): java.lang.Number -} - -@kotlin.Metadata -public interface AI { - // source: 'AI.kt' - public abstract @org.jetbrains.annotations.NotNull method getNumber(): java.lang.Number -} diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/BytecodeListingHandler.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/BytecodeListingHandler.kt index 54bc6b0baaf..c32a3f02911 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/BytecodeListingHandler.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/BytecodeListingHandler.kt @@ -44,19 +44,29 @@ class BytecodeListingHandler(testServices: TestServices) : JvmBinaryArtifactHand if (multiModuleInfoDumper.isEmpty()) return val sourceFile = testServices.moduleStructure.originalTestDataFiles.first() - val extension = - if (testServices.defaultsProvider.defaultFrontend == FrontendKinds.FIR && FIR_IDENTICAL !in testServices.moduleStructure.allDirectives) ".fir.txt" else ".txt" - val defaultTxtFile = sourceFile.withExtension(extension) + val defaultTxtFile = sourceFile.withExtension(".txt") + val irTxtFile = sourceFile.withSuffixAndExtension("_ir", ".txt") + val firTxtFile = sourceFile.withExtension(".fir.txt") + + val isFir = testServices.defaultsProvider.defaultFrontend == FrontendKinds.FIR val isIr = testServices.defaultsProvider.defaultTargetBackend?.isIR == true - val txtFile = - if (isIr) sourceFile.withSuffixAndExtension("_ir", extension).takeIf(File::exists) ?: defaultTxtFile - else defaultTxtFile - assertions.assertEqualsToFile(txtFile, multiModuleInfoDumper.generateResultingDump()) + val actualFile = when { + isFir -> firTxtFile.takeIf { it.exists() } ?: irTxtFile.takeIf { it.exists() } ?: defaultTxtFile + isIr -> irTxtFile.takeIf { it.exists() } ?: defaultTxtFile + else -> defaultTxtFile + } - if (isIr && txtFile != defaultTxtFile) { - if (txtFile.readText() == defaultTxtFile.readText()) assertions.fail { - "JVM and JVM_IR golden files are identical. Remove $txtFile." + val goldenFile = when { + isFir -> irTxtFile.takeIf { it.exists() } ?: defaultTxtFile + else -> defaultTxtFile + } + + assertions.assertEqualsToFile(actualFile, multiModuleInfoDumper.generateResultingDump()) + + if (actualFile != goldenFile) { + if (actualFile.readText().trim() == goldenFile.readText().trim()) assertions.fail { + "JVM and JVM_IR golden files are identical. Remove $actualFile." } } }