Enable all Java 9 tests
This commit is contained in:
-16
@@ -18,12 +18,9 @@ package org.jetbrains.kotlin.checkers;
|
|||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.kotlin.test.ConfigurationKind;
|
import org.jetbrains.kotlin.test.ConfigurationKind;
|
||||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
|
||||||
import org.jetbrains.kotlin.test.TestJdkKind;
|
import org.jetbrains.kotlin.test.TestJdkKind;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public abstract class AbstractDiagnosticsWithJdk9Test extends AbstractDiagnosticsTest {
|
public abstract class AbstractDiagnosticsWithJdk9Test extends AbstractDiagnosticsTest {
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -37,17 +34,4 @@ public abstract class AbstractDiagnosticsWithJdk9Test extends AbstractDiagnostic
|
|||||||
protected TestJdkKind getTestJdkKind(@NotNull File file) {
|
protected TestJdkKind getTestJdkKind(@NotNull File file) {
|
||||||
return TestJdkKind.FULL_JDK_9;
|
return TestJdkKind.FULL_JDK_9;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void doMultiFileTest(
|
|
||||||
@NotNull File file,
|
|
||||||
@NotNull Map<String, ModuleAndDependencies> modules,
|
|
||||||
@NotNull List<TestFile> testFiles
|
|
||||||
) {
|
|
||||||
if (KotlinTestUtils.getJdk9HomeIfPossible() == null) {
|
|
||||||
// Skip this test if no Java 9 is found
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
super.doMultiFileTest(file, modules, testFiles);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -560,10 +560,7 @@ public class KotlinTestUtils {
|
|||||||
configuration.put(JVMConfigurationKeys.JDK_HOME, new File(jdk6));
|
configuration.put(JVMConfigurationKeys.JDK_HOME, new File(jdk6));
|
||||||
}
|
}
|
||||||
else if (jdkKind == TestJdkKind.FULL_JDK_9) {
|
else if (jdkKind == TestJdkKind.FULL_JDK_9) {
|
||||||
File home = getJdk9HomeIfPossible();
|
configuration.put(JVMConfigurationKeys.JDK_HOME, getJdk9Home());
|
||||||
if (home != null) {
|
|
||||||
configuration.put(JVMConfigurationKeys.JDK_HOME, home);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (SystemInfo.IS_AT_LEAST_JAVA9) {
|
else if (SystemInfo.IS_AT_LEAST_JAVA9) {
|
||||||
configuration.put(JVMConfigurationKeys.JDK_HOME, new File(System.getProperty("java.home")));
|
configuration.put(JVMConfigurationKeys.JDK_HOME, new File(System.getProperty("java.home")));
|
||||||
@@ -587,26 +584,18 @@ public class KotlinTestUtils {
|
|||||||
return configuration;
|
return configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@NotNull
|
||||||
public static File getJdk9HomeIfPossible() {
|
public static File getJdk9Home() {
|
||||||
String jdk9 = System.getenv("JDK_19");
|
String jdk9 = System.getenv("JDK_9");
|
||||||
if (jdk9 == null) {
|
if (jdk9 == null) {
|
||||||
jdk9 = System.getenv("JDK_9");
|
jdk9 = System.getenv("JDK_19");
|
||||||
}
|
if (jdk9 == null) {
|
||||||
if (jdk9 == null) {
|
throw new AssertionError("Environment variable JDK_9 is not set!");
|
||||||
// TODO: replace this with a failure as soon as Java 9 is installed on all TeamCity agents
|
}
|
||||||
System.err.println("Environment variable JDK_19 is not set, the test will be skipped");
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
return new File(jdk9);
|
return new File(jdk9);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private static String getJreHome(@NotNull String jdkHome) {
|
|
||||||
File jre = new File(jdkHome, "jre");
|
|
||||||
return jre.isDirectory() ? jre.getPath() : jdkHome;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void resolveAllKotlinFiles(KotlinCoreEnvironment environment) throws IOException {
|
public static void resolveAllKotlinFiles(KotlinCoreEnvironment environment) throws IOException {
|
||||||
List<String> paths = ContentRootsKt.getKotlinSourceRoots(environment.getConfiguration());
|
List<String> paths = ContentRootsKt.getKotlinSourceRoots(environment.getConfiguration());
|
||||||
if (paths.isEmpty()) return;
|
if (paths.isEmpty()) return;
|
||||||
@@ -982,11 +971,8 @@ public class KotlinTestUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean compileJavaFilesExternallyWithJava9(@NotNull Collection<File> files, @NotNull List<String> options) {
|
public static boolean compileJavaFilesExternallyWithJava9(@NotNull Collection<File> files, @NotNull List<String> options) {
|
||||||
File jdk9 = getJdk9HomeIfPossible();
|
|
||||||
assert jdk9 != null : "Environment variable JDK_19 is not set";
|
|
||||||
|
|
||||||
List<String> command = new ArrayList<>();
|
List<String> command = new ArrayList<>();
|
||||||
command.add(new File(jdk9, "bin/javac").getPath());
|
command.add(new File(getJdk9Home(), "bin/javac").getPath());
|
||||||
command.addAll(options);
|
command.addAll(options);
|
||||||
for (File file : files) {
|
for (File file : files) {
|
||||||
command.add(file.getPath());
|
command.add(file.getPath());
|
||||||
|
|||||||
@@ -32,14 +32,12 @@ class Java9ModulesIntegrationTest : AbstractKotlinCompilerIntegrationTest() {
|
|||||||
addModules: List<String> = emptyList(),
|
addModules: List<String> = emptyList(),
|
||||||
manifest: Manifest? = null
|
manifest: Manifest? = null
|
||||||
): File {
|
): File {
|
||||||
val jdk9Home = KotlinTestUtils.getJdk9HomeIfPossible() ?: return File("<test-skipped>")
|
|
||||||
|
|
||||||
val paths = (modulePath + ForTestCompileRuntime.runtimeJarForTests()).joinToString(separator = File.pathSeparator) { it.path }
|
val paths = (modulePath + ForTestCompileRuntime.runtimeJarForTests()).joinToString(separator = File.pathSeparator) { it.path }
|
||||||
|
|
||||||
val kotlinOptions = mutableListOf(
|
val kotlinOptions = mutableListOf(
|
||||||
"-jdk-home", jdk9Home.path,
|
"-jdk-home", KotlinTestUtils.getJdk9Home().path,
|
||||||
"-jvm-target", "1.8",
|
"-jvm-target", "1.8",
|
||||||
"-Xmodule-path=$paths"
|
"-Xmodule-path=$paths"
|
||||||
)
|
)
|
||||||
if (addModules.isNotEmpty()) {
|
if (addModules.isNotEmpty()) {
|
||||||
kotlinOptions += "-Xadd-modules=${addModules.joinToString()}"
|
kotlinOptions += "-Xadd-modules=${addModules.joinToString()}"
|
||||||
@@ -160,11 +158,10 @@ class Java9ModulesIntegrationTest : AbstractKotlinCompilerIntegrationTest() {
|
|||||||
fun testSpecifyPathToModuleInfoInArguments() {
|
fun testSpecifyPathToModuleInfoInArguments() {
|
||||||
val a = module("moduleA")
|
val a = module("moduleA")
|
||||||
|
|
||||||
val jdk9Home = KotlinTestUtils.getJdk9HomeIfPossible() ?: return
|
|
||||||
val kotlinOptions = mutableListOf(
|
val kotlinOptions = mutableListOf(
|
||||||
"$testDataDirectory/someOtherDirectoryWithTheActualModuleInfo/module-info.java",
|
"$testDataDirectory/someOtherDirectoryWithTheActualModuleInfo/module-info.java",
|
||||||
"-jdk-home", jdk9Home.path,
|
"-jdk-home", KotlinTestUtils.getJdk9Home().path,
|
||||||
"-Xmodule-path=${a.path}"
|
"-Xmodule-path=${a.path}"
|
||||||
)
|
)
|
||||||
compileLibrary(
|
compileLibrary(
|
||||||
"moduleB",
|
"moduleB",
|
||||||
@@ -175,8 +172,6 @@ class Java9ModulesIntegrationTest : AbstractKotlinCompilerIntegrationTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun testMultiReleaseLibrary() {
|
fun testMultiReleaseLibrary() {
|
||||||
val jdk9Home = KotlinTestUtils.getJdk9HomeIfPossible() ?: return
|
|
||||||
|
|
||||||
val librarySrc = FileUtil.findFilesByMask(JAVA_FILES, File(testDataDirectory, "library"))
|
val librarySrc = FileUtil.findFilesByMask(JAVA_FILES, File(testDataDirectory, "library"))
|
||||||
val libraryOut = File(tmpdir, "out")
|
val libraryOut = File(tmpdir, "out")
|
||||||
KotlinTestUtils.compileJavaFilesExternallyWithJava9(librarySrc, listOf("-d", libraryOut.path))
|
KotlinTestUtils.compileJavaFilesExternallyWithJava9(librarySrc, listOf("-d", libraryOut.path))
|
||||||
@@ -186,7 +181,9 @@ class Java9ModulesIntegrationTest : AbstractKotlinCompilerIntegrationTest() {
|
|||||||
File(libraryOut, "module-info.class").renameTo(File(libraryOut9, "module-info.class"))
|
File(libraryOut, "module-info.class").renameTo(File(libraryOut9, "module-info.class"))
|
||||||
|
|
||||||
// Use the name other from 'library' to prevent it from being loaded as an automatic module if module-info.class is not found
|
// Use the name other from 'library' to prevent it from being loaded as an automatic module if module-info.class is not found
|
||||||
val libraryJar = createMultiReleaseJar(jdk9Home, File(tmpdir, "multi-release-library.jar"), libraryOut, libraryOut9)
|
val libraryJar = createMultiReleaseJar(
|
||||||
|
KotlinTestUtils.getJdk9Home(), File(tmpdir, "multi-release-library.jar"), libraryOut, libraryOut9
|
||||||
|
)
|
||||||
|
|
||||||
module("main", listOf(libraryJar))
|
module("main", listOf(libraryJar))
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-4
@@ -103,10 +103,9 @@ public class PluginTestCaseBase {
|
|||||||
case MOCK_JDK:
|
case MOCK_JDK:
|
||||||
return mockJdk();
|
return mockJdk();
|
||||||
case FULL_JDK_9:
|
case FULL_JDK_9:
|
||||||
File jre9 = KotlinTestUtils.getJdk9HomeIfPossible();
|
String jre9 = KotlinTestUtils.getJdk9Home().getPath();
|
||||||
assert jre9 != null : "JDK_19 environment variable is not set";
|
VfsRootAccess.allowRootAccess(jre9);
|
||||||
VfsRootAccess.allowRootAccess(jre9.getPath());
|
return getSdk(jre9, "Full JDK 9");
|
||||||
return getSdk(jre9.getPath(), "Full JDK 9");
|
|
||||||
case FULL_JDK:
|
case FULL_JDK:
|
||||||
return fullJdk();
|
return fullJdk();
|
||||||
default:
|
default:
|
||||||
|
|||||||
+12
-20
@@ -26,49 +26,41 @@ import org.jetbrains.kotlin.test.TestJdkKind.FULL_JDK_9
|
|||||||
class Java9MultiModuleHighlightingTest : AbstractMultiModuleHighlightingTest() {
|
class Java9MultiModuleHighlightingTest : AbstractMultiModuleHighlightingTest() {
|
||||||
override fun getTestDataPath(): String = PluginTestCaseBase.getTestDataPathBase() + "/multiModuleHighlighting/java9/"
|
override fun getTestDataPath(): String = PluginTestCaseBase.getTestDataPathBase() + "/multiModuleHighlighting/java9/"
|
||||||
|
|
||||||
private inline fun doTest(test: () -> Unit) {
|
|
||||||
// Skip this test if no Java 9 is found
|
|
||||||
if (KotlinTestUtils.getJdk9HomeIfPossible() != null) {
|
|
||||||
test()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun module(name: String): Module = super.module(name, FULL_JDK_9, false)
|
private fun module(name: String): Module = super.module(name, FULL_JDK_9, false)
|
||||||
|
|
||||||
fun testSimpleModuleExportsPackage() = doTest {
|
fun testSimpleModuleExportsPackage() {
|
||||||
module("main").addDependency(module("dependency"))
|
module("main").addDependency(module("dependency"))
|
||||||
checkHighlightingInAllFiles()
|
checkHighlightingInAllFiles()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testSimpleLibraryExportsPackage() = doTest {
|
fun testSimpleLibraryExportsPackage() {
|
||||||
val jdk9Home = KotlinTestUtils.getJdk9HomeIfPossible() ?: return
|
|
||||||
// -Xallow-kotlin-package to avoid "require kotlin.stdlib" in module-info.java
|
// -Xallow-kotlin-package to avoid "require kotlin.stdlib" in module-info.java
|
||||||
val library = MockLibraryUtil.compileJvmLibraryToJar(
|
val library = MockLibraryUtil.compileJvmLibraryToJar(
|
||||||
testDataPath + "${getTestName(true)}/library", "library",
|
testDataPath + "${getTestName(true)}/library", "library",
|
||||||
extraOptions = listOf("-jdk-home", jdk9Home.path, "-Xallow-kotlin-package"),
|
extraOptions = listOf("-jdk-home", KotlinTestUtils.getJdk9Home().path, "-Xallow-kotlin-package"),
|
||||||
useJava9 = true
|
useJava9 = true
|
||||||
)
|
)
|
||||||
|
|
||||||
module("main").addLibrary(library, "library")
|
module("main").addLibrary(library, "library")
|
||||||
checkHighlightingInAllFiles()
|
checkHighlightingInAllFiles()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testNamedDependsOnUnnamed() = doTest {
|
fun testNamedDependsOnUnnamed() {
|
||||||
module("main").addDependency(module("dependency"))
|
module("main").addDependency(module("dependency"))
|
||||||
checkHighlightingInAllFiles()
|
checkHighlightingInAllFiles()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testUnnamedDependsOnNamed() = doTest {
|
fun testUnnamedDependsOnNamed() {
|
||||||
module("main").addDependency(module("dependency"))
|
module("main").addDependency(module("dependency"))
|
||||||
checkHighlightingInAllFiles()
|
checkHighlightingInAllFiles()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testDeclarationKinds() = doTest {
|
fun testDeclarationKinds() {
|
||||||
module("main").addDependency(module("dependency"))
|
module("main").addDependency(module("dependency"))
|
||||||
checkHighlightingInAllFiles()
|
checkHighlightingInAllFiles()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testExportsTo() = doTest {
|
fun testExportsTo() {
|
||||||
val d = module("dependency")
|
val d = module("dependency")
|
||||||
module("first").addDependency(d)
|
module("first").addDependency(d)
|
||||||
module("second").addDependency(d)
|
module("second").addDependency(d)
|
||||||
@@ -76,17 +68,17 @@ class Java9MultiModuleHighlightingTest : AbstractMultiModuleHighlightingTest() {
|
|||||||
checkHighlightingInAllFiles()
|
checkHighlightingInAllFiles()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testExportedPackageIsInaccessibleWithoutRequires() = doTest {
|
fun testExportedPackageIsInaccessibleWithoutRequires() {
|
||||||
module("main").addDependency(module("dependency"))
|
module("main").addDependency(module("dependency"))
|
||||||
checkHighlightingInAllFiles()
|
checkHighlightingInAllFiles()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testTypealiasToUnexported() = doTest {
|
fun testTypealiasToUnexported() {
|
||||||
module("main").addDependency(module("dependency"))
|
module("main").addDependency(module("dependency"))
|
||||||
checkHighlightingInAllFiles()
|
checkHighlightingInAllFiles()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testCyclicDependency() = doTest {
|
fun testCyclicDependency() {
|
||||||
val a = module("moduleA")
|
val a = module("moduleA")
|
||||||
val b = module("moduleB")
|
val b = module("moduleB")
|
||||||
val c = module("moduleC")
|
val c = module("moduleC")
|
||||||
|
|||||||
@@ -977,10 +977,10 @@ open class KotlinJpsBuildTest : AbstractKotlinJpsBuildTestCase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun testJre9() {
|
fun testJre9() {
|
||||||
val path = KotlinTestUtils.getJdk9HomeIfPossible()?.absolutePath ?: return
|
val jdk9Path = KotlinTestUtils.getJdk9Home().absolutePath
|
||||||
|
|
||||||
val jdk = myModel.global.addSdk(JDK_NAME, path, "9", JpsJavaSdkType.INSTANCE)
|
val jdk = myModel.global.addSdk(JDK_NAME, jdk9Path, "9", JpsJavaSdkType.INSTANCE)
|
||||||
jdk.addRoot(StandardFileSystems.JRT_PROTOCOL_PREFIX + path + URLUtil.JAR_SEPARATOR + "java.base", JpsOrderRootType.COMPILED)
|
jdk.addRoot(StandardFileSystems.JRT_PROTOCOL_PREFIX + jdk9Path + URLUtil.JAR_SEPARATOR + "java.base", JpsOrderRootType.COMPILED)
|
||||||
|
|
||||||
loadProject(workDir.absolutePath + File.separator + PROJECT_NAME + ".ipr")
|
loadProject(workDir.absolutePath + File.separator + PROJECT_NAME + ".ipr")
|
||||||
addKotlinStdlibDependency()
|
addKotlinStdlibDependency()
|
||||||
|
|||||||
@@ -32,11 +32,7 @@ interface Java9TestLauncher {
|
|||||||
//TODO unmute after investigation (tests are failing on TeamCity)
|
//TODO unmute after investigation (tests are failing on TeamCity)
|
||||||
if (SystemInfoRt.isWindows) return
|
if (SystemInfoRt.isWindows) return
|
||||||
|
|
||||||
val jdk9Home = KotlinTestUtils.getJdk9HomeIfPossible() ?: run {
|
val jdk9Home = KotlinTestUtils.getJdk9Home()
|
||||||
println("JDK9 not found, the test was skipped")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
val javaExe = File(jdk9Home, "bin/java.exe").takeIf { it.exists() } ?: File(jdk9Home, "bin/java")
|
val javaExe = File(jdk9Home, "bin/java.exe").takeIf { it.exists() } ?: File(jdk9Home, "bin/java")
|
||||||
assert(javaExe.exists()) { "Can't find 'java' executable in $jdk9Home" }
|
assert(javaExe.exists()) { "Can't find 'java' executable in $jdk9Home" }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user