Add CLI test for K/javac project with K/J interdependency

Yet this test fails if JavacWrapper does not add Kotlin output dir to classpath
This commit is contained in:
Mikhail Glukhikh
2019-10-10 14:39:27 +03:00
parent 9f3d834b2a
commit 87e2f9d96b
6 changed files with 43 additions and 5 deletions
@@ -170,10 +170,10 @@ class JavacWrapper(
setClassPathForCompilation(outDir)
makeOutputDirectoryClassesVisible()
context.get(Log.outKey)?.println(
"Compiling $javaFilesNumber Java source files" +
" to [${fileManager.getLocation(CLASS_OUTPUT)?.firstOrNull()?.path}]"
)
val outputPath =
// Includes a hack with 'takeIf' for CLI test, to have stable string here (independent from random test directory)
fileManager.getLocation(CLASS_OUTPUT)?.firstOrNull()?.path?.takeIf { "compilerProject_test" !in it } ?: "test directory"
context.get(Log.outKey)?.print("Compiling $javaFilesNumber Java source files to [$outputPath]")
compile(fileObjects)
errorCount() == 0
}
@@ -340,7 +340,7 @@ class JavacWrapper(
private fun makeOutputDirectoryClassesVisible() {
// TODO: below we have a hacky part with a purpose
// to make already analyzed classes visible by Javac without reading them again.
// However, it does not work as it should (but some tests depend on this code fragment)
// This works (and necessary!) when javac has "-proc:none" argument, so works without APT
val reader = ClassReader.instance(context)
val names = Names.instance(context)
val outDirName = fileManager.getLocation(CLASS_OUTPUT)?.firstOrNull()?.path ?: ""
@@ -368,6 +368,9 @@ class JavacWrapper(
private fun setClassPathForCompilation(outDir: File?) = apply {
(outDir ?: outputDirectory)?.let { outputDir ->
if (outputDir.exists()) {
// This line is necessary for e.g. CliTestGenerated.jvm.javacKotlinJavaInterdependency to work
// In general, it makes compiled Kotlin classes from the module visible for javac
// It's necessary when javac work with APT (without -proc:none flag)
fileManager.setLocation(CLASS_PATH, fileManager.getLocation(CLASS_PATH) + outputDir)
}
outputDir.mkdirs()
@@ -0,0 +1,6 @@
$TESTDATA_DIR$/javacKotlinJavaInterdependency/test/ClassWithTypeParameter.kt
$TESTDATA_DIR$/javacKotlinJavaInterdependency/test/ClassWithTypeParameter.java
-Xuse-javac
-Xcompile-java
-d
$TEMP_DIR$
@@ -0,0 +1,2 @@
info: compiling 1 Java source files to [test directory]
OK
@@ -0,0 +1,7 @@
package test;
public class ClassWithTypeParameter<T extends KotlinInterface> {
public ClassWithTypeParameter(T kotlinInterface) {}
}
@@ -0,0 +1,15 @@
package test
interface KotlinInterface
class Impl1 : KotlinInterface
class Impl2 : KotlinInterface
class Impl3 : KotlinInterface
fun getProducer1() = Impl1().let(::ClassWithTypeParameter)
fun getProducer2() = Impl2().let(::ClassWithTypeParameter)
fun getProducer3() = Impl3().let(::ClassWithTypeParameter)
@@ -346,6 +346,11 @@ public class CliTestGenerated extends AbstractCliTest {
runTest("compiler/testData/cli/jvm/javaSrcWrongPackage.args");
}
@TestMetadata("javacKotlinJavaInterdependency.args")
public void testJavacKotlinJavaInterdependency() throws Exception {
runTest("compiler/testData/cli/jvm/javacKotlinJavaInterdependency.args");
}
@TestMetadata("jdkPathDoesNotExist.args")
public void testJdkPathDoesNotExist() throws Exception {
runTest("compiler/testData/cli/jvm/jdkPathDoesNotExist.args");