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