Extract jvm6-specific test utils, add codegen on specific jdk tests

This commit is contained in:
Ilya Chernikov
2017-09-18 17:59:04 +02:00
parent 82690fe6b3
commit 51efd717f6
14 changed files with 125 additions and 24 deletions
+5 -2
View File
@@ -93,6 +93,7 @@ Properties().apply {
extra["JDK_16"] = jdkPath("1.6")
extra["JDK_17"] = jdkPath("1.7")
extra["JDK_18"] = jdkPath("1.8")
extra["JDK_9"] = jdkPathIfFound("9")
extra["versions.protobuf-java"] = "2.6.1"
extra["versions.javax.inject"] = "1"
@@ -421,13 +422,15 @@ tasks {
"check" { dependsOn("test") }
}
fun jdkPath(version: String): String {
fun jdkPathIfFound(version: String): String? {
val jdkName = "JDK_${version.replace(".", "")}"
val jdkMajorVersion = JdkMajorVersion.valueOf(jdkName)
return configuredJdks.find { it.majorVersion == jdkMajorVersion }?.homeDir?.canonicalPath
?: throw GradleException ("Please set environment variable $jdkName to point to JDK $version installation")
}
fun jdkPath(version: String): String = jdkPathIfFound(version)
?: throw GradleException ("Please set environment variable JDK_${version.replace(".", "")} to point to JDK $version installation")
fun Project.configureJvmProject(javaHome: String, javaVersion: String) {
tasks.withType<JavaCompile> {
+1 -1
View File
@@ -7,7 +7,7 @@ import org.gradle.kotlin.dsl.*
import org.gradle.api.tasks.testing.Test
import org.gradle.kotlin.dsl.extra
fun Project.projectTest(body: Test.() -> Unit = {}): Test = (tasks.findByName("test") as Test).apply {
fun Project.projectTest(taskName: String = "test", body: Test.() -> Unit = {}): Test = getOrCreateTask(taskName) {
doFirst {
val patterns = filter.includePatterns + ((filter as? DefaultTestFilter)?.commandLineIncludePatterns ?: emptySet())
if (patterns.isEmpty() || patterns.any { '*' in it }) return@doFirst
+1
View File
@@ -23,6 +23,7 @@ dependencies {
compile(project(":js:js.translator"))
compileOnly(project(":plugins:android-extensions-compiler"))
compile(project(":kotlin-test:kotlin-test-jvm"))
compile(project(":compiler:tests-common-jvm6"))
compile(commonDep("junit:junit"))
compile(ideaSdkCoreDeps("intellij-core"))
compile(ideaSdkDeps("openapi", "idea", "idea_rt"))
+36
View File
@@ -42,6 +42,7 @@ dependencies {
testCompileOnly(projectDist(":kotlin-test:kotlin-test-jvm"))
testCompileOnly(projectDist(":kotlin-test:kotlin-test-junit"))
testCompile(project(":compiler.tests-common"))
testCompile(project(":compiler:tests-common-jvm6"))
testCompile(project(":compiler:ir.ir2cfg"))
testCompile(project(":compiler:ir.tree")) // used for deepCopyWithSymbols call that is removed by proguard from the compiler TODO: make it more straightforward
otherCompilerModules.forEach {
@@ -79,3 +80,38 @@ projectTest {
systemProperty("kotlin.test.script.classpath", the<JavaPluginConvention>().sourceSets.getByName("test").output.classesDirs.joinToString(File.pathSeparator))
}
evaluationDependsOn(":compiler:tests-common-jvm6")
fun Project.codegenTest(taskName: String, body: Test.() -> Unit): Test = projectTest(taskName) {
dependsOn(*testDistProjects.map { "$it:dist" }.toTypedArray())
workingDir = rootDir
environment("TEST_SERVER_CLASSES_DIRS", project(":compiler:tests-common-jvm6").the<JavaPluginConvention>().sourceSets.getByName("main").output.classesDirs.asPath)
filter.includeTestsMatching("org.jetbrains.kotlin.codegen.CodegenJdkCommonTestSuite*")
body()
}
codegenTest("codegen-target6-jvm6-test") {
systemProperty("kotlin.test.default.jvm.target", "1.6")
systemProperty("kotlin.test.java.compilation.target", "1.6")
systemProperty("kotlin.test.box.in.separate.process.port", "5100")
}
codegenTest("codegen-target6-jvm9-test") {
systemProperty("kotlin.test.default.jvm.target", "1.6")
jvmArgs = listOf("--add-opens", "java.desktop/javax.swing=ALL-UNNAMED", "--add-opens", "java.base/java.io=ALL-UNNAMED")
}
codegenTest("codegen-target8-jvm8-test") {
systemProperty("kotlin.test.default.jvm.target", "1.8")
}
codegenTest("codegen-target8-jvm9-test") {
systemProperty("kotlin.test.default.jvm.target", "1.8")
jvmArgs = listOf("--add-opens", "java.desktop/javax.swing=ALL-UNNAMED", "--add-opens", "java.base/java.io=ALL-UNNAMED")
}
codegenTest("codegen-target9-jvm9-test") {
systemProperty("kotlin.test.default.jvm.target", "1.8")
systemProperty("kotlin.test.substitute.bytecode.1.8.to.1.9", "true")
jvmArgs = listOf("--add-opens", "java.desktop/javax.swing=ALL-UNNAMED", "--add-opens", "java.base/java.io=ALL-UNNAMED")
}
@@ -0,0 +1,22 @@
apply { plugin("kotlin") }
jvmTarget = "1.6"
dependencies {
compile(project(":core"))
compile(project(":core::util.runtime"))
compile(project(":compiler:util"))
compile(project(":compiler:backend"))
compile(project(":compiler:frontend"))
compile(project(":compiler:frontend.java"))
compile(project(":compiler:util"))
compile(project(":compiler:cli-common"))
compile(project(":compiler:cli"))
compile(project(":kotlin-test:kotlin-test-jvm"))
}
sourceSets {
"main" { projectDefault() }
"test" {}
}
@@ -16,17 +16,34 @@
package org.jetbrains.kotlin.test.clientserver
import org.jetbrains.kotlin.codegen.getBoxMethodOrNull
import org.jetbrains.kotlin.codegen.getGeneratedClass
import java.io.File
import java.io.ObjectInputStream
import java.io.ObjectOutputStream
import java.lang.reflect.Method
import java.net.ServerSocket
import java.net.Socket
import java.net.URL
import java.net.URLClassLoader
import java.util.concurrent.Executors
fun getGeneratedClass(classLoader: ClassLoader, className: String): Class<*> {
try {
return classLoader.loadClass(className)
}
catch (e: ClassNotFoundException) {
error("No class file was generated for: " + className)
}
}
fun getBoxMethodOrNull(aClass: Class<*>): Method? {
try {
return aClass.getMethod("box")
}
catch (e: NoSuchMethodException) {
return null
}
}
//Use only JDK 1.6 compatible api
object TestProcessServer {
@@ -16,7 +16,6 @@
package org.jetbrains.kotlin.test.clientserver
import org.jetbrains.kotlin.utils.rethrow
import java.io.File
import java.io.ObjectInputStream
import java.io.ObjectOutputStream
@@ -34,6 +34,8 @@ import java.util.List;
import static org.jetbrains.kotlin.codegen.TestUtilsKt.*;
import static org.jetbrains.kotlin.test.KotlinTestUtils.assertEqualsToFile;
import static org.jetbrains.kotlin.test.clientserver.TestProcessServerKt.getBoxMethodOrNull;
import static org.jetbrains.kotlin.test.clientserver.TestProcessServerKt.getGeneratedClass;
public abstract class AbstractBlackBoxCodegenTest extends CodegenTestCase {
@@ -80,6 +80,8 @@ import static org.jetbrains.kotlin.cli.common.output.outputUtils.OutputUtilsKt.w
import static org.jetbrains.kotlin.codegen.CodegenTestUtil.*;
import static org.jetbrains.kotlin.codegen.TestUtilsKt.*;
import static org.jetbrains.kotlin.test.KotlinTestUtils.getAnnotationsJar;
import static org.jetbrains.kotlin.test.clientserver.TestProcessServerKt.getBoxMethodOrNull;
import static org.jetbrains.kotlin.test.clientserver.TestProcessServerKt.getGeneratedClass;
public abstract class CodegenTestCase extends KtUsefulTestCase {
private static final String DEFAULT_TEST_FILE_NAME = "a_test";
@@ -35,23 +35,6 @@ fun clearReflectionCache(classLoader: ClassLoader) {
}
fun getGeneratedClass(classLoader: ClassLoader, className: String): Class<*> {
try {
return classLoader.loadClass(className)
}
catch (e: ClassNotFoundException) {
error("No class file was generated for: " + className)
}
}
fun getBoxMethodOrNull(aClass: Class<*>): Method? {
try {
return aClass.getMethod("box")
}
catch (e: NoSuchMethodException) {
return null
}
}
fun ClassLoader?.extractUrls(): List<URL> {
return (this as? URLClassLoader)?.let {
@@ -46,7 +46,7 @@ object CodegenJdkCommonTestSuite {
fun setUp() {
val boxInSeparateProcessPort = System.getProperty(CodegenTestCase.RUN_BOX_TEST_IN_SEPARATE_PROCESS_PORT)
if (boxInSeparateProcessPort != null) {
val classpath = "out/test/tests-common" +
val classpath = (System.getenv("TEST_SERVER_CLASSES_DIRS") ?: "out/test/tests-common") +
File.pathSeparatorChar +
ForTestCompileRuntime.runtimeJarForTests() +
File.pathSeparatorChar +
+35
View File
@@ -2631,6 +2631,41 @@
"reporting": "org.gradle.api.reporting.ReportingExtension"
}
},
":compiler:tests-common-jvm6": {
"conventions": {
"base": "org.gradle.api.plugins.BasePluginConvention",
"java": "org.gradle.api.plugins.JavaPluginConvention"
},
"configurations": [
"apiElements",
"archives",
"compile",
"compileClasspath",
"compileOnly",
"default",
"implementation",
"kapt",
"kaptTest",
"runtime",
"runtimeClasspath",
"runtimeElements",
"runtimeOnly",
"testCompile",
"testCompileClasspath",
"testCompileOnly",
"testImplementation",
"testRuntime",
"testRuntimeClasspath",
"testRuntimeOnly"
],
"extensions": {
"ext": "org.gradle.api.plugins.ExtraPropertiesExtension",
"kotlin": "org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension",
"kapt": "org.jetbrains.kotlin.gradle.plugin.KaptExtension",
"defaultArtifacts": "org.gradle.api.internal.plugins.DefaultArtifactPublicationSet",
"reporting": "org.gradle.api.reporting.ReportingExtension"
}
},
":compiler:tests-java8": {
"conventions": {
"base": "org.gradle.api.plugins.BasePluginConvention",
+1
View File
@@ -39,6 +39,7 @@ include ":kotlin-build-common",
":compiler:incremental-compilation-impl",
":compiler:android-tests",
":compiler.tests-common",
":compiler:tests-common-jvm6",
":js:js.ast",
":js:js.serializer",
":js:js.parser",