Fix coroutine test generator
This commit is contained in:
committed by
Roman Artemev
parent
f1a44ed1a4
commit
c887b88ed9
+31
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. 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.tests.generator
|
||||
|
||||
import org.jetbrains.kotlin.test.TargetBackend
|
||||
import org.jetbrains.kotlin.utils.Printer
|
||||
|
||||
class RunTestMethodWithPackageReplacementModel(
|
||||
private val targetBackend: TargetBackend,
|
||||
private val testMethodName: String,
|
||||
private val testRunnerMethodName: String
|
||||
) : MethodModel {
|
||||
override val name = METHOD_NAME
|
||||
override val dataString: String? = null
|
||||
|
||||
override fun generateSignature(p: Printer) {
|
||||
p.print("private void $name(String testDataFilePath, String packageName) throws Exception")
|
||||
}
|
||||
|
||||
override fun generateBody(p: Printer) {
|
||||
val className = TargetBackend::class.java.simpleName
|
||||
p.println("KotlinTestUtils.$testRunnerMethodName(filePath -> $testMethodName(filePath, packageName), $className.$targetBackend, testDataFilePath);")
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val METHOD_NAME = "runTestWithPackageReplacement"
|
||||
}
|
||||
}
|
||||
+12
-2
@@ -137,7 +137,7 @@ public class SimpleTestClassModel implements TestClassModel {
|
||||
if (testMethods == null) {
|
||||
if (!rootFile.isDirectory()) {
|
||||
if (CoroutinesKt.isCommonCoroutineTest(rootFile)) {
|
||||
testMethods = CoroutinesKt.createCommonCoroutinesTestMethodModels(rootFile, rootFile, doTestMethodName, filenamePattern,
|
||||
testMethods = CoroutinesKt.createCommonCoroutinesTestMethodModels(rootFile, rootFile, filenamePattern,
|
||||
checkFilenameStartsLowerCase, targetBackend,
|
||||
skipIgnored);
|
||||
}
|
||||
@@ -155,6 +155,9 @@ public class SimpleTestClassModel implements TestClassModel {
|
||||
result.add(new TestAllFilesPresentMethodModel());
|
||||
|
||||
File[] listFiles = rootFile.listFiles();
|
||||
|
||||
boolean hasCoroutines = false;
|
||||
|
||||
if (listFiles != null) {
|
||||
for (File file : listFiles) {
|
||||
if (filenamePattern.matcher(file.getName()).matches()) {
|
||||
@@ -164,7 +167,8 @@ public class SimpleTestClassModel implements TestClassModel {
|
||||
}
|
||||
|
||||
if (!file.isDirectory() && CoroutinesKt.isCommonCoroutineTest(file)) {
|
||||
result.addAll(CoroutinesKt.createCommonCoroutinesTestMethodModels(rootFile, file, doTestMethodName,
|
||||
hasCoroutines = true;
|
||||
result.addAll(CoroutinesKt.createCommonCoroutinesTestMethodModels(rootFile, file,
|
||||
filenamePattern,
|
||||
checkFilenameStartsLowerCase,
|
||||
targetBackend, skipIgnored));
|
||||
@@ -176,6 +180,12 @@ public class SimpleTestClassModel implements TestClassModel {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (hasCoroutines) {
|
||||
String methodName = doTestMethodName + "WithCoroutinesPackageReplacement";
|
||||
result.add(new RunTestMethodWithPackageReplacementModel(targetBackend, methodName, testRunnerMethodName));
|
||||
}
|
||||
|
||||
result.sort(BY_NAME);
|
||||
|
||||
testMethods = result;
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
package org.jetbrains.kotlin.generators.util
|
||||
|
||||
import org.jetbrains.kotlin.generators.tests.generator.MethodModel
|
||||
import org.jetbrains.kotlin.generators.tests.generator.RunTestMethodWithPackageReplacementModel
|
||||
import org.jetbrains.kotlin.generators.tests.generator.SimpleTestMethodModel
|
||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils.isIgnoredTarget
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.TargetBackend
|
||||
import org.jetbrains.kotlin.utils.Printer
|
||||
@@ -17,7 +17,6 @@ import java.util.regex.Pattern
|
||||
class CoroutinesTestModel(
|
||||
rootDir: File,
|
||||
file: File,
|
||||
private val doTestMethodName: String,
|
||||
filenamePattern: Pattern,
|
||||
checkFilenameStartsLowerCase: Boolean?,
|
||||
targetBackend: TargetBackend,
|
||||
@@ -36,26 +35,9 @@ class CoroutinesTestModel(
|
||||
|
||||
override fun generateBody(p: Printer) {
|
||||
val filePath = KotlinTestUtils.getFilePath(file) + if (file.isDirectory) "/" else ""
|
||||
p.println("String fileName = KotlinTestUtils.navigationMetadata(\"", filePath, "\");")
|
||||
|
||||
if (isIgnoredTarget(targetBackend, file)) {
|
||||
p.println("try {")
|
||||
p.pushIndent()
|
||||
}
|
||||
|
||||
val packageName = if (isLanguageVersion1_3) "kotlin.coroutines" else "kotlin.coroutines.experimental"
|
||||
p.println(doTestMethodName + "WithCoroutinesPackageReplacement", "(fileName, \"$packageName\");")
|
||||
|
||||
if (isIgnoredTarget(targetBackend, file)) {
|
||||
p.popIndent()
|
||||
p.println("}")
|
||||
p.println("catch (Throwable ignore) {")
|
||||
p.pushIndent()
|
||||
p.println("return;")
|
||||
p.popIndent()
|
||||
p.println("}")
|
||||
p.println("throw new AssertionError(\"Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that.\");")
|
||||
}
|
||||
p.println(RunTestMethodWithPackageReplacementModel.METHOD_NAME, "(\"$filePath\", \"$packageName\");")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +48,6 @@ fun isCommonCoroutineTest(file: File): Boolean {
|
||||
fun createCommonCoroutinesTestMethodModels(
|
||||
rootDir: File,
|
||||
file: File,
|
||||
doTestMethodName: String,
|
||||
filenamePattern: Pattern,
|
||||
checkFilenameStartsLowerCase: Boolean?,
|
||||
targetBackend: TargetBackend,
|
||||
@@ -77,7 +58,6 @@ fun createCommonCoroutinesTestMethodModels(
|
||||
CoroutinesTestModel(
|
||||
rootDir,
|
||||
file,
|
||||
doTestMethodName,
|
||||
filenamePattern,
|
||||
checkFilenameStartsLowerCase,
|
||||
targetBackend,
|
||||
@@ -90,7 +70,6 @@ fun createCommonCoroutinesTestMethodModels(
|
||||
CoroutinesTestModel(
|
||||
rootDir,
|
||||
file,
|
||||
doTestMethodName,
|
||||
filenamePattern,
|
||||
checkFilenameStartsLowerCase,
|
||||
targetBackend,
|
||||
@@ -100,7 +79,6 @@ fun createCommonCoroutinesTestMethodModels(
|
||||
CoroutinesTestModel(
|
||||
rootDir,
|
||||
file,
|
||||
doTestMethodName,
|
||||
filenamePattern,
|
||||
checkFilenameStartsLowerCase,
|
||||
targetBackend,
|
||||
|
||||
Reference in New Issue
Block a user