Refactor test class name computation in GenerateTests
Allow to pass the FQ name of the base test class, instead of the Class object (to avoid dependencies on other modules)
This commit is contained in:
@@ -311,11 +311,11 @@ fun main(args: Array<String>) {
|
||||
model("ir/box", targetBackend = TargetBackend.JVM)
|
||||
}
|
||||
|
||||
testClass<AbstractBlackBoxInlineCodegenTest>("BlackBoxInlineCodegenTestGenerated") {
|
||||
testClass<AbstractBlackBoxInlineCodegenTest> {
|
||||
model("codegen/boxInline")
|
||||
}
|
||||
|
||||
testClass<AbstractCompileKotlinAgainstInlineKotlinTest>("CompileKotlinAgainstInlineKotlinTestGenerated") {
|
||||
testClass<AbstractCompileKotlinAgainstInlineKotlinTest> {
|
||||
model("codegen/boxInline")
|
||||
}
|
||||
|
||||
@@ -962,19 +962,19 @@ fun main(args: Array<String>) {
|
||||
model("expressionSelection", testMethod = "doTestExpressionSelection", pattern = KT_WITHOUT_DOTS_IN_NAME)
|
||||
}
|
||||
|
||||
testClass(AbstractCommonDecompiledTextTest::class.java) {
|
||||
testClass<AbstractCommonDecompiledTextTest> {
|
||||
model("decompiler/decompiledText", pattern = """^([^\.]+)$""")
|
||||
}
|
||||
|
||||
testClass(AbstractJvmDecompiledTextTest::class.java) {
|
||||
testClass<AbstractJvmDecompiledTextTest> {
|
||||
model("decompiler/decompiledTextJvm", pattern = """^([^\.]+)$""")
|
||||
}
|
||||
|
||||
testClass(AbstractCommonDecompiledTextFromJsMetadataTest::class.java) {
|
||||
testClass<AbstractCommonDecompiledTextFromJsMetadataTest> {
|
||||
model("decompiler/decompiledText", pattern = """^([^\.]+)$""", targetBackend = TargetBackend.JS)
|
||||
}
|
||||
|
||||
testClass(AbstractJsDecompiledTextFromJsMetadataTest::class.java) {
|
||||
testClass<AbstractJsDecompiledTextFromJsMetadataTest> {
|
||||
model("decompiler/decompiledTextJs", pattern = """^([^\.]+)$""", targetBackend = TargetBackend.JS)
|
||||
}
|
||||
|
||||
@@ -1226,7 +1226,7 @@ fun main(args: Array<String>) {
|
||||
model("smartMultiFile", extension = null, recursive = false)
|
||||
}
|
||||
|
||||
testClass<AbstractJvmBasicCompletionTest>("org.jetbrains.kotlin.idea.completion.test.KDocCompletionTestGenerated") {
|
||||
testClass<AbstractJvmBasicCompletionTest>("KDocCompletionTestGenerated") {
|
||||
model("kdoc")
|
||||
}
|
||||
|
||||
@@ -1234,7 +1234,7 @@ fun main(args: Array<String>) {
|
||||
model("basic/java8")
|
||||
}
|
||||
|
||||
testClass<AbstractCompletionIncrementalResolveTest>() {
|
||||
testClass<AbstractCompletionIncrementalResolveTest> {
|
||||
model("incrementalResolve")
|
||||
}
|
||||
}
|
||||
@@ -1282,12 +1282,12 @@ fun main(args: Array<String>) {
|
||||
model("incremental/lookupTracker/js", extension = null, recursive = false)
|
||||
}
|
||||
|
||||
testClass(AbstractIncrementalLazyCachesTest::class.java) {
|
||||
testClass<AbstractIncrementalLazyCachesTest> {
|
||||
model("incremental/lazyKotlinCaches", extension = null, excludeParentDirs = true)
|
||||
model("incremental/changeIncrementalOption", extension = null, excludeParentDirs = true)
|
||||
}
|
||||
|
||||
testClass(AbstractIncrementalCacheVersionChangedTest::class.java) {
|
||||
testClass<AbstractIncrementalCacheVersionChangedTest> {
|
||||
model("incremental/cacheVersionChanged", extension = null, excludeParentDirs = true)
|
||||
}
|
||||
|
||||
@@ -1529,32 +1529,24 @@ fun main(args: Array<String>) {
|
||||
}
|
||||
}
|
||||
|
||||
class TestGroup(val testsRoot: String, val testDataRoot: String) {
|
||||
class TestGroup(private val testsRoot: String, val testDataRoot: String) {
|
||||
inline fun <reified T: TestCase> testClass(
|
||||
suiteTestClass: String = getDefaultSuiteTestClass(T::class.java),
|
||||
suiteTestClassName: String = getDefaultSuiteTestClassName(T::class.java.simpleName),
|
||||
noinline init: TestClass.() -> Unit
|
||||
) {
|
||||
testClass(T::class.java, suiteTestClass, init)
|
||||
testClass(T::class.java.name, suiteTestClassName, init)
|
||||
}
|
||||
|
||||
fun testClass(
|
||||
baseTestClass: Class<out TestCase>,
|
||||
suiteTestClass: String = getDefaultSuiteTestClass(baseTestClass),
|
||||
baseTestClassName: String,
|
||||
suiteTestClassName: String = getDefaultSuiteTestClassName(baseTestClassName.substringAfterLast('.')),
|
||||
init: TestClass.() -> Unit
|
||||
) {
|
||||
val testClass = TestClass()
|
||||
testClass.init()
|
||||
|
||||
val lastDot = suiteTestClass.lastIndexOf('.')
|
||||
val suiteTestClassName = if (lastDot == -1) suiteTestClass else suiteTestClass.substring(lastDot+1)
|
||||
val suiteTestClassPackage = if (lastDot == -1) baseTestClass.`package`.name else suiteTestClass.substring(0, lastDot)
|
||||
|
||||
TestGenerator(
|
||||
testsRoot,
|
||||
suiteTestClassPackage,
|
||||
suiteTestClassName,
|
||||
baseTestClass,
|
||||
testClass.testModels
|
||||
baseTestClassName,
|
||||
TestClass().apply(init).testModels
|
||||
).generateAndSave()
|
||||
}
|
||||
|
||||
@@ -1592,17 +1584,15 @@ class TestGroup(val testsRoot: String, val testDataRoot: String) {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun testGroup(testsRoot: String, testDataRoot: String, init: TestGroup.() -> Unit) {
|
||||
TestGroup(testsRoot, testDataRoot).init()
|
||||
}
|
||||
|
||||
fun getDefaultSuiteTestClass(baseTestClass:Class<*>): String {
|
||||
val baseName = baseTestClass.simpleName
|
||||
if (!baseName.startsWith("Abstract")) {
|
||||
throw IllegalArgumentException("Doesn't start with \"Abstract\": $baseName")
|
||||
fun getDefaultSuiteTestClassName(baseTestClassName: String): String {
|
||||
if (!baseTestClassName.startsWith("Abstract")) {
|
||||
throw IllegalArgumentException("Doesn't start with \"Abstract\": $baseTestClassName")
|
||||
}
|
||||
return baseName.substring("Abstract".length) + "Generated"
|
||||
return baseTestClassName.substringAfter("Abstract") + "Generated"
|
||||
}
|
||||
|
||||
@@ -16,10 +16,8 @@
|
||||
|
||||
package org.jetbrains.kotlin.generators.tests.generator;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import junit.framework.TestCase;
|
||||
import kotlin.text.StringsKt;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.generators.util.GeneratorsFileUtil;
|
||||
@@ -32,15 +30,12 @@ import org.junit.runner.RunWith;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
import static kotlin.collections.CollectionsKt.single;
|
||||
|
||||
public class TestGenerator {
|
||||
private static final Set<String> GENERATED_FILES = ContainerUtil.newHashSet();
|
||||
private static final Set<String> GENERATED_FILES = new HashSet<>();
|
||||
private static final Class RUNNER = JUnit3RunnerWithInners.class;
|
||||
|
||||
private final String baseTestClassPackage;
|
||||
@@ -52,16 +47,15 @@ public class TestGenerator {
|
||||
|
||||
public TestGenerator(
|
||||
@NotNull String baseDir,
|
||||
@NotNull String suiteClassPackage,
|
||||
@NotNull String suiteClassName,
|
||||
@NotNull Class<? extends TestCase> baseTestClass,
|
||||
@NotNull String suiteTestClassFqName,
|
||||
@NotNull String baseTestClassFqName,
|
||||
@NotNull Collection<? extends TestClassModel> testClassModels
|
||||
) {
|
||||
this.suiteClassPackage = suiteClassPackage;
|
||||
this.suiteClassName = suiteClassName;
|
||||
this.baseTestClassPackage = baseTestClass.getPackage().getName();
|
||||
this.baseTestClassName = baseTestClass.getSimpleName();
|
||||
this.testClassModels = Lists.newArrayList(testClassModels);
|
||||
this.baseTestClassPackage = StringsKt.substringBeforeLast(baseTestClassFqName, '.', "");
|
||||
this.baseTestClassName = StringsKt.substringAfterLast(baseTestClassFqName, '.', baseTestClassFqName);
|
||||
this.suiteClassPackage = StringsKt.substringBeforeLast(suiteTestClassFqName, '.', baseTestClassPackage);
|
||||
this.suiteClassName = StringsKt.substringAfterLast(suiteTestClassFqName, '.', suiteTestClassFqName);
|
||||
this.testClassModels = new ArrayList<>(testClassModels);
|
||||
|
||||
this.testSourceFilePath = baseDir + "/" + this.suiteClassPackage.replace(".", "/") + "/" + this.suiteClassName + ".java";
|
||||
|
||||
@@ -163,9 +157,7 @@ public class TestGenerator {
|
||||
|
||||
boolean first = true;
|
||||
|
||||
for (Iterator<MethodModel> iterator = testMethods.iterator(); iterator.hasNext(); ) {
|
||||
MethodModel methodModel = iterator.next();
|
||||
|
||||
for (MethodModel methodModel : testMethods) {
|
||||
if (!methodModel.shouldBeGenerated()) continue;
|
||||
|
||||
if (first) {
|
||||
@@ -178,8 +170,7 @@ public class TestGenerator {
|
||||
generateTestMethod(p, methodModel);
|
||||
}
|
||||
|
||||
for (Iterator<TestClassModel> iterator = innerTestClasses.iterator(); iterator.hasNext(); ) {
|
||||
TestClassModel innerTestClass = iterator.next();
|
||||
for (TestClassModel innerTestClass : innerTestClasses) {
|
||||
if (!innerTestClass.isEmpty()) {
|
||||
if (first) {
|
||||
first = false;
|
||||
|
||||
Reference in New Issue
Block a user