[JVM IR] Fix lambdaInLocalFunction.kt by adding helper methods that

return the target backend under test.
This commit is contained in:
Mark Punzalan
2020-01-15 01:01:52 -08:00
committed by Alexander Udalov
parent beb3165839
commit 7329a1641a
4 changed files with 34 additions and 11 deletions
@@ -6,8 +6,10 @@
package org.jetbrains.kotlin
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.test.TargetBackend
fun createTextForHelpers(isReleaseCoroutines: Boolean, checkStateMachine: Boolean, checkTailCallOptimization: Boolean): String {
// Add the directive `// WITH_COROUTINES` to use these helpers in codegen tests (see TestFiles.java).
fun createTextForCoroutineHelpers(isReleaseCoroutines: Boolean, checkStateMachine: Boolean, checkTailCallOptimization: Boolean): String {
val coroutinesPackage =
if (isReleaseCoroutines)
DescriptorUtils.COROUTINES_PACKAGE_FQ_NAME_RELEASE.asString()
@@ -188,3 +190,11 @@ fun createTextForHelpers(isReleaseCoroutines: Boolean, checkStateMachine: Boolea
|${if (checkTailCallOptimization) checkTailCallOptimizationString else ""}
""".trimMargin()
}
// Add the directive `// WITH_HELPERS` to use these helpers in codegen tests (see CodegenTestCase.java).
fun createTextForCodegenTestHelpers(backend: TargetBackend) =
"""
|package helpers
|
|fun isIR() = ${backend.isIR}
""".trimMargin()
@@ -16,6 +16,7 @@ import kotlin.io.FilesKt;
import kotlin.text.Charsets;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.TestHelperGeneratorKt;
import org.jetbrains.kotlin.TestsCompilerError;
import org.jetbrains.kotlin.TestsCompiletimeError;
import org.jetbrains.kotlin.backend.common.output.OutputFile;
@@ -783,7 +784,7 @@ public abstract class CodegenTestCase extends KtUsefulTestCase {
expectedText = expectedText.replace("COROUTINES_PACKAGE", coroutinesPackage);
}
List<TestFile> testFiles = createTestFiles(file, expectedText, coroutinesPackage);
List<TestFile> testFiles = createTestFiles(file, expectedText);
doMultiFileTest(file, testFiles);
}
@@ -794,14 +795,18 @@ public abstract class CodegenTestCase extends KtUsefulTestCase {
}
@NotNull
private static List<TestFile> createTestFiles(File file, String expectedText, String coroutinesPackage) {
return TestFiles.createTestFiles(file.getName(), expectedText, new TestFiles.TestFileFactoryNoModules<TestFile>() {
private List<TestFile> createTestFiles(File file, String expectedText) {
List testFiles = TestFiles.createTestFiles(file.getName(), expectedText, new TestFiles.TestFileFactoryNoModules<TestFile>() {
@NotNull
@Override
public TestFile create(@NotNull String fileName, @NotNull String text, @NotNull Map<String, String> directives) {
return new TestFile(fileName, text);
}
}, coroutinesPackage);
if (InTextDirectivesUtils.isDirectiveDefined(expectedText, "WITH_HELPERS")) {
testFiles.add(new TestFile("CodegenTestHelpers.kt", TestHelperGeneratorKt.createTextForCodegenTestHelpers(getBackend())));
}
return testFiles;
}
@NotNull
@@ -8,7 +8,7 @@ package org.jetbrains.kotlin.test;
import com.google.common.collect.Lists;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.CoroutineTestUtilKt;
import org.jetbrains.kotlin.TestHelperGeneratorKt;
import java.util.Collections;
import java.util.List;
@@ -113,7 +113,8 @@ public class TestFiles {
factory.createFile(
supportModule,
"CoroutineUtil.kt",
CoroutineTestUtilKt.createTextForHelpers(isReleaseCoroutines, checkStateMachine, checkTailCallOptimization),
TestHelperGeneratorKt.createTextForCoroutineHelpers(
isReleaseCoroutines, checkStateMachine, checkTailCallOptimization),
directives
));
}