Kapt: slightly improve CustomJdkTestLauncher
- Include stdout & stderr dump to the exception message if the Java command fails - Support running JVM_IR tests - Do not print anything to the stdout of the test itself in case it's successful #KT-49682
This commit is contained in:
+1
-1
@@ -7,7 +7,7 @@ package org.jetbrains.kotlin.kapt3.test
|
||||
|
||||
import org.jetbrains.kotlin.test.TargetBackend
|
||||
|
||||
abstract class AbstractIrClassFileToSourceStubConverterTest : AbstractClassFileToSourceStubConverterTest() {
|
||||
open class AbstractIrClassFileToSourceStubConverterTest : AbstractClassFileToSourceStubConverterTest() {
|
||||
override val backend = TargetBackend.JVM_IR
|
||||
}
|
||||
|
||||
|
||||
+11
-4
@@ -56,6 +56,7 @@ import org.jetbrains.kotlin.resolve.jvm.extensions.AnalysisHandlerExtension
|
||||
import org.jetbrains.kotlin.resolve.jvm.extensions.PartialAnalysisHandlerExtension
|
||||
import org.jetbrains.kotlin.test.ConfigurationKind
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.TargetBackend
|
||||
import org.jetbrains.kotlin.test.TestJdkKind
|
||||
import org.jetbrains.kotlin.test.util.trimTrailingWhitespacesAndAddNewlineAtEOF
|
||||
import org.jetbrains.kotlin.utils.PathUtil
|
||||
@@ -246,11 +247,17 @@ open class AbstractClassFileToSourceStubConverterTest : AbstractKotlinKapt3Test(
|
||||
|
||||
@JvmStatic
|
||||
fun main(args: Array<String>) {
|
||||
if (args.isEmpty()) error("1 argument expected, 0 passed")
|
||||
val test = AbstractClassFileToSourceStubConverterTest()
|
||||
if (args.size != 2) error("2 argument expected, ${args.size} passed")
|
||||
|
||||
val test = when (args[0]) {
|
||||
TargetBackend.JVM.name -> AbstractClassFileToSourceStubConverterTest()
|
||||
TargetBackend.JVM_IR.name -> AbstractIrClassFileToSourceStubConverterTest()
|
||||
else -> throw UnsupportedOperationException(args[0])
|
||||
}
|
||||
|
||||
try {
|
||||
test.setUp()
|
||||
test.doTest(args[0])
|
||||
test.doTest(args[1])
|
||||
} finally {
|
||||
test.tearDown()
|
||||
}
|
||||
@@ -273,7 +280,7 @@ open class AbstractClassFileToSourceStubConverterTest : AbstractKotlinKapt3Test(
|
||||
addOrRemoveFlag(KaptFlag.KEEP_KDOC_COMMENTS_IN_STUBS, testFile)
|
||||
|
||||
super.doTest(filePath)
|
||||
doTestWithJdk11(AbstractClassFileToSourceStubConverterTest::class.java, filePath)
|
||||
doTestWithJdk11(AbstractClassFileToSourceStubConverterTest::class.java, backend.name, filePath)
|
||||
}
|
||||
|
||||
override fun check(kaptContext: KaptContextForStubGeneration, javaFiles: List<File>, txtFile: File, wholeFile: File) {
|
||||
|
||||
+15
-11
@@ -26,12 +26,12 @@ import java.net.URLClassLoader
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
interface CustomJdkTestLauncher {
|
||||
fun doTestWithJdk11(mainClass: Class<*>, arg: String) {
|
||||
fun doTestWithJdk11(mainClass: Class<*>, vararg args: String) {
|
||||
if (isJava9OrLater()) return
|
||||
KtTestUtil.getJdk11Home().let { doTestCustomJdk(mainClass, arg, it) }
|
||||
doTestCustomJdk(mainClass, KtTestUtil.getJdk11Home(), *args)
|
||||
}
|
||||
|
||||
private fun doTestCustomJdk(mainClass: Class<*>, arg: String, javaHome: File) {
|
||||
private fun doTestCustomJdk(mainClass: Class<*>, javaHome: File, vararg args: String) {
|
||||
//TODO unmute after investigation (tests are failing on TeamCity)
|
||||
if (SystemInfoRt.isWindows) return
|
||||
|
||||
@@ -52,16 +52,21 @@ interface CustomJdkTestLauncher {
|
||||
"-classpath",
|
||||
classpath.joinToString(File.pathSeparator),
|
||||
mainClass.name,
|
||||
arg
|
||||
*args
|
||||
)
|
||||
|
||||
println("Process arguments: [${command.joinToString()}]")
|
||||
|
||||
val process = ProcessBuilder(*command).inheritIO().start()
|
||||
|
||||
val process = ProcessBuilder(*command).start()
|
||||
val stdout = process.inputStream.bufferedReader().use { it.readText() }
|
||||
val stderr = process.errorStream.bufferedReader().use { it.readText() }
|
||||
process.waitFor(3, TimeUnit.MINUTES)
|
||||
if (process.exitValue() != 0) {
|
||||
throw AssertionError("Java $javaHome test process exited with exit code ${process.exitValue()} \n")
|
||||
|
||||
val exitCode = process.exitValue()
|
||||
if (exitCode != 0) {
|
||||
throw AssertionError(
|
||||
"Java $javaHome test process exited with exit code $exitCode\n\n" +
|
||||
"--- STDOUT ---\n$stdout\n\n" +
|
||||
"--- STDERR ---\n$stderr"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,5 +75,4 @@ interface CustomJdkTestLauncher {
|
||||
is ClassLoader -> collectClasspath(classLoader.parent)
|
||||
else -> emptyList()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user