Support configuration directives FULL_JDK, WITH_RUNTIME, WITH_REFLECT in Psi2Ir tests.
This commit is contained in:
committed by
Dmitry Petrov
parent
d623c70778
commit
539d7ccf6f
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.jetbrains.kotlin.ir
|
||||
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||
import org.jetbrains.kotlin.codegen.CodegenTestCase
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.psi2ir.Psi2IrConfiguration
|
||||
@@ -23,15 +25,52 @@ import org.jetbrains.kotlin.psi2ir.Psi2IrTranslator
|
||||
import org.jetbrains.kotlin.resolve.AnalyzingUtils
|
||||
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil
|
||||
import org.jetbrains.kotlin.test.ConfigurationKind
|
||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils.getAnnotationsJar
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
abstract class AbstractIrGeneratorTestCase : CodegenTestCase() {
|
||||
override fun doMultiFileTest(wholeFile: File, files: List<TestFile>, javaFilesDir: File?) {
|
||||
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.ALL, files, javaFilesDir)
|
||||
setupEnvironment(files, javaFilesDir)
|
||||
|
||||
loadMultiFiles(files)
|
||||
doTest(wholeFile, files)
|
||||
}
|
||||
|
||||
private fun setupEnvironment(files: List<TestFile>, javaFilesDir: File?) {
|
||||
val jdkKind = getJdkKind(files)
|
||||
|
||||
val javacOptions = ArrayList<String>(0)
|
||||
var addRuntime = false
|
||||
var addReflect = false
|
||||
for (file in files) {
|
||||
if (InTextDirectivesUtils.isDirectiveDefined(file.content, "WITH_RUNTIME")) {
|
||||
addRuntime = true
|
||||
}
|
||||
if (InTextDirectivesUtils.isDirectiveDefined(file.content, "WITH_REFLECT")) {
|
||||
addReflect = true
|
||||
}
|
||||
|
||||
javacOptions.addAll(InTextDirectivesUtils.findListWithPrefixes(file.content, "// JAVAC_OPTIONS:"))
|
||||
}
|
||||
|
||||
val configurationKind = when {
|
||||
addReflect -> ConfigurationKind.ALL
|
||||
addRuntime -> ConfigurationKind.NO_KOTLIN_REFLECT
|
||||
else -> ConfigurationKind.JDK_ONLY
|
||||
};
|
||||
|
||||
val configuration = createConfiguration(
|
||||
configurationKind, jdkKind,
|
||||
listOf<File>(getAnnotationsJar()),
|
||||
arrayOf(javaFilesDir).filterNotNull(),
|
||||
files
|
||||
)
|
||||
|
||||
myEnvironment = KotlinCoreEnvironment.createForTests(testRootDisposable, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES)
|
||||
}
|
||||
|
||||
protected abstract fun doTest(wholeFile: File, testFiles: List<TestFile>)
|
||||
|
||||
protected fun generateIrFilesAsSingleModule(testFiles: List<TestFile>, ignoreErrors: Boolean = false): Map<TestFile, IrFile> {
|
||||
|
||||
+1
-1
@@ -21,6 +21,6 @@ import java.io.File
|
||||
abstract class AbstractPsi2IrAcceptanceTestCase : AbstractIrGeneratorTestCase() {
|
||||
override fun doTest(wholeFile: File, testFiles: List<TestFile>) {
|
||||
// Just make sure that nothing interesting happens - e.g., no exceptions thrown
|
||||
generateIrFilesAsSingleModule(testFiles, true)
|
||||
generateIrFilesAsSingleModule(testFiles, false)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
class C(x: Int, val y: Int, var z: Int = 1) {
|
||||
constructor() : this(0, 0, 0) {}
|
||||
|
||||
|
||||
+2
@@ -1,3 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
enum class TestEnum1 {
|
||||
TEST1, TEST2
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
class Test1 {
|
||||
init {
|
||||
println()
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
interface IFoo {
|
||||
fun foo()
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
val test1 by lazy { 42 }
|
||||
|
||||
class C(val map: MutableMap<String, Any>) {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun test1() {
|
||||
val x by lazy { 42 }
|
||||
println(x)
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun testEmpty(ss: List<String>) {
|
||||
for (s in ss);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
object FiveTimes
|
||||
|
||||
class IntCell(var value: Int)
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun expectsString(s: String) {}
|
||||
fun expectsInt(i: Int) {}
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun test1() {
|
||||
try {
|
||||
println()
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
object A
|
||||
|
||||
fun testWithSubject(x: Any?) =
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
val anonymous = fun() { println() }
|
||||
@@ -1,3 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun test0() {
|
||||
run {
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user