[TEST-GEN] Extract run of TestGenerator to top of test generation DSL

This commit is contained in:
Dmitriy Novozhilov
2020-11-09 12:10:00 +03:00
parent 2a73aaba4d
commit 380e8a3814
10 changed files with 47 additions and 32 deletions
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.generators.tests.generator
import junit.framework.TestCase
import org.jetbrains.kotlin.generators.tests.generator.InconsistencyChecker.Companion.hasDryRunArg
import org.jetbrains.kotlin.generators.tests.generator.InconsistencyChecker.Companion.inconsistencyChecker
import org.jetbrains.kotlin.generators.tests.generator.generators.TestGenerator
import org.jetbrains.kotlin.generators.tests.generator.generators.impl.*
import org.jetbrains.kotlin.test.TargetBackend
import java.io.File
@@ -21,8 +20,11 @@ class TestGroup(
val testRunnerMethodName: String,
val additionalRunnerArguments: List<String> = emptyList(),
val annotations: List<AnnotationModel> = emptyList(),
private val dryRun: Boolean = false
) {
private val _testClasses: MutableList<TestClass> = mutableListOf()
val testClasses: List<TestClass>
get() = _testClasses
inline fun <reified T : TestCase> testClass(
suiteTestClassName: String = getDefaultSuiteTestClassName(T::class.java.simpleName),
useJunit4: Boolean = false,
@@ -39,11 +41,7 @@ class TestGroup(
annotations: List<AnnotationModel> = emptyList(),
init: TestClass.() -> Unit
) {
val testClass = TestClass(baseTestClassName, suiteTestClassName, useJunit4, annotations).apply(init)
val (changed, testSourceFilePath) = TestGeneratorImpl.generateAndSave(testClass, dryRun)
if (changed) {
inconsistencyChecker(dryRun).add(testSourceFilePath)
}
_testClasses += TestClass(baseTestClassName, suiteTestClassName, useJunit4, annotations).apply(init)
}
inner class TestClass(
@@ -99,20 +97,38 @@ class TestGroup(
}
fun testGroupSuite(
init: TestGroupSuite.() -> Unit
): TestGroupSuite {
return TestGroupSuite().apply(init)
}
fun generateTestGroupSuite(
args: Array<String>,
init: TestGroupSuite.() -> Unit
) {
testGroupSuite(hasDryRunArg(args), init)
generateTestGroupSuite(hasDryRunArg(args), init)
}
fun testGroupSuite(
fun generateTestGroupSuite(
dryRun: Boolean = false,
init: TestGroupSuite.() -> Unit
) {
TestGroupSuite(dryRun).init()
val suite = testGroupSuite(init)
for (testGroup in suite.testGroups) {
for (testClass in testGroup.testClasses) {
val (changed, testSourceFilePath) = TestGeneratorImpl.generateAndSave(testClass, dryRun)
if (changed) {
inconsistencyChecker(dryRun).add(testSourceFilePath)
}
}
}
}
class TestGroupSuite(private val dryRun: Boolean) {
class TestGroupSuite {
private val _testGroups = mutableListOf<TestGroup>()
val testGroups: List<TestGroup>
get() = _testGroups
fun testGroup(
testsRoot: String,
testDataRoot: String,
@@ -120,13 +136,12 @@ class TestGroupSuite(private val dryRun: Boolean) {
additionalRunnerArguments: List<String> = emptyList(),
init: TestGroup.() -> Unit
) {
TestGroup(
_testGroups += TestGroup(
testsRoot,
testDataRoot,
testRunnerMethodName,
additionalRunnerArguments,
dryRun = dryRun
).init()
).apply(init)
}
}
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.formatter.AbstractFormatterTest
import org.jetbrains.kotlin.formatter.AbstractTypingIndentationTestBase
import org.jetbrains.kotlin.generators.tests.generator.TestGroup
import org.jetbrains.kotlin.generators.tests.generator.muteExtraSuffix
import org.jetbrains.kotlin.generators.tests.generator.testGroupSuite
import org.jetbrains.kotlin.generators.tests.generator.generateTestGroupSuite
import org.jetbrains.kotlin.generators.util.KT_OR_KTS
import org.jetbrains.kotlin.generators.util.KT_OR_KTS_WITHOUT_DOTS_IN_NAME
import org.jetbrains.kotlin.generators.util.KT_WITHOUT_DOTS_IN_NAME
@@ -195,7 +195,7 @@ import org.jetbrains.kotlinx.serialization.AbstractSerializationPluginDiagnostic
fun main(args: Array<String>) {
System.setProperty("java.awt.headless", "true")
testGroupSuite(args) {
generateTestGroupSuite(args) {
testGroup("idea/jvm-debugger/jvm-debugger-test/test", "idea/jvm-debugger/jvm-debugger-test/testData") {
testClass<AbstractKotlinSteppingTest> {
model(
@@ -31,7 +31,7 @@ import org.jetbrains.kotlin.formatter.AbstractFormatterTest
import org.jetbrains.kotlin.formatter.AbstractTypingIndentationTestBase
import org.jetbrains.kotlin.generators.tests.generator.TestGroup
import org.jetbrains.kotlin.generators.tests.generator.muteExtraSuffix
import org.jetbrains.kotlin.generators.tests.generator.testGroupSuite
import org.jetbrains.kotlin.generators.tests.generator.generateTestGroupSuite
import org.jetbrains.kotlin.generators.util.KT_OR_KTS
import org.jetbrains.kotlin.generators.util.KT_OR_KTS_WITHOUT_DOTS_IN_NAME
import org.jetbrains.kotlin.generators.util.KT_WITHOUT_DOTS_IN_NAME
@@ -167,7 +167,7 @@ import org.jetbrains.kotlinx.serialization.AbstractSerializationIrBytecodeListin
fun main(args: Array<String>) {
System.setProperty("java.awt.headless", "true")
testGroupSuite(args) {
generateTestGroupSuite(args) {
testGroup("idea/jvm-debugger/jvm-debugger-test/test", "idea/jvm-debugger/jvm-debugger-test/testData") {
testClass<AbstractKotlinSteppingTest> {
model(