[Tests] Introduce transformers functions object
This commit is contained in:
+3
-2
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.test.runners.codegen;
|
|||||||
import com.intellij.testFramework.TestDataPath;
|
import com.intellij.testFramework.TestDataPath;
|
||||||
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
||||||
import org.jetbrains.kotlin.test.TargetBackend;
|
import org.jetbrains.kotlin.test.TargetBackend;
|
||||||
|
import org.jetbrains.kotlin.test.runners.TransformersFunctions;
|
||||||
import org.jetbrains.kotlin.test.TestMetadata;
|
import org.jetbrains.kotlin.test.TestMetadata;
|
||||||
import org.junit.jupiter.api.Nested;
|
import org.junit.jupiter.api.Nested;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@@ -19291,13 +19292,13 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
|||||||
@Test
|
@Test
|
||||||
@TestMetadata("boxResultInlineClassOfConstructorCall.kt")
|
@TestMetadata("boxResultInlineClassOfConstructorCall.kt")
|
||||||
public void testBoxResultInlineClassOfConstructorCall() throws Exception {
|
public void testBoxResultInlineClassOfConstructorCall() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", s -> s.replaceAll("OPTIONAL_JVM_INLINE_ANNOTATION", "@kotlin.jvm.JvmInline"));
|
runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions::replaceOptionalJvmInlineAnnotationWithReal);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("boxResultInlineClassOfConstructorCall.kt")
|
@TestMetadata("boxResultInlineClassOfConstructorCall.kt")
|
||||||
public void testBoxResultInlineClassOfConstructorCall_valueClasses() throws Exception {
|
public void testBoxResultInlineClassOfConstructorCall_valueClasses() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", s -> s.replaceAll("OPTIONAL_JVM_INLINE_ANNOTATION", ""));
|
runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions::removeOptionalJvmInlineAnnotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
+2
-1
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.test.runners.codegen;
|
|||||||
import com.intellij.testFramework.TestDataPath;
|
import com.intellij.testFramework.TestDataPath;
|
||||||
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
||||||
import org.jetbrains.kotlin.test.TargetBackend;
|
import org.jetbrains.kotlin.test.TargetBackend;
|
||||||
|
import org.jetbrains.kotlin.test.runners.TransformersFunctions;
|
||||||
import org.jetbrains.kotlin.test.TestMetadata;
|
import org.jetbrains.kotlin.test.TestMetadata;
|
||||||
import org.junit.jupiter.api.Nested;
|
import org.junit.jupiter.api.Nested;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@@ -18907,7 +18908,7 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
@Test
|
@Test
|
||||||
@TestMetadata("boxResultInlineClassOfConstructorCall.kt")
|
@TestMetadata("boxResultInlineClassOfConstructorCall.kt")
|
||||||
public void testBoxResultInlineClassOfConstructorCall() throws Exception {
|
public void testBoxResultInlineClassOfConstructorCall() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", s -> s.replaceAll("OPTIONAL_JVM_INLINE_ANNOTATION", "@kotlin.jvm.JvmInline"));
|
runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions::replaceOptionalJvmInlineAnnotationWithReal);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
+3
-2
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.test.runners.codegen;
|
|||||||
import com.intellij.testFramework.TestDataPath;
|
import com.intellij.testFramework.TestDataPath;
|
||||||
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
||||||
import org.jetbrains.kotlin.test.TargetBackend;
|
import org.jetbrains.kotlin.test.TargetBackend;
|
||||||
|
import org.jetbrains.kotlin.test.runners.TransformersFunctions;
|
||||||
import org.jetbrains.kotlin.test.TestMetadata;
|
import org.jetbrains.kotlin.test.TestMetadata;
|
||||||
import org.junit.jupiter.api.Nested;
|
import org.junit.jupiter.api.Nested;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@@ -19291,13 +19292,13 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
@Test
|
@Test
|
||||||
@TestMetadata("boxResultInlineClassOfConstructorCall.kt")
|
@TestMetadata("boxResultInlineClassOfConstructorCall.kt")
|
||||||
public void testBoxResultInlineClassOfConstructorCall() throws Exception {
|
public void testBoxResultInlineClassOfConstructorCall() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", s -> s.replaceAll("OPTIONAL_JVM_INLINE_ANNOTATION", "@kotlin.jvm.JvmInline"));
|
runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions::replaceOptionalJvmInlineAnnotationWithReal);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("boxResultInlineClassOfConstructorCall.kt")
|
@TestMetadata("boxResultInlineClassOfConstructorCall.kt")
|
||||||
public void testBoxResultInlineClassOfConstructorCall_valueClasses() throws Exception {
|
public void testBoxResultInlineClassOfConstructorCall_valueClasses() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", s -> s.replaceAll("OPTIONAL_JVM_INLINE_ANNOTATION", ""));
|
runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions::removeOptionalJvmInlineAnnotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.test.runners
|
||||||
|
|
||||||
|
object TransformersFunctions {
|
||||||
|
@JvmStatic
|
||||||
|
fun replaceOptionalJvmInlineAnnotationWithReal(source: String): String {
|
||||||
|
return source.replace("OPTIONAL_JVM_INLINE_ANNOTATION", "@JvmInline")
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun removeOptionalJvmInlineAnnotation(source: String): String {
|
||||||
|
return source.replace("OPTIONAL_JVM_INLINE_ANNOTATION", "")
|
||||||
|
}
|
||||||
|
}
|
||||||
+6
-1
@@ -124,7 +124,12 @@ private class TestGeneratorImplInstance(
|
|||||||
p.println("import " + KtTestUtil::class.java.canonicalName + ";")
|
p.println("import " + KtTestUtil::class.java.canonicalName + ";")
|
||||||
|
|
||||||
for (clazz in testClassModels.flatMapTo(mutableSetOf()) { classModel -> classModel.imports }) {
|
for (clazz in testClassModels.flatMapTo(mutableSetOf()) { classModel -> classModel.imports }) {
|
||||||
p.println("import ${clazz.name};")
|
val realName = when (clazz) {
|
||||||
|
TransformingTestMethodModel.TransformerFunctionsClassPlaceHolder::class.java ->
|
||||||
|
"org.jetbrains.kotlin.test.runners.TransformersFunctions"
|
||||||
|
else -> clazz.name
|
||||||
|
}
|
||||||
|
p.println("import $realName;")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (suiteClassPackage != baseTestClassPackage) {
|
if (suiteClassPackage != baseTestClassPackage) {
|
||||||
|
|||||||
+2
-1
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
|
|||||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||||
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
||||||
import org.jetbrains.kotlin.test.TargetBackend;
|
import org.jetbrains.kotlin.test.TargetBackend;
|
||||||
|
import org.jetbrains.kotlin.test.runners.TransformersFunctions;
|
||||||
import org.jetbrains.kotlin.test.TestMetadata;
|
import org.jetbrains.kotlin.test.TestMetadata;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
@@ -15780,7 +15781,7 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
|
|
||||||
@TestMetadata("boxResultInlineClassOfConstructorCall.kt")
|
@TestMetadata("boxResultInlineClassOfConstructorCall.kt")
|
||||||
public void testBoxResultInlineClassOfConstructorCall() throws Exception {
|
public void testBoxResultInlineClassOfConstructorCall() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", s -> s.replaceAll("OPTIONAL_JVM_INLINE_ANNOTATION", "@kotlin.jvm.JvmInline"));
|
runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions::replaceOptionalJvmInlineAnnotationWithReal);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("boxUnboxInlineClassesWithOperatorsGetSet.kt")
|
@TestMetadata("boxUnboxInlineClassesWithOperatorsGetSet.kt")
|
||||||
|
|||||||
+9
-4
@@ -129,7 +129,12 @@ object NewTestGeneratorImpl : TestGenerator(METHOD_GENERATORS) {
|
|||||||
p.println("import ${KtTestUtil::class.java.canonicalName};")
|
p.println("import ${KtTestUtil::class.java.canonicalName};")
|
||||||
|
|
||||||
for (clazz in testClassModels.flatMapTo(mutableSetOf()) { classModel -> classModel.imports }) {
|
for (clazz in testClassModels.flatMapTo(mutableSetOf()) { classModel -> classModel.imports }) {
|
||||||
p.println("import ${clazz.name};")
|
val realName = when (clazz) {
|
||||||
|
TransformingTestMethodModel.TransformerFunctionsClassPlaceHolder::class.java ->
|
||||||
|
"org.jetbrains.kotlin.test.runners.TransformersFunctions"
|
||||||
|
else -> clazz.name
|
||||||
|
}
|
||||||
|
p.println("import $realName;")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (suiteClassPackage != baseTestClassPackage) {
|
if (suiteClassPackage != baseTestClassPackage) {
|
||||||
@@ -208,7 +213,7 @@ object NewTestGeneratorImpl : TestGenerator(METHOD_GENERATORS) {
|
|||||||
|
|
||||||
var first = true
|
var first = true
|
||||||
|
|
||||||
val transformers = testClassModel.predefinedTransformers(false)
|
val transformers = testClassModel.predefinedNativeTransformers(false)
|
||||||
|
|
||||||
if (transformers.isNotEmpty()) {
|
if (transformers.isNotEmpty()) {
|
||||||
p.println("public ${testClassModel.name}() {")
|
p.println("public ${testClassModel.name}() {")
|
||||||
@@ -286,8 +291,8 @@ object NewTestGeneratorImpl : TestGenerator(METHOD_GENERATORS) {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun TestClassModel.predefinedTransformers(recursive: Boolean): List<Pair<String, String>> =
|
private fun TestClassModel.predefinedNativeTransformers(recursive: Boolean): List<Pair<String, String>> =
|
||||||
methods.mapNotNull { method ->
|
methods.mapNotNull { method ->
|
||||||
(method as? TransformingTestMethodModel)?.takeIf { it.isNative }?.let { it.source.file.path to it.transformer }
|
(method as? TransformingTestMethodModel)?.takeIf { it.isNative }?.let { it.source.file.path to it.transformer }
|
||||||
} + if (recursive) innerTestClasses.flatMap { it.predefinedTransformers(recursive) } else listOf()
|
} + if (recursive) innerTestClasses.flatMap { it.predefinedNativeTransformers(recursive) } else listOf()
|
||||||
}
|
}
|
||||||
|
|||||||
+3
@@ -16,8 +16,11 @@ abstract class TransformingTestMethodModel(val source: SimpleTestMethodModel, va
|
|||||||
override val tags: List<String>
|
override val tags: List<String>
|
||||||
get() = source.tags
|
get() = source.tags
|
||||||
|
|
||||||
|
object TransformerFunctionsClassPlaceHolder
|
||||||
object Kind : MethodModel.Kind()
|
object Kind : MethodModel.Kind()
|
||||||
|
|
||||||
|
override fun imports(): Collection<Class<*>> = super.imports() + TransformerFunctionsClassPlaceHolder::class.java
|
||||||
|
|
||||||
internal val isNative
|
internal val isNative
|
||||||
get() = source.targetBackend in listOf(TargetBackend.NATIVE, TargetBackend.ANY)
|
get() = source.targetBackend in listOf(TargetBackend.NATIVE, TargetBackend.ANY)
|
||||||
// Native tests load sources before runTest call if more than 1 test is called, so we need to register it before.
|
// Native tests load sources before runTest call if more than 1 test is called, so we need to register it before.
|
||||||
|
|||||||
+2
-1
@@ -10,7 +10,8 @@ class WithoutJvmInlineTestMethodModel(
|
|||||||
val withAnnotation: Boolean
|
val withAnnotation: Boolean
|
||||||
) : TransformingTestMethodModel(
|
) : TransformingTestMethodModel(
|
||||||
source,
|
source,
|
||||||
transformer = "s -> s.replaceAll(\"OPTIONAL_JVM_INLINE_ANNOTATION\", \"${if (withAnnotation) "@kotlin.jvm.JvmInline" else ""}\")"
|
transformer = "TransformersFunctions::" +
|
||||||
|
if (withAnnotation) "replaceOptionalJvmInlineAnnotationWithReal" else "removeOptionalJvmInlineAnnotation"
|
||||||
) {
|
) {
|
||||||
override val name: String = source.name + if (withAnnotation) "" else "_valueClasses"
|
override val name: String = source.name + if (withAnnotation) "" else "_valueClasses"
|
||||||
}
|
}
|
||||||
+2
-1
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.js.test;
|
|||||||
import com.intellij.testFramework.TestDataPath;
|
import com.intellij.testFramework.TestDataPath;
|
||||||
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
||||||
import org.jetbrains.kotlin.test.TargetBackend;
|
import org.jetbrains.kotlin.test.TargetBackend;
|
||||||
|
import org.jetbrains.kotlin.test.runners.TransformersFunctions;
|
||||||
import org.jetbrains.kotlin.test.TestMetadata;
|
import org.jetbrains.kotlin.test.TestMetadata;
|
||||||
import org.junit.jupiter.api.Nested;
|
import org.junit.jupiter.api.Nested;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@@ -14841,7 +14842,7 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
|||||||
@Test
|
@Test
|
||||||
@TestMetadata("boxResultInlineClassOfConstructorCall.kt")
|
@TestMetadata("boxResultInlineClassOfConstructorCall.kt")
|
||||||
public void testBoxResultInlineClassOfConstructorCall_valueClasses() throws Exception {
|
public void testBoxResultInlineClassOfConstructorCall_valueClasses() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", s -> s.replaceAll("OPTIONAL_JVM_INLINE_ANNOTATION", ""));
|
runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions::removeOptionalJvmInlineAnnotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
+2
-1
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.js.test.ir;
|
|||||||
import com.intellij.testFramework.TestDataPath;
|
import com.intellij.testFramework.TestDataPath;
|
||||||
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
||||||
import org.jetbrains.kotlin.test.TargetBackend;
|
import org.jetbrains.kotlin.test.TargetBackend;
|
||||||
|
import org.jetbrains.kotlin.test.runners.TransformersFunctions;
|
||||||
import org.jetbrains.kotlin.test.TestMetadata;
|
import org.jetbrains.kotlin.test.TestMetadata;
|
||||||
import org.junit.jupiter.api.Nested;
|
import org.junit.jupiter.api.Nested;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@@ -14805,7 +14806,7 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
|||||||
@Test
|
@Test
|
||||||
@TestMetadata("boxResultInlineClassOfConstructorCall.kt")
|
@TestMetadata("boxResultInlineClassOfConstructorCall.kt")
|
||||||
public void testBoxResultInlineClassOfConstructorCall_valueClasses() throws Exception {
|
public void testBoxResultInlineClassOfConstructorCall_valueClasses() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", s -> s.replaceAll("OPTIONAL_JVM_INLINE_ANNOTATION", ""));
|
runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions::removeOptionalJvmInlineAnnotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
+2
-1
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
|
|||||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||||
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
||||||
import org.jetbrains.kotlin.test.TargetBackend;
|
import org.jetbrains.kotlin.test.TargetBackend;
|
||||||
|
import org.jetbrains.kotlin.test.runners.TransformersFunctions;
|
||||||
import org.jetbrains.kotlin.test.TestMetadata;
|
import org.jetbrains.kotlin.test.TestMetadata;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
@@ -12472,7 +12473,7 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
|
|||||||
|
|
||||||
@TestMetadata("boxResultInlineClassOfConstructorCall.kt")
|
@TestMetadata("boxResultInlineClassOfConstructorCall.kt")
|
||||||
public void testBoxResultInlineClassOfConstructorCall_valueClasses() throws Exception {
|
public void testBoxResultInlineClassOfConstructorCall_valueClasses() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", s -> s.replaceAll("OPTIONAL_JVM_INLINE_ANNOTATION", ""));
|
runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", TransformersFunctions::removeOptionalJvmInlineAnnotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("boxUnboxInlineClassesWithOperatorsGetSet.kt")
|
@TestMetadata("boxUnboxInlineClassesWithOperatorsGetSet.kt")
|
||||||
|
|||||||
Reference in New Issue
Block a user