[Tests] All tests correct generation

This commit is contained in:
Evgeniy.Zhelenskiy
2021-12-02 23:08:35 +03:00
parent f0af2487c7
commit e62c6e3eac
14 changed files with 78 additions and 27 deletions
@@ -18907,7 +18907,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"); runTest("compiler/testData/codegen/box/inlineClasses/boxResultInlineClassOfConstructorCall.kt", s -> s.replaceAll("OPTIONAL_JVM_INLINE_ANNOTATION", "@kotlin.jvm.JvmInline"));
} }
@Test @Test
@@ -5,11 +5,12 @@
package org.jetbrains.kotlin.generators.impl package org.jetbrains.kotlin.generators.impl
import org.jetbrains.kotlin.generators.model.MethodModel
import org.jetbrains.kotlin.generators.MethodGenerator import org.jetbrains.kotlin.generators.MethodGenerator
import org.jetbrains.kotlin.generators.model.MethodModel
import org.jetbrains.kotlin.generators.model.RunTestMethodModel import org.jetbrains.kotlin.generators.model.RunTestMethodModel
import org.jetbrains.kotlin.test.TargetBackend import org.jetbrains.kotlin.test.TargetBackend
import org.jetbrains.kotlin.utils.Printer import org.jetbrains.kotlin.utils.Printer
import java.util.function.Function
object RunTestMethodGenerator : MethodGenerator<RunTestMethodModel>() { object RunTestMethodGenerator : MethodGenerator<RunTestMethodModel>() {
override val kind: MethodModel.Kind override val kind: MethodModel.Kind
@@ -17,19 +18,21 @@ object RunTestMethodGenerator : MethodGenerator<RunTestMethodModel>() {
override fun generateBody(method: RunTestMethodModel, p: Printer) { override fun generateBody(method: RunTestMethodModel, p: Printer) {
with(method) { with(method) {
val transformerPostfix = if (method.withTransformer) ", transformer" else ""
if (!isWithTargetBackend()) { if (!isWithTargetBackend()) {
p.println("KotlinTestUtils.${method.testRunnerMethodName}(this::$testMethodName, this, testDataFilePath);") p.println("KotlinTestUtils.${method.testRunnerMethodName}(this::$testMethodName, this, testDataFilePath$transformerPostfix);")
} else { } else {
val className = TargetBackend::class.java.simpleName val className = TargetBackend::class.java.simpleName
val additionalArguments = if (additionalRunnerArguments.isNotEmpty()) val additionalArguments = if (additionalRunnerArguments.isNotEmpty())
additionalRunnerArguments.joinToString(separator = ", ", prefix = ", ") additionalRunnerArguments.joinToString(separator = ", ", prefix = ", ")
else "" 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) { 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}<String, String> transformer" else ""
p.print("private void ${method.name}(String testDataFilePath${optionalTransformer}) throws Exception")
} }
} }
@@ -60,6 +60,7 @@ import java.lang.annotation.Annotation;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.*; import java.util.*;
import java.util.function.Function;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; 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 { 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<String, String> contentTransformer) throws Exception {
runTestImpl(testWithCustomIgnoreDirective(test, TargetBackend.ANY, IGNORE_BACKEND_DIRECTIVE_PREFIX), testCase, testDataFile, contentTransformer);
} }
public static void runTest(@NotNull TestCase testCase, @NotNull Function0<Unit> test) { public static void runTest(@NotNull TestCase testCase, @NotNull Function0<Unit> test) {
@@ -454,8 +459,15 @@ public class KotlinTestUtils {
runTest0(test, targetBackend, testDataFile); runTest0(test, targetBackend, testDataFile);
} }
public static void runTest(
DoTest test, TargetBackend targetBackend, @TestDataFile String testDataFile,
@NotNull Function<String, String> contentTransformer
) throws Exception {
runTest0(test, targetBackend, testDataFile, contentTransformer);
}
public static void runTestWithCustomIgnoreDirective(DoTest test, TargetBackend targetBackend, @TestDataFile String testDataFile, String ignoreDirective) throws Exception { 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`. // 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 // * 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 // * 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 { 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<String, String> 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<String, String> contentTransformer) throws Exception {
if (testCase != null && !isRunTestOverridden(testCase)) { if (testCase != null && !isRunTestOverridden(testCase)) {
Function0<Unit> wrapWithMuteInDatabase = MuteWithDatabaseKt.wrapWithMuteInDatabase(testCase, () -> { Function0<Unit> wrapWithMuteInDatabase = MuteWithDatabaseKt.wrapWithMuteInDatabase(testCase, () -> {
try { try {
@@ -15740,6 +15740,10 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath);
} }
private void runTest(String testDataFilePath, java.util.function.Function<String, String> transformer) throws Exception {
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath, transformer);
}
public void testAllFilesPresentInInlineClasses() throws Exception { public void testAllFilesPresentInInlineClasses() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/inlineClasses"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); 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") @TestMetadata("boxResultInlineClassOfConstructorCall.kt")
public void testBoxResultInlineClassOfConstructorCall() throws Exception { 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") @TestMetadata("boxUnboxInlineClassesWithOperatorsGetSet.kt")
@@ -209,8 +209,8 @@ object NewTestGeneratorImpl : TestGenerator(METHOD_GENERATORS) {
var first = true var first = true
for (methodModel in testMethods) { for (methodModel in testMethods) {
if (methodModel is RunTestMethodModel) continue if (methodModel is RunTestMethodModel) continue // should also skip its imports
if (!methodModel.shouldBeGenerated()) continue if (!methodModel.shouldBeGenerated()) continue // should also skip its imports
if (first) { if (first) {
first = false first = false
@@ -11,7 +11,8 @@ class RunTestMethodModel(
val targetBackend: TargetBackend, val targetBackend: TargetBackend,
val testMethodName: String, val testMethodName: String,
val testRunnerMethodName: String, val testRunnerMethodName: String,
val additionalRunnerArguments: List<String> = emptyList() val additionalRunnerArguments: List<String> = emptyList(),
val withTransformer: Boolean = false
) : MethodModel { ) : MethodModel {
object Kind : MethodModel.Kind() object Kind : MethodModel.Kind()
@@ -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.sortWith(BY_NAME)
result result
} }
@@ -38,6 +38,11 @@ class SingleClassTestModel(
} }
true 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) } result.sortedWith { o1: MethodModel, o2: MethodModel -> o1.name.compareTo(o2.name, ignoreCase = true) }
} }
@@ -10,12 +10,15 @@ import org.jetbrains.kotlin.test.TargetBackend
import java.io.File import java.io.File
import java.util.regex.Pattern import java.util.regex.Pattern
fun TestEntityModel.containsWithoutJvmInline(backend: TargetBackend): Boolean = backend == TargetBackend.JVM_IR && when (this) { fun TestEntityModel.containsWithoutJvmInline(): Boolean = when (this) {
is ClassModel -> methods.any { it.containsWithoutJvmInline(backend) } || innerTestClasses.any { it.containsWithoutJvmInline(backend) } is ClassModel -> methods.any { it.containsWithoutJvmInline() } || innerTestClasses.any { it.containsWithoutJvmInline() }
is SimpleTestMethodModel -> file.readLines().any { Regex("^\\s*//\\s*WORKS_WHEN_VALUE_CLASS\\s*$").matches(it) } is SimpleTestMethodModel -> file.isFile && file.readLines().any { Regex("^\\s*//\\s*WORKS_WHEN_VALUE_CLASS\\s*$").matches(it) }
else -> false else -> false
} }
private fun TargetBackend.isRecursivelyCompatibleWith(targetBackend: TargetBackend): Boolean =
this == targetBackend || this != TargetBackend.ANY && this.compatibleWith.isRecursivelyCompatibleWith(targetBackend)
fun methodModelLocator( fun methodModelLocator(
rootDir: File, rootDir: File,
file: File, file: File,
@@ -33,6 +36,12 @@ fun methodModelLocator(
skipIgnored, skipIgnored,
tags tags
).let { methodModel -> ).let { methodModel ->
if (methodModel.containsWithoutJvmInline(targetBackend)) listOf(true, false).map { WithoutJvmInlineTestMethodModel(methodModel, it) } if (methodModel.containsWithoutJvmInline()) {
else listOf(methodModel) 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)
} }
@@ -14840,8 +14840,8 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
@Test @Test
@TestMetadata("boxResultInlineClassOfConstructorCall.kt") @TestMetadata("boxResultInlineClassOfConstructorCall.kt")
public void testBoxResultInlineClassOfConstructorCall() throws Exception { public void testBoxResultInlineClassOfConstructorCall_valueClasses() 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", ""));
} }
@Test @Test
@@ -14804,8 +14804,8 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
@Test @Test
@TestMetadata("boxResultInlineClassOfConstructorCall.kt") @TestMetadata("boxResultInlineClassOfConstructorCall.kt")
public void testBoxResultInlineClassOfConstructorCall() throws Exception { public void testBoxResultInlineClassOfConstructorCall_valueClasses() 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", ""));
} }
@Test @Test
@@ -12422,6 +12422,10 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
KotlinTestUtils.runTest0(this::doTest, TargetBackend.WASM, testDataFilePath); KotlinTestUtils.runTest0(this::doTest, TargetBackend.WASM, testDataFilePath);
} }
private void runTest(String testDataFilePath, java.util.function.Function<String, String> transformer) throws Exception {
KotlinTestUtils.runTest0(this::doTest, TargetBackend.WASM, testDataFilePath, transformer);
}
public void testAllFilesPresentInInlineClasses() throws Exception { public void testAllFilesPresentInInlineClasses() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/inlineClasses"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.WASM, true); 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") @TestMetadata("boxResultInlineClassOfConstructorCall.kt")
public void testBoxResultInlineClassOfConstructorCall() throws Exception { public void testBoxResultInlineClassOfConstructorCall_valueClasses() 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", ""));
} }
@TestMetadata("boxUnboxInlineClassesWithOperatorsGetSet.kt") @TestMetadata("boxUnboxInlineClassesWithOperatorsGetSet.kt")
@@ -15699,8 +15699,8 @@ public class NativeExtBlackBoxTestGenerated extends AbstractNativeBlackBoxTest {
@Test @Test
@TestMetadata("boxResultInlineClassOfConstructorCall.kt") @TestMetadata("boxResultInlineClassOfConstructorCall.kt")
public void testBoxResultInlineClassOfConstructorCall() throws Exception { public void testBoxResultInlineClassOfConstructorCall_valueClasses() 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", ""));
} }
@Test @Test
@@ -15,7 +15,9 @@ import org.junit.jupiter.api.extension.ExtendWith
abstract class AbstractNativeBlackBoxTest { abstract class AbstractNativeBlackBoxTest {
internal lateinit var testRunProvider: TestRunProvider 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 testDataFile = getAbsoluteFile(testDataFilePath)
val testRun = getSingleTestRun(testDataFile) val testRun = getSingleTestRun(testDataFile)
val testRunner = createRunner(testRun) val testRunner = createRunner(testRun)