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 0160339df3c..3b34a0a3950 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 @@ -18907,7 +18907,7 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { @Test @TestMetadata("boxResultInlineClassOfConstructorCall.kt") public void testBoxResultInlineClassOfConstructorCall() throws Exception { - runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt"); + runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", s -> s.replaceAll("OPTIONAL_JVM_INLINE_ANNOTATION", "@kotlin.jvm.JvmInline")); } @Test diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/generators/impl/RunTestMethodGenerator.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/generators/impl/RunTestMethodGenerator.kt index 6dd71d49783..73cf9ee5c81 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/generators/impl/RunTestMethodGenerator.kt +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/generators/impl/RunTestMethodGenerator.kt @@ -5,11 +5,12 @@ package org.jetbrains.kotlin.generators.impl -import org.jetbrains.kotlin.generators.model.MethodModel import org.jetbrains.kotlin.generators.MethodGenerator +import org.jetbrains.kotlin.generators.model.MethodModel import org.jetbrains.kotlin.generators.model.RunTestMethodModel import org.jetbrains.kotlin.test.TargetBackend import org.jetbrains.kotlin.utils.Printer +import java.util.function.Function object RunTestMethodGenerator : MethodGenerator() { override val kind: MethodModel.Kind @@ -17,19 +18,21 @@ object RunTestMethodGenerator : MethodGenerator() { override fun generateBody(method: RunTestMethodModel, p: Printer) { with(method) { + val transformerPostfix = if (method.withTransformer) ", transformer" else "" if (!isWithTargetBackend()) { - p.println("KotlinTestUtils.${method.testRunnerMethodName}(this::$testMethodName, this, testDataFilePath);") + p.println("KotlinTestUtils.${method.testRunnerMethodName}(this::$testMethodName, this, testDataFilePath$transformerPostfix);") } else { val className = TargetBackend::class.java.simpleName val additionalArguments = if (additionalRunnerArguments.isNotEmpty()) additionalRunnerArguments.joinToString(separator = ", ", prefix = ", ") else "" - p.println("KotlinTestUtils.$testRunnerMethodName(this::$testMethodName, $className.$targetBackend, testDataFilePath$additionalArguments);") + p.println("KotlinTestUtils.$testRunnerMethodName(this::$testMethodName, $className.$targetBackend, testDataFilePath$additionalArguments$transformerPostfix);") } } } override fun generateSignature(method: RunTestMethodModel, p: Printer) { - p.print("private void ${method.name}(String testDataFilePath) throws Exception") + val optionalTransformer = if (method.withTransformer) ", ${Function::class.java.canonicalName} transformer" else "" + p.print("private void ${method.name}(String testDataFilePath${optionalTransformer}) throws Exception") } } diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java index 123f56aa060..2e5520bfaf6 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java @@ -60,6 +60,7 @@ import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.nio.file.Path; import java.util.*; +import java.util.function.Function; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -429,7 +430,11 @@ public class KotlinTestUtils { } public static void runTest(@NotNull DoTest test, @NotNull TestCase testCase, @TestDataFile String testDataFile) throws Exception { - runTestImpl(testWithCustomIgnoreDirective(test, TargetBackend.ANY, IGNORE_BACKEND_DIRECTIVE_PREFIX), testCase, testDataFile); + runTestImpl(testWithCustomIgnoreDirective(test, TargetBackend.ANY, IGNORE_BACKEND_DIRECTIVE_PREFIX), testCase, testDataFile, null); + } + + public static void runTest(@NotNull DoTest test, @NotNull TestCase testCase, @TestDataFile String testDataFile, @NotNull Function contentTransformer) throws Exception { + runTestImpl(testWithCustomIgnoreDirective(test, TargetBackend.ANY, IGNORE_BACKEND_DIRECTIVE_PREFIX), testCase, testDataFile, contentTransformer); } public static void runTest(@NotNull TestCase testCase, @NotNull Function0 test) { @@ -454,8 +459,15 @@ public class KotlinTestUtils { runTest0(test, targetBackend, testDataFile); } + public static void runTest( + DoTest test, TargetBackend targetBackend, @TestDataFile String testDataFile, + @NotNull Function contentTransformer + ) throws Exception { + runTest0(test, targetBackend, testDataFile, contentTransformer); + } + public static void runTestWithCustomIgnoreDirective(DoTest test, TargetBackend targetBackend, @TestDataFile String testDataFile, String ignoreDirective) throws Exception { - runTestImpl(testWithCustomIgnoreDirective(test, targetBackend, ignoreDirective), null, testDataFile); + runTestImpl(testWithCustomIgnoreDirective(test, targetBackend, ignoreDirective), null, testDataFile, null); } // In this test runner version, NONE of the parameters are annotated by `TestDataFile`. @@ -467,10 +479,16 @@ public class KotlinTestUtils { // * sometimes, for too common/general names, it shows many variants to navigate // * it adds an additional step for navigation -- you must choose an exact file to navigate public static void runTest0(DoTest test, TargetBackend targetBackend, String testDataFilePath) throws Exception { - runTestImpl(testWithCustomIgnoreDirective(test, targetBackend, IGNORE_BACKEND_DIRECTIVE_PREFIX), null, testDataFilePath); + runTestImpl(testWithCustomIgnoreDirective(test, targetBackend, IGNORE_BACKEND_DIRECTIVE_PREFIX), null, testDataFilePath, null); } - private static void runTestImpl(@NotNull DoTest test, @Nullable TestCase testCase, String testDataFilePath) throws Exception { + public static void runTest0( + DoTest test, TargetBackend targetBackend, String testDataFilePath, @NotNull Function contentTransformer + ) throws Exception { + runTestImpl(testWithCustomIgnoreDirective(test, targetBackend, IGNORE_BACKEND_DIRECTIVE_PREFIX), null, testDataFilePath, contentTransformer); + } + + private static void runTestImpl(@NotNull DoTest test, @Nullable TestCase testCase, String testDataFilePath, @SuppressWarnings("unused") @Nullable Function contentTransformer) throws Exception { if (testCase != null && !isRunTestOverridden(testCase)) { Function0 wrapWithMuteInDatabase = MuteWithDatabaseKt.wrapWithMuteInDatabase(testCase, () -> { try { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 661e2e125ea..4935e2c7dc8 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -15740,6 +15740,10 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); } + private void runTest(String testDataFilePath, java.util.function.Function transformer) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath, transformer); + } + public void testAllFilesPresentInInlineClasses() throws Exception { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/inlineClasses"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); } @@ -15776,7 +15780,7 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes @TestMetadata("boxResultInlineClassOfConstructorCall.kt") public void testBoxResultInlineClassOfConstructorCall() throws Exception { - runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt"); + runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", s -> s.replaceAll("OPTIONAL_JVM_INLINE_ANNOTATION", "@kotlin.jvm.JvmInline")); } @TestMetadata("boxUnboxInlineClassesWithOperatorsGetSet.kt") diff --git a/generators/test-generator/tests/org/jetbrains/kotlin/generators/NewTestGeneratorImpl.kt b/generators/test-generator/tests/org/jetbrains/kotlin/generators/NewTestGeneratorImpl.kt index e813eecdea8..65b966d4c8c 100644 --- a/generators/test-generator/tests/org/jetbrains/kotlin/generators/NewTestGeneratorImpl.kt +++ b/generators/test-generator/tests/org/jetbrains/kotlin/generators/NewTestGeneratorImpl.kt @@ -209,8 +209,8 @@ object NewTestGeneratorImpl : TestGenerator(METHOD_GENERATORS) { var first = true for (methodModel in testMethods) { - if (methodModel is RunTestMethodModel) continue - if (!methodModel.shouldBeGenerated()) continue + if (methodModel is RunTestMethodModel) continue // should also skip its imports + if (!methodModel.shouldBeGenerated()) continue // should also skip its imports if (first) { first = false diff --git a/generators/test-generator/tests/org/jetbrains/kotlin/generators/model/RunTestMethodModel.kt b/generators/test-generator/tests/org/jetbrains/kotlin/generators/model/RunTestMethodModel.kt index 49da9295b40..8998e314743 100644 --- a/generators/test-generator/tests/org/jetbrains/kotlin/generators/model/RunTestMethodModel.kt +++ b/generators/test-generator/tests/org/jetbrains/kotlin/generators/model/RunTestMethodModel.kt @@ -11,7 +11,8 @@ class RunTestMethodModel( val targetBackend: TargetBackend, val testMethodName: String, val testRunnerMethodName: String, - val additionalRunnerArguments: List = emptyList() + val additionalRunnerArguments: List = emptyList(), + val withTransformer: Boolean = false ) : MethodModel { object Kind : MethodModel.Kind() diff --git a/generators/test-generator/tests/org/jetbrains/kotlin/generators/model/SimpleTestClassModel.kt b/generators/test-generator/tests/org/jetbrains/kotlin/generators/model/SimpleTestClassModel.kt index 1cae3199540..b19262d8fca 100644 --- a/generators/test-generator/tests/org/jetbrains/kotlin/generators/model/SimpleTestClassModel.kt +++ b/generators/test-generator/tests/org/jetbrains/kotlin/generators/model/SimpleTestClassModel.kt @@ -117,6 +117,11 @@ class SimpleTestClassModel( } } } + if (result.any { it is WithoutJvmInlineTestMethodModel }) { + val additionalRunner = + RunTestMethodModel(targetBackend, doTestMethodName, testRunnerMethodName, additionalRunnerArguments, withTransformer = true) + result.add(additionalRunner) + } result.sortWith(BY_NAME) result } diff --git a/generators/test-generator/tests/org/jetbrains/kotlin/generators/model/SingleClassTestModel.kt b/generators/test-generator/tests/org/jetbrains/kotlin/generators/model/SingleClassTestModel.kt index cd005e6be25..bee3bc2962b 100644 --- a/generators/test-generator/tests/org/jetbrains/kotlin/generators/model/SingleClassTestModel.kt +++ b/generators/test-generator/tests/org/jetbrains/kotlin/generators/model/SingleClassTestModel.kt @@ -38,6 +38,11 @@ class SingleClassTestModel( } true } + if (result.any { it is WithoutJvmInlineTestMethodModel }) { + val additionalRunner = + RunTestMethodModel(targetBackend, doTestMethodName, testRunnerMethodName, additionalRunnerArguments, withTransformer = true) + result.add(additionalRunner) + } result.sortedWith { o1: MethodModel, o2: MethodModel -> o1.name.compareTo(o2.name, ignoreCase = true) } } diff --git a/generators/test-generator/tests/org/jetbrains/kotlin/generators/util/MethodModelLocator.kt b/generators/test-generator/tests/org/jetbrains/kotlin/generators/util/MethodModelLocator.kt index aaaa4292aa0..08ec8a2948d 100644 --- a/generators/test-generator/tests/org/jetbrains/kotlin/generators/util/MethodModelLocator.kt +++ b/generators/test-generator/tests/org/jetbrains/kotlin/generators/util/MethodModelLocator.kt @@ -10,12 +10,15 @@ import org.jetbrains.kotlin.test.TargetBackend import java.io.File import java.util.regex.Pattern -fun TestEntityModel.containsWithoutJvmInline(backend: TargetBackend): Boolean = backend == TargetBackend.JVM_IR && when (this) { - is ClassModel -> methods.any { it.containsWithoutJvmInline(backend) } || innerTestClasses.any { it.containsWithoutJvmInline(backend) } - is SimpleTestMethodModel -> file.readLines().any { Regex("^\\s*//\\s*WORKS_WHEN_VALUE_CLASS\\s*$").matches(it) } +fun TestEntityModel.containsWithoutJvmInline(): Boolean = when (this) { + is ClassModel -> methods.any { it.containsWithoutJvmInline() } || innerTestClasses.any { it.containsWithoutJvmInline() } + is SimpleTestMethodModel -> file.isFile && file.readLines().any { Regex("^\\s*//\\s*WORKS_WHEN_VALUE_CLASS\\s*$").matches(it) } else -> false } +private fun TargetBackend.isRecursivelyCompatibleWith(targetBackend: TargetBackend): Boolean = + this == targetBackend || this != TargetBackend.ANY && this.compatibleWith.isRecursivelyCompatibleWith(targetBackend) + fun methodModelLocator( rootDir: File, file: File, @@ -33,6 +36,12 @@ fun methodModelLocator( skipIgnored, tags ).let { methodModel -> - if (methodModel.containsWithoutJvmInline(targetBackend)) listOf(true, false).map { WithoutJvmInlineTestMethodModel(methodModel, it) } - else listOf(methodModel) + if (methodModel.containsWithoutJvmInline()) { + val isWithoutAnnotations = when { + targetBackend.isRecursivelyCompatibleWith(TargetBackend.JVM_IR) -> listOf(true, false) + targetBackend.isRecursivelyCompatibleWith(TargetBackend.JVM) -> listOf(true) + else -> listOf(false) + } + isWithoutAnnotations.map { WithoutJvmInlineTestMethodModel(methodModel, it) } + } else listOf(methodModel) } \ 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 79192687d28..ede861035cc 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 @@ -14840,8 +14840,8 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { @Test @TestMetadata("boxResultInlineClassOfConstructorCall.kt") - public void testBoxResultInlineClassOfConstructorCall() throws Exception { - runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt"); + public void testBoxResultInlineClassOfConstructorCall_valueClasses() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", s -> s.replaceAll("OPTIONAL_JVM_INLINE_ANNOTATION", "")); } @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 5cb71228643..472d9c3ac0f 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 @@ -14804,8 +14804,8 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { @Test @TestMetadata("boxResultInlineClassOfConstructorCall.kt") - public void testBoxResultInlineClassOfConstructorCall() throws Exception { - runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt"); + public void testBoxResultInlineClassOfConstructorCall_valueClasses() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", s -> s.replaceAll("OPTIONAL_JVM_INLINE_ANNOTATION", "")); } @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 28bb3d1e476..6abd3186e93 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 @@ -12422,6 +12422,10 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest KotlinTestUtils.runTest0(this::doTest, TargetBackend.WASM, testDataFilePath); } + private void runTest(String testDataFilePath, java.util.function.Function transformer) throws Exception { + KotlinTestUtils.runTest0(this::doTest, TargetBackend.WASM, testDataFilePath, transformer); + } + public void testAllFilesPresentInInlineClasses() throws Exception { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/inlineClasses"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.WASM, true); } @@ -12467,8 +12471,8 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest } @TestMetadata("boxResultInlineClassOfConstructorCall.kt") - public void testBoxResultInlineClassOfConstructorCall() throws Exception { - runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt"); + public void testBoxResultInlineClassOfConstructorCall_valueClasses() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", s -> s.replaceAll("OPTIONAL_JVM_INLINE_ANNOTATION", "")); } @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 f04e36bdf77..3f6e9d0e718 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 @@ -15699,8 +15699,8 @@ public class NativeExtBlackBoxTestGenerated extends AbstractNativeBlackBoxTest { @Test @TestMetadata("boxResultInlineClassOfConstructorCall.kt") - public void testBoxResultInlineClassOfConstructorCall() throws Exception { - runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt"); + public void testBoxResultInlineClassOfConstructorCall_valueClasses() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", s -> s.replaceAll("OPTIONAL_JVM_INLINE_ANNOTATION", "")); } @Test diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativeBlackBoxTest.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativeBlackBoxTest.kt index b95ab5cfe4a..9ee9aa08ddd 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativeBlackBoxTest.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativeBlackBoxTest.kt @@ -15,7 +15,9 @@ import org.junit.jupiter.api.extension.ExtendWith abstract class AbstractNativeBlackBoxTest { internal lateinit var testRunProvider: TestRunProvider - fun runTest(@TestDataFile testDataFilePath: String): Unit = with(testRunProvider) { + @Suppress("UNUSED_PARAMETER") + @JvmOverloads + fun runTest(@TestDataFile testDataFilePath: String, sourceTransformer: (String) -> String = { it }): Unit = with(testRunProvider) { val testDataFile = getAbsoluteFile(testDataFilePath) val testRun = getSingleTestRun(testDataFile) val testRunner = createRunner(testRun)