[Tests] Generate runTest with transformer parameter + example
This commit is contained in:
+3
-2
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.generators
|
||||
import org.jetbrains.kotlin.generators.impl.SimpleTestClassModelTestAllFilesPresentMethodGenerator
|
||||
import org.jetbrains.kotlin.generators.impl.SimpleTestMethodGenerator
|
||||
import org.jetbrains.kotlin.generators.impl.SingleClassTestModelAllFilesPresentedMethodGenerator
|
||||
import org.jetbrains.kotlin.generators.impl.WithoutJvmInlineTestMethodGenerator
|
||||
import org.jetbrains.kotlin.generators.model.*
|
||||
import org.jetbrains.kotlin.generators.util.GeneratorsFileUtil
|
||||
import org.jetbrains.kotlin.test.TestMetadata
|
||||
@@ -18,14 +19,14 @@ import org.junit.jupiter.api.Tag
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.util.*
|
||||
|
||||
private const val TEST_GENERATOR_NAME = "GenerateNewCompilerTests.kt"
|
||||
|
||||
private val METHOD_GENERATORS = listOf(
|
||||
SimpleTestClassModelTestAllFilesPresentMethodGenerator,
|
||||
SimpleTestMethodGenerator,
|
||||
SingleClassTestModelAllFilesPresentedMethodGenerator
|
||||
SingleClassTestModelAllFilesPresentedMethodGenerator,
|
||||
WithoutJvmInlineTestMethodGenerator,
|
||||
)
|
||||
|
||||
object NewTestGeneratorImpl : TestGenerator(METHOD_GENERATORS) {
|
||||
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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.generators.impl
|
||||
|
||||
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.WithoutJvmInlineTestMethodModel
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil
|
||||
import org.jetbrains.kotlin.utils.Printer
|
||||
|
||||
object WithoutJvmInlineTestMethodGenerator : MethodGenerator<WithoutJvmInlineTestMethodModel>() {
|
||||
|
||||
override val kind: MethodModel.Kind
|
||||
get() = WithoutJvmInlineTestMethodModel.Kind
|
||||
|
||||
override fun generateSignature(method: WithoutJvmInlineTestMethodModel, p: Printer) {
|
||||
generateDefaultSignature(method, p)
|
||||
}
|
||||
|
||||
override fun generateBody(method: WithoutJvmInlineTestMethodModel, p: Printer) {
|
||||
with(method) {
|
||||
val filePath = KtTestUtil.getFilePath(source.file) + if (source.file.isDirectory) "/" else ""
|
||||
p.println("${RunTestMethodModel.METHOD_NAME}(\"$filePath\", s -> s.replaceAll(\"@(kotlin.jvm.)?JvmInline\", \"\"));")
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
-13
@@ -8,10 +8,10 @@ import com.intellij.openapi.util.io.FileUtil
|
||||
import org.jetbrains.kotlin.generators.util.TestGeneratorUtil.fileNameToJavaIdentifier
|
||||
import org.jetbrains.kotlin.generators.util.extractTagsFromDirectory
|
||||
import org.jetbrains.kotlin.generators.util.extractTagsFromTestFile
|
||||
import org.jetbrains.kotlin.generators.util.methodModelLocator
|
||||
import org.jetbrains.kotlin.test.TargetBackend
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
import java.util.regex.Pattern
|
||||
|
||||
class SimpleTestClassModel(
|
||||
@@ -87,16 +87,14 @@ class SimpleTestClassModel(
|
||||
|
||||
override val methods: Collection<MethodModel> by lazy {
|
||||
if (!rootFile.isDirectory) {
|
||||
return@lazy listOf(
|
||||
SimpleTestMethodModel(
|
||||
rootFile,
|
||||
rootFile,
|
||||
filenamePattern,
|
||||
checkFilenameStartsLowerCase,
|
||||
targetBackend,
|
||||
skipIgnored,
|
||||
extractTagsFromTestFile(rootFile)
|
||||
)
|
||||
return@lazy methodModelLocator(
|
||||
rootFile,
|
||||
rootFile,
|
||||
filenamePattern,
|
||||
checkFilenameStartsLowerCase,
|
||||
targetBackend,
|
||||
skipIgnored,
|
||||
extractTagsFromTestFile(rootFile)
|
||||
)
|
||||
}
|
||||
val result = mutableListOf<MethodModel>()
|
||||
@@ -110,8 +108,8 @@ class SimpleTestClassModel(
|
||||
if (file.isDirectory && excludeParentDirs && dirHasSubDirs(file)) {
|
||||
continue
|
||||
}
|
||||
result.add(
|
||||
SimpleTestMethodModel(
|
||||
result.addAll(
|
||||
methodModelLocator(
|
||||
rootFile, file, filenamePattern,
|
||||
checkFilenameStartsLowerCase, targetBackend, skipIgnored, extractTagsFromTestFile(file)
|
||||
)
|
||||
|
||||
+3
-5
@@ -5,10 +5,10 @@
|
||||
package org.jetbrains.kotlin.generators.model
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import org.jetbrains.kotlin.generators.util.methodModelLocator
|
||||
import org.jetbrains.kotlin.test.TargetBackend
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
import java.util.regex.Pattern
|
||||
|
||||
class SingleClassTestModel(
|
||||
@@ -45,10 +45,8 @@ class SingleClassTestModel(
|
||||
get() = emptyList()
|
||||
|
||||
private fun getTestMethodsFromFile(file: File): Collection<MethodModel> {
|
||||
return listOf(
|
||||
SimpleTestMethodModel(
|
||||
rootFile, file, filenamePattern, checkFilenameStartsLowerCase, targetBackend, skipIgnored, tags = emptyList()
|
||||
)
|
||||
return methodModelLocator(
|
||||
rootFile, file, filenamePattern, checkFilenameStartsLowerCase, targetBackend, skipIgnored, tags = emptyList()
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 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.generators.model
|
||||
|
||||
class WithoutJvmInlineTestMethodModel(
|
||||
val source: SimpleTestMethodModel
|
||||
) : MethodModel {
|
||||
object Kind : MethodModel.Kind()
|
||||
|
||||
override val kind: MethodModel.Kind
|
||||
get() = Kind
|
||||
override val name: String
|
||||
get() = "${source.name}WithoutJvmInlineAnnotation"
|
||||
override val dataString: String
|
||||
get() = source.dataString
|
||||
override val tags: List<String>
|
||||
get() = source.tags
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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.generators.util
|
||||
|
||||
import org.jetbrains.kotlin.generators.model.*
|
||||
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_WITHOUT_JVM_INLINE\\s*$").matches(it) }
|
||||
else -> false
|
||||
}
|
||||
|
||||
fun methodModelLocator(
|
||||
rootDir: File,
|
||||
file: File,
|
||||
filenamePattern: Pattern,
|
||||
checkFilenameStartsLowerCase: Boolean?,
|
||||
targetBackend: TargetBackend,
|
||||
skipIgnored: Boolean,
|
||||
tags: List<String>
|
||||
): List<MethodModel> = SimpleTestMethodModel(
|
||||
rootDir,
|
||||
file,
|
||||
filenamePattern,
|
||||
checkFilenameStartsLowerCase,
|
||||
targetBackend,
|
||||
skipIgnored,
|
||||
tags
|
||||
).let { methodModel ->
|
||||
listOf(methodModel) + if (methodModel.containsWithoutJvmInline(targetBackend)) listOf(WithoutJvmInlineTestMethodModel(methodModel)) else emptyList()
|
||||
}
|
||||
Reference in New Issue
Block a user