From b1d1f87318ae5f289f709548b567121f7b4cdcb0 Mon Sep 17 00:00:00 2001 From: "Evgeniy.Zhelenskiy" Date: Wed, 8 Dec 2021 22:52:03 +0300 Subject: [PATCH] [Tests] Introduce reversible source file preprocessor --- .../FirBlackBoxCodegenTestGenerated.java | 4 ++-- .../org/jetbrains/kotlin/test/TestRunner.kt | 20 ++++++------------- .../test/services/SourceFileProvider.kt | 7 ++++++- .../codegen/BlackBoxCodegenTestGenerated.java | 2 +- .../IrBlackBoxCodegenTestGenerated.java | 4 ++-- .../test/utils/TransformersFunctions.kt | 10 +++------- .../LightAnalysisModeTestGenerated.java | 2 +- .../model/WithoutJvmInlineTestMethodModel.kt | 4 ++-- .../js/test/JsCodegenBoxTestGenerated.java | 2 +- .../test/ir/IrJsCodegenBoxTestGenerated.java | 2 +- .../IrCodegenBoxWasmTestGenerated.java | 2 +- .../NativeExtBlackBoxTestGenerated.java | 4 ++-- 12 files changed, 28 insertions(+), 35 deletions(-) diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index e32bb099640..88c58fad1f2 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -19292,13 +19292,13 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT @Test @TestMetadata("boxResultInlineClassOfConstructorCall.kt") public void testBoxResultInlineClassOfConstructorCall() throws Exception { - runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions::replaceOptionalJvmInlineAnnotationWithReal); + runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions.getReplaceOptionalJvmInlineAnnotationWithReal()); } @Test @TestMetadata("boxResultInlineClassOfConstructorCall.kt") public void testBoxResultInlineClassOfConstructorCall_valueClasses() throws Exception { - runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions::removeOptionalJvmInlineAnnotation); + runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions.getRemoveOptionalJvmInlineAnnotation()); } @Test diff --git a/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/TestRunner.kt b/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/TestRunner.kt index 60fe4fbb85c..ea278ef6380 100644 --- a/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/TestRunner.kt +++ b/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/TestRunner.kt @@ -24,13 +24,9 @@ class TestRunner(private val testConfiguration: TestConfiguration) { private val allFailedExceptions = mutableListOf() private val allRanHandlers = mutableSetOf>() - fun runTest( - @TestDataFile testDataFileName: String, - expectedFileTransformer: ((String) -> String)? = null, - beforeDispose: (TestConfiguration) -> Unit = {}, - ) { + fun runTest(@TestDataFile testDataFileName: String, beforeDispose: (TestConfiguration) -> Unit = {}) { try { - runTestImpl(testDataFileName, expectedFileTransformer) + runTestImpl(testDataFileName) } finally { try { testConfiguration.testServices.temporaryDirectoryManager.cleanupTemporaryDirectories() @@ -42,7 +38,7 @@ class TestRunner(private val testConfiguration: TestConfiguration) { } } - private fun runTestImpl(@TestDataFile testDataFileName: String, expectedFileTransformer: ((String) -> String)?) { + private fun runTestImpl(@TestDataFile testDataFileName: String) { val services = testConfiguration.testServices @Suppress("NAME_SHADOWING") @@ -70,14 +66,10 @@ class TestRunner(private val testConfiguration: TestConfiguration) { if (it.shouldSkipTest()) return } - runTestPipeline(moduleStructure, services, expectedFileTransformer) + runTestPipeline(moduleStructure, services) } - fun runTestPipeline( - moduleStructure: TestModuleStructure, - services: TestServices, - expectedFileTransformer: ((String) -> String)?, - ) { + fun runTestPipeline(moduleStructure: TestModuleStructure, services: TestServices) { val globalMetadataInfoHandler = testConfiguration.testServices.globalMetadataInfoHandler globalMetadataInfoHandler.parseExistingMetadataInfosFromAllSources() @@ -105,7 +97,7 @@ class TestRunner(private val testConfiguration: TestConfiguration) { } if (testConfiguration.metaInfoHandlerEnabled) { withAssertionCatching(WrappedException::FromMetaInfoHandler) { - globalMetadataInfoHandler.compareAllMetaDataInfos(expectedFileTransformer) + globalMetadataInfoHandler.compareAllMetaDataInfos() } } diff --git a/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/services/SourceFileProvider.kt b/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/services/SourceFileProvider.kt index 3e7cd43a28b..0945a1d1283 100644 --- a/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/services/SourceFileProvider.kt +++ b/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/services/SourceFileProvider.kt @@ -15,6 +15,10 @@ abstract class SourceFilePreprocessor(val testServices: TestServices) { abstract fun process(file: TestFile, content: String): String } +abstract class ReversibleSourceFilePreprocessor(testServices: TestServices) : SourceFilePreprocessor(testServices) { + abstract fun revert(file: TestFile, actualContent: String): String +} + abstract class SourceFileProvider : TestService { abstract val kotlinSourceDirectory: File abstract val javaSourceDirectory: File @@ -23,11 +27,12 @@ abstract class SourceFileProvider : TestService { abstract fun getContentOfSourceFile(testFile: TestFile): String abstract fun getRealFileForSourceFile(testFile: TestFile): File abstract fun getRealFileForBinaryFile(testFile: TestFile): File + abstract val preprocessors: List } val TestServices.sourceFileProvider: SourceFileProvider by TestServices.testServiceAccessor() -class SourceFileProviderImpl(val testServices: TestServices, val preprocessors: List) : SourceFileProvider() { +class SourceFileProviderImpl(val testServices: TestServices, override val preprocessors: List) : SourceFileProvider() { override val kotlinSourceDirectory: File = testServices.getOrCreateTempDirectory("kotlin-files") override val javaSourceDirectory: File = testServices.getOrCreateTempDirectory("java-files") override val javaBinaryDirectory: File = testServices.getOrCreateTempDirectory("java-binary-files") diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java index c4cc8e33738..93cddfe471f 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java @@ -18908,7 +18908,7 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { @Test @TestMetadata("boxResultInlineClassOfConstructorCall.kt") public void testBoxResultInlineClassOfConstructorCall() throws Exception { - runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions::replaceOptionalJvmInlineAnnotationWithReal); + runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions.getReplaceOptionalJvmInlineAnnotationWithReal()); } @Test diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index 2985900cc4f..5b85138d33d 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -19292,13 +19292,13 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes @Test @TestMetadata("boxResultInlineClassOfConstructorCall.kt") public void testBoxResultInlineClassOfConstructorCall() throws Exception { - runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions::replaceOptionalJvmInlineAnnotationWithReal); + runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions.getReplaceOptionalJvmInlineAnnotationWithReal()); } @Test @TestMetadata("boxResultInlineClassOfConstructorCall.kt") public void testBoxResultInlineClassOfConstructorCall_valueClasses() throws Exception { - runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions::removeOptionalJvmInlineAnnotation); + runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions.getRemoveOptionalJvmInlineAnnotation()); } @Test diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/utils/TransformersFunctions.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/utils/TransformersFunctions.kt index 1f947da40fa..116893961f3 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/utils/TransformersFunctions.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/utils/TransformersFunctions.kt @@ -9,18 +9,14 @@ import java.io.File object TransformersFunctions { @JvmStatic - fun replaceOptionalJvmInlineAnnotationWithReal(source: String): String { - return source.replace("OPTIONAL_JVM_INLINE_ANNOTATION", "@JvmInline") - } + val replaceOptionalJvmInlineAnnotationWithReal = ReplacingSourceTransformer("OPTIONAL_JVM_INLINE_ANNOTATION", "@JvmInline") @JvmStatic - fun removeOptionalJvmInlineAnnotation(source: String): String { - return source.replace("OPTIONAL_JVM_INLINE_ANNOTATION", "") - } + val removeOptionalJvmInlineAnnotation = ReplacingSourceTransformer("OPTIONAL_JVM_INLINE_ANNOTATION", "") object Android { val forAll: List<(String) -> String> = listOf( - TransformersFunctions::replaceOptionalJvmInlineAnnotationWithReal, + replaceOptionalJvmInlineAnnotationWithReal, ) val forSpecificFile: Map String> = mapOf( ) diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 56453e78588..33716d0898b 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -15781,7 +15781,7 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes @TestMetadata("boxResultInlineClassOfConstructorCall.kt") public void testBoxResultInlineClassOfConstructorCall() throws Exception { - runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions::replaceOptionalJvmInlineAnnotationWithReal); + runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions.getReplaceOptionalJvmInlineAnnotationWithReal()); } @TestMetadata("boxUnboxInlineClassesWithOperatorsGetSet.kt") diff --git a/generators/test-generator/tests/org/jetbrains/kotlin/generators/model/WithoutJvmInlineTestMethodModel.kt b/generators/test-generator/tests/org/jetbrains/kotlin/generators/model/WithoutJvmInlineTestMethodModel.kt index 9e771f7a630..a482ff6c513 100644 --- a/generators/test-generator/tests/org/jetbrains/kotlin/generators/model/WithoutJvmInlineTestMethodModel.kt +++ b/generators/test-generator/tests/org/jetbrains/kotlin/generators/model/WithoutJvmInlineTestMethodModel.kt @@ -11,8 +11,8 @@ class WithoutJvmInlineTestMethodModel( withPostfix: Boolean, ) : TransformingTestMethodModel( source, - transformer = "TransformersFunctions::" + - if (withAnnotation) "replaceOptionalJvmInlineAnnotationWithReal" else "removeOptionalJvmInlineAnnotation" + transformer = "TransformersFunctions.get" + + if (withAnnotation) "ReplaceOptionalJvmInlineAnnotationWithReal()" else "RemoveOptionalJvmInlineAnnotation()" ) { override val name: String = source.name + if (withPostfix) "_valueClasses" else "" } \ No newline at end of file diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java index 046429c57f0..9db2e02b602 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java @@ -14842,7 +14842,7 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { @Test @TestMetadata("boxResultInlineClassOfConstructorCall.kt") public void testBoxResultInlineClassOfConstructorCall() throws Exception { - runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions::removeOptionalJvmInlineAnnotation); + runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions.getRemoveOptionalJvmInlineAnnotation()); } @Test diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java index eaad87a4063..9a89c54fc1c 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java @@ -14806,7 +14806,7 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { @Test @TestMetadata("boxResultInlineClassOfConstructorCall.kt") public void testBoxResultInlineClassOfConstructorCall() throws Exception { - runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions::removeOptionalJvmInlineAnnotation); + runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions.getRemoveOptionalJvmInlineAnnotation()); } @Test diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java index be6da78299e..85a2b22bd47 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java @@ -12473,7 +12473,7 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest @TestMetadata("boxResultInlineClassOfConstructorCall.kt") public void testBoxResultInlineClassOfConstructorCall() throws Exception { - runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions::removeOptionalJvmInlineAnnotation); + runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions.getRemoveOptionalJvmInlineAnnotation()); } @TestMetadata("boxUnboxInlineClassesWithOperatorsGetSet.kt") diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeExtBlackBoxTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeExtBlackBoxTestGenerated.java index a7e7b624a87..5afbe863693 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeExtBlackBoxTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeExtBlackBoxTestGenerated.java @@ -15646,7 +15646,7 @@ public class NativeExtBlackBoxTestGenerated extends AbstractNativeBlackBoxTest { @NativeBlackBoxTestCaseGroupProvider(ExtTestCaseGroupProvider.class) public class InlineClasses { public InlineClasses() { - register("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions::removeOptionalJvmInlineAnnotation); + register("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions.getRemoveOptionalJvmInlineAnnotation()); } @Test @@ -15705,7 +15705,7 @@ public class NativeExtBlackBoxTestGenerated extends AbstractNativeBlackBoxTest { @Test @TestMetadata("boxResultInlineClassOfConstructorCall.kt") public void testBoxResultInlineClassOfConstructorCall() throws Exception { - // There is a registered source transformer for the testcase: TransformersFunctions::removeOptionalJvmInlineAnnotation + // There is a registered source transformer for the testcase: TransformersFunctions.getRemoveOptionalJvmInlineAnnotation() runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt"); }