Add special tests for interceptRun support
Basically they're built upon basic coroutine tests, but for each of them different interceptResume implementation are injected (currently there are 12 of them). It might be more simple just to generated additional testData, but I see this more problematic in a sense of further maintenance Note that all tests add idempotent 'interceptRun' operators, which just execute given lambda in the current thread #KT-14891 Fixed
This commit is contained in:
@@ -18,5 +18,6 @@
|
||||
<orderEntry type="module" module-name="descriptor.loader.java" scope="TEST" />
|
||||
<orderEntry type="module" module-name="frontend.java" scope="TEST" />
|
||||
<orderEntry type="module" module-name="jps-tests" scope="TEST" />
|
||||
<orderEntry type="module" module-name="compiler-tests" scope="TEST" />
|
||||
</component>
|
||||
</module>
|
||||
</module>
|
||||
|
||||
+13
-8
@@ -31,20 +31,25 @@ private val packagePattern = Pattern.compile("(?m)^\\s*package[ |\t]+([\\w|\\.]*
|
||||
|
||||
private val importPattern = Pattern.compile("import[ |\t]([\\w|]*\\.)")
|
||||
|
||||
internal fun genFiles(file: File, fileContent: String, filesHolder: CodegenTestsOnAndroidGenerator.FilesWriter): FqName? {
|
||||
val testFiles = createTestFiles(file, fileContent)
|
||||
internal fun genFiles(
|
||||
testFileName: String,
|
||||
filePath: String,
|
||||
fileContent: String,
|
||||
filesHolder: CodegenTestsOnAndroidGenerator.FilesWriter
|
||||
): FqName? {
|
||||
val testFiles = createTestFiles(testFileName, fileContent)
|
||||
if (testFiles.filter { it.name.endsWith(".java") }.isNotEmpty()) {
|
||||
//TODO support java files
|
||||
return null;
|
||||
return null
|
||||
}
|
||||
val ktFiles = testFiles.filter { it.name.endsWith(".kt") }
|
||||
if (ktFiles.isEmpty()) return null
|
||||
|
||||
val newPackagePrefix = file.path.replace("\\\\|-|\\.|/".toRegex(), "_")
|
||||
val newPackagePrefix = filePath.replace("\\\\|-|\\.|/".toRegex(), "_")
|
||||
val oldPackage = Ref<FqName>()
|
||||
val isSingle = testFiles.size == 1
|
||||
val resultFiles = testFiles.map {
|
||||
val fileName = if (isSingle) it.name else file.name.substringBeforeLast(".kt") + "/" + it.name
|
||||
val fileName = if (isSingle) it.name else testFileName.substringBeforeLast(".kt") + "/" + it.name
|
||||
TestClassInfo(
|
||||
fileName,
|
||||
changePackage(newPackagePrefix, it.content, oldPackage),
|
||||
@@ -77,14 +82,14 @@ internal fun genFiles(file: File, fileContent: String, filesHolder: CodegenTests
|
||||
|
||||
val boxFiles = resultFiles.filter { hasBoxMethod(it.content) }
|
||||
if (boxFiles.size != 1) {
|
||||
println("Several box methods in $file")
|
||||
println("Several box methods in $filePath")
|
||||
}
|
||||
return boxFiles.last().newClassId
|
||||
}
|
||||
|
||||
|
||||
private fun createTestFiles(file: File, expectedText: String): List<CodegenTestCase.TestFile> {
|
||||
val files = KotlinTestUtils.createTestFiles(file.name, expectedText, object : KotlinTestUtils.TestFileFactoryNoModules<CodegenTestCase.TestFile>() {
|
||||
private fun createTestFiles(fileName: String, expectedText: String): List<CodegenTestCase.TestFile> {
|
||||
val files = KotlinTestUtils.createTestFiles(fileName, expectedText, object : KotlinTestUtils.TestFileFactoryNoModules<CodegenTestCase.TestFile>() {
|
||||
override fun create(fileName: String, text: String, directives: Map<String, String>): CodegenTestCase.TestFile {
|
||||
return CodegenTestCase.TestFile(fileName, text)
|
||||
}
|
||||
|
||||
+35
-5
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.backend.common.output.OutputFileCollection;
|
||||
import org.jetbrains.kotlin.cli.common.output.outputUtils.OutputUtilsKt;
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles;
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
||||
import org.jetbrains.kotlin.codegen.AbstractAdditionalCoroutineBlackBoxCodegenTest;
|
||||
import org.jetbrains.kotlin.codegen.CodegenTestFiles;
|
||||
import org.jetbrains.kotlin.codegen.GenerationUtils;
|
||||
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime;
|
||||
@@ -252,17 +253,46 @@ public class CodegenTestsOnAndroidGenerator extends KtUsefulTestCase {
|
||||
InTextDirectivesUtils.isDirectiveDefined(fullFileText, "WITH_REFLECT") ? holderFull : holderMock;
|
||||
filesHolder = fullFileText.contains("+JVM.INHERIT_MULTIFILE_PARTS") ? holderInheritMFP : filesHolder;
|
||||
|
||||
FqName classWithBoxMethod = AndroidTestGeneratorKt.genFiles(file, fullFileText, filesHolder);
|
||||
if (classWithBoxMethod == null)
|
||||
continue;
|
||||
if (!generateTest(file.getName(), file.getPath(), fullFileText, printer, filesHolder)) continue;
|
||||
|
||||
if (fullFileText.contains(AbstractAdditionalCoroutineBlackBoxCodegenTest.INTERCEPT_RESUME_PLACEHOLDER)) {
|
||||
int counter = 1;
|
||||
for (String replacement : AbstractAdditionalCoroutineBlackBoxCodegenTest.ALL_REPLACEMENTS) {
|
||||
String testFileName = file.getName().replace(".kt", "_" + counter + ".kt");
|
||||
String filePath = file.getPath().replace(".kt", "_" + counter + ".kt");
|
||||
generateTest(
|
||||
testFileName,
|
||||
filePath,
|
||||
fullFileText.replace(
|
||||
AbstractAdditionalCoroutineBlackBoxCodegenTest.INTERCEPT_RESUME_PLACEHOLDER, replacement
|
||||
),
|
||||
printer,
|
||||
filesHolder
|
||||
);
|
||||
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
String generatedTestName = generateTestName(file.getName());
|
||||
generateTestMethod(printer, generatedTestName, classWithBoxMethod.asString(), StringUtil.escapeStringCharacters(file.getPath()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean generateTest(
|
||||
@NotNull String testFileName,
|
||||
@NotNull String filePath,
|
||||
@NotNull String fullFileText,
|
||||
@NotNull Printer printer,
|
||||
@NotNull FilesWriter filesHolder
|
||||
) {
|
||||
FqName classWithBoxMethod = AndroidTestGeneratorKt.genFiles(testFileName, filePath, fullFileText, filesHolder);
|
||||
if (classWithBoxMethod == null) return false;
|
||||
|
||||
String generatedTestName = generateTestName(testFileName);
|
||||
generateTestMethod(printer, generatedTestName, classWithBoxMethod.asString(), StringUtil.escapeStringCharacters(filePath));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private static boolean hasBoxMethod(String text) {
|
||||
|
||||
Reference in New Issue
Block a user