diff --git a/compiler/build.gradle.kts b/compiler/build.gradle.kts index 937204b96cb..94839424ed6 100644 --- a/compiler/build.gradle.kts +++ b/compiler/build.gradle.kts @@ -117,6 +117,7 @@ projectTest { systemProperty("kotlin.ant.classpath", antLauncherJar.asPath) systemProperty("kotlin.ant.launcher.class", "org.apache.tools.ant.Main") } + exclude("org/jetbrains/kotlin/codegen/jdk/JvmTarget*") } fun Project.codegenTest(target: Int, jvm: Int, @@ -125,15 +126,8 @@ fun Project.codegenTest(target: Int, jvm: Int, dependsOn(*testDistProjects.map { "$it:dist" }.toTypedArray()) workingDir = rootDir - filter.includeTestsMatching("org.jetbrains.kotlin.codegen.BlackBoxCodegenTestGenerated*") - filter.includeTestsMatching("org.jetbrains.kotlin.codegen.BlackBoxInlineCodegenTestGenerated*") - filter.includeTestsMatching("org.jetbrains.kotlin.codegen.CompileKotlinAgainstInlineKotlinTestGenerated*") - filter.includeTestsMatching("org.jetbrains.kotlin.codegen.CompileKotlinAgainstKotlinTestGenerated*") - filter.includeTestsMatching("org.jetbrains.kotlin.codegen.BlackBoxAgainstJavaCodegenTestGenerated*") + filter.includeTestsMatching("org.jetbrains.kotlin.codegen.jdk.JvmTarget${target}OnJvm${jvm}") - if (jdk == "JDK_9") { - jvmArgs = listOf("--add-opens", "java.desktop/javax.swing=ALL-UNNAMED", "--add-opens", "java.base/java.io=ALL-UNNAMED") - } body() doFirst { val jdkPath = project.findProperty(jdk) ?: error("$jdk is not optional to run this test") diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/jdk/CustomJvmTargetOnJvmBaseTest.kt b/compiler/tests/org/jetbrains/kotlin/codegen/jdk/CustomJvmTargetOnJvmBaseTest.kt new file mode 100644 index 00000000000..c3197c81daf --- /dev/null +++ b/compiler/tests/org/jetbrains/kotlin/codegen/jdk/CustomJvmTargetOnJvmBaseTest.kt @@ -0,0 +1,41 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.codegen.jdk + +import org.jetbrains.kotlin.codegen.* +import org.jetbrains.kotlin.test.SuiteRunnerForCustomJdk +import org.jetbrains.kotlin.test.RunOnlyJdk6Test +import org.junit.runner.RunWith +import org.junit.runners.Suite + +/* + * NB: ALL NECESSARY FLAGS ARE PASSED THROUGH Gradle + */ + +@Suite.SuiteClasses( + BlackBoxCodegenTestGenerated::class, + BlackBoxInlineCodegenTestGenerated::class, + CompileKotlinAgainstInlineKotlinTestGenerated::class, + CompileKotlinAgainstKotlinTestGenerated::class, + BlackBoxAgainstJavaCodegenTestGenerated::class +) +abstract class CustomJvmTargetOnJvmBaseTest + +@RunOnlyJdk6Test +@RunWith(SuiteRunnerForCustomJdk::class) +class JvmTarget6OnJvm6 : CustomJvmTargetOnJvmBaseTest() + +@RunWith(SuiteRunnerForCustomJdk::class) +class JvmTarget8OnJvm8 : CustomJvmTargetOnJvmBaseTest() + +@RunWith(SuiteRunnerForCustomJdk::class) +class JvmTarget6OnJvm9 : CustomJvmTargetOnJvmBaseTest() + +@RunWith(SuiteRunnerForCustomJdk::class) +class JvmTarget8OnJvm9 : CustomJvmTargetOnJvmBaseTest() + +@RunWith(SuiteRunnerForCustomJdk::class) +class JvmTarget9OnJvm9 : CustomJvmTargetOnJvmBaseTest() \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/test/SuiteRunnerForCustomJdk.kt b/compiler/tests/org/jetbrains/kotlin/test/SuiteRunnerForCustomJdk.kt new file mode 100644 index 00000000000..c262829a005 --- /dev/null +++ b/compiler/tests/org/jetbrains/kotlin/test/SuiteRunnerForCustomJdk.kt @@ -0,0 +1,75 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.test + +import org.junit.runner.Description +import org.junit.runner.manipulation.Filter +import org.junit.runners.Suite +import org.junit.runners.model.RunnerBuilder +import java.io.File +import java.lang.reflect.Modifier +import java.util.* + +annotation class RunOnlyJdk6Test + +class SuiteRunnerForCustomJdk constructor(klass: Class<*>, builder: RunnerBuilder?) : + Suite(builder, klass, getAnnotatedClasses(klass).flatMap { + collectDeclaredClasses( + it, + true + ) + }.distinct().toTypedArray()) { + + init { + if (klass.getAnnotation(RunOnlyJdk6Test::class.java) != null) { + filter(object : Filter() { + override fun shouldRun(description: Description): Boolean { + if (description.isTest) { + val methodAnnotation = description.getAnnotation(TestMetadata::class.java) ?: return true + val testClassAnnotation = description.testClass.getAnnotation(TestMetadata::class.java) ?: return true + + val path = testClassAnnotation.value + "/" + methodAnnotation.value + val fileText = File(path).readText() + return !InTextDirectivesUtils.isDirectiveDefined(fileText, "// JVM_TARGET:") && + !InTextDirectivesUtils.isDirectiveDefined(fileText, "// SKIP_JDK6") + } + return true + } + + override fun describe(): String { + return "skipped on JDK 6" + } + }) + } + } + + companion object { + + private fun getAnnotatedClasses(klass: Class<*>, addSuperAnnotations: Boolean = true): List> { + val annotation = klass.getAnnotation(SuiteClasses::class.java) + return (annotation?.value?.map { it.java } ?: emptyList()) + + if (addSuperAnnotations) getAnnotatedClasses( + klass.superclass, + false + ) else emptyList() + } + + private fun collectDeclaredClasses(klass: Class<*>, withItself: Boolean): List> { + val result = ArrayList>() + if (klass.enclosingClass != null && !Modifier.isStatic(klass.modifiers)) return emptyList() + + if (withItself) { + result.add(klass) + } + + for (aClass in klass.declaredClasses) { + result.addAll(collectDeclaredClasses(aClass, true)) + } + + return result + } + } +}