jvm-abi-gen: Add tests for uses of private Kotlin classes from Java
This commit is contained in:
committed by
Alexander Udalov
parent
8de6a5224f
commit
ec4d7b2bb6
@@ -5,10 +5,14 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.jvm.abi
|
package org.jetbrains.kotlin.jvm.abi
|
||||||
|
|
||||||
|
import com.intellij.openapi.util.io.FileUtil
|
||||||
import junit.framework.TestCase
|
import junit.framework.TestCase
|
||||||
import org.jetbrains.kotlin.cli.common.ExitCode
|
import org.jetbrains.kotlin.cli.common.ExitCode
|
||||||
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
|
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
|
||||||
|
import org.jetbrains.kotlin.codegen.CodegenTestUtil
|
||||||
|
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime
|
||||||
import org.jetbrains.kotlin.config.Services
|
import org.jetbrains.kotlin.config.Services
|
||||||
|
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import kotlin.io.path.ExperimentalPathApi
|
import kotlin.io.path.ExperimentalPathApi
|
||||||
import kotlin.io.path.createTempDirectory
|
import kotlin.io.path.createTempDirectory
|
||||||
@@ -45,6 +49,9 @@ abstract class BaseJvmAbiTest : TestCase() {
|
|||||||
val abiDir: File
|
val abiDir: File
|
||||||
get() = if (name == null) workingDir.resolve("abi") else workingDir.resolve("$name/abi")
|
get() = if (name == null) workingDir.resolve("abi") else workingDir.resolve("$name/abi")
|
||||||
|
|
||||||
|
val javaDestinationDir: File
|
||||||
|
get() = if (name == null) workingDir.resolve("javaOut") else workingDir.resolve("$name/javaOut")
|
||||||
|
|
||||||
override fun toString(): String =
|
override fun toString(): String =
|
||||||
"compilation '$name'"
|
"compilation '$name'"
|
||||||
}
|
}
|
||||||
@@ -76,6 +83,23 @@ abstract class BaseJvmAbiTest : TestCase() {
|
|||||||
val errorLines = listOf("Could not compile $compilation", "Exit code: $exitCode", "Errors:") + messageCollector.errors
|
val errorLines = listOf("Could not compile $compilation", "Exit code: $exitCode", "Errors:") + messageCollector.errors
|
||||||
error(errorLines.joinToString("\n"))
|
error(errorLines.joinToString("\n"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Compile Java files into both the destination and ABI directories in order make the
|
||||||
|
// results available to run and to downstream compilations.
|
||||||
|
val javaFiles = CodegenTestUtil.findJavaSourcesInDirectory(compilation.srcDir).map(::File)
|
||||||
|
if (javaFiles.isNotEmpty()) {
|
||||||
|
compilation.javaDestinationDir.mkdirs()
|
||||||
|
val javacOptions = listOf(
|
||||||
|
"-classpath",
|
||||||
|
(abiDependencies + compilation.destinationDir).joinToString(File.pathSeparator) { it.canonicalPath }
|
||||||
|
+ File.pathSeparator + ForTestCompileRuntime.runtimeJarForTests(),
|
||||||
|
"-d",
|
||||||
|
compilation.javaDestinationDir.canonicalPath
|
||||||
|
)
|
||||||
|
KotlinTestUtils.compileJavaFiles(javaFiles, javacOptions)
|
||||||
|
FileUtil.copyDir(compilation.javaDestinationDir, compilation.destinationDir)
|
||||||
|
FileUtil.copyDir(compilation.javaDestinationDir, compilation.abiDir)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected open val useIrBackend: Boolean
|
protected open val useIrBackend: Boolean
|
||||||
|
|||||||
Generated
+20
@@ -80,6 +80,26 @@ public class CompileAgainstJvmAbiTestGenerated extends AbstractCompileAgainstJvm
|
|||||||
runTest("plugins/jvm-abi-gen/testData/compile/kt-40340/");
|
runTest("plugins/jvm-abi-gen/testData/compile/kt-40340/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("privateAnnotationsFromJavaApp")
|
||||||
|
public void testPrivateAnnotationsFromJavaApp() throws Exception {
|
||||||
|
runTest("plugins/jvm-abi-gen/testData/compile/privateAnnotationsFromJavaApp/");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("privateAnnotationsFromJavaLib")
|
||||||
|
public void testPrivateAnnotationsFromJavaLib() throws Exception {
|
||||||
|
runTest("plugins/jvm-abi-gen/testData/compile/privateAnnotationsFromJavaLib/");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("privateClassesFromJavaApp")
|
||||||
|
public void testPrivateClassesFromJavaApp() throws Exception {
|
||||||
|
runTest("plugins/jvm-abi-gen/testData/compile/privateClassesFromJavaApp/");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("privateClassesFromJavaLib")
|
||||||
|
public void testPrivateClassesFromJavaLib() throws Exception {
|
||||||
|
runTest("plugins/jvm-abi-gen/testData/compile/privateClassesFromJavaLib/");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("privateOnlyConstructors")
|
@TestMetadata("privateOnlyConstructors")
|
||||||
public void testPrivateOnlyConstructors() throws Exception {
|
public void testPrivateOnlyConstructors() throws Exception {
|
||||||
runTest("plugins/jvm-abi-gen/testData/compile/privateOnlyConstructors/");
|
runTest("plugins/jvm-abi-gen/testData/compile/privateOnlyConstructors/");
|
||||||
|
|||||||
Generated
+20
@@ -80,6 +80,26 @@ public class IrCompileAgainstJvmAbiTestGenerated extends AbstractIrCompileAgains
|
|||||||
runTest("plugins/jvm-abi-gen/testData/compile/kt-40340/");
|
runTest("plugins/jvm-abi-gen/testData/compile/kt-40340/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("privateAnnotationsFromJavaApp")
|
||||||
|
public void testPrivateAnnotationsFromJavaApp() throws Exception {
|
||||||
|
runTest("plugins/jvm-abi-gen/testData/compile/privateAnnotationsFromJavaApp/");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("privateAnnotationsFromJavaLib")
|
||||||
|
public void testPrivateAnnotationsFromJavaLib() throws Exception {
|
||||||
|
runTest("plugins/jvm-abi-gen/testData/compile/privateAnnotationsFromJavaLib/");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("privateClassesFromJavaApp")
|
||||||
|
public void testPrivateClassesFromJavaApp() throws Exception {
|
||||||
|
runTest("plugins/jvm-abi-gen/testData/compile/privateClassesFromJavaApp/");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("privateClassesFromJavaLib")
|
||||||
|
public void testPrivateClassesFromJavaLib() throws Exception {
|
||||||
|
runTest("plugins/jvm-abi-gen/testData/compile/privateClassesFromJavaLib/");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("privateOnlyConstructors")
|
@TestMetadata("privateOnlyConstructors")
|
||||||
public void testPrivateOnlyConstructors() throws Exception {
|
public void testPrivateOnlyConstructors() throws Exception {
|
||||||
runTest("plugins/jvm-abi-gen/testData/compile/privateOnlyConstructors/");
|
runTest("plugins/jvm-abi-gen/testData/compile/privateOnlyConstructors/");
|
||||||
|
|||||||
Generated
+20
@@ -80,6 +80,26 @@ public class LegacyCompileAgainstJvmAbiTestGenerated extends AbstractLegacyCompi
|
|||||||
runTest("plugins/jvm-abi-gen/testData/compile/kt-40340/");
|
runTest("plugins/jvm-abi-gen/testData/compile/kt-40340/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("privateAnnotationsFromJavaApp")
|
||||||
|
public void testPrivateAnnotationsFromJavaApp() throws Exception {
|
||||||
|
runTest("plugins/jvm-abi-gen/testData/compile/privateAnnotationsFromJavaApp/");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("privateAnnotationsFromJavaLib")
|
||||||
|
public void testPrivateAnnotationsFromJavaLib() throws Exception {
|
||||||
|
runTest("plugins/jvm-abi-gen/testData/compile/privateAnnotationsFromJavaLib/");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("privateClassesFromJavaApp")
|
||||||
|
public void testPrivateClassesFromJavaApp() throws Exception {
|
||||||
|
runTest("plugins/jvm-abi-gen/testData/compile/privateClassesFromJavaApp/");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("privateClassesFromJavaLib")
|
||||||
|
public void testPrivateClassesFromJavaLib() throws Exception {
|
||||||
|
runTest("plugins/jvm-abi-gen/testData/compile/privateClassesFromJavaLib/");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("privateOnlyConstructors")
|
@TestMetadata("privateOnlyConstructors")
|
||||||
public void testPrivateOnlyConstructors() throws Exception {
|
public void testPrivateOnlyConstructors() throws Exception {
|
||||||
runTest("plugins/jvm-abi-gen/testData/compile/privateOnlyConstructors/");
|
runTest("plugins/jvm-abi-gen/testData/compile/privateOnlyConstructors/");
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
import lib.J
|
||||||
|
|
||||||
|
fun runAppAndReturnOk(): String {
|
||||||
|
return J.value()
|
||||||
|
}
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
package lib;
|
||||||
|
|
||||||
|
@A(value = "OK")
|
||||||
|
public class J {
|
||||||
|
public static String value() {
|
||||||
|
return J.class.getAnnotation(A.class).value();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package lib
|
||||||
|
|
||||||
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
|
private annotation class A(val value: String)
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
import lib.J
|
||||||
|
|
||||||
|
fun runAppAndReturnOk(): String {
|
||||||
|
return if (J::class.java.annotations.size == 1) "OK" else "Fail"
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package lib;
|
||||||
|
|
||||||
|
@A
|
||||||
|
public class J {}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package lib
|
||||||
|
|
||||||
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
|
private annotation class A
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
import lib.J
|
||||||
|
|
||||||
|
fun runAppAndReturnOk(): String {
|
||||||
|
return J.result()
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package lib;
|
||||||
|
|
||||||
|
public class J {
|
||||||
|
public static String result() {
|
||||||
|
return new A().result();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package lib
|
||||||
|
|
||||||
|
private class A {
|
||||||
|
fun result() = "OK"
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
import lib.J
|
||||||
|
|
||||||
|
fun runAppAndReturnOk(): String {
|
||||||
|
return J.result()
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package lib;
|
||||||
|
|
||||||
|
public class J {
|
||||||
|
public static String result() {
|
||||||
|
return new A().result();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package lib
|
||||||
|
|
||||||
|
private class A {
|
||||||
|
fun result() = "OK"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user