Enable all Java 9 tests

This commit is contained in:
Alexander Udalov
2018-02-14 13:13:24 +01:00
parent 914cf18051
commit d2ed73eb78
7 changed files with 37 additions and 83 deletions
@@ -18,12 +18,9 @@ package org.jetbrains.kotlin.checkers;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.test.ConfigurationKind;
import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.test.TestJdkKind;
import java.io.File;
import java.util.List;
import java.util.Map;
public abstract class AbstractDiagnosticsWithJdk9Test extends AbstractDiagnosticsTest {
@NotNull
@@ -37,17 +34,4 @@ public abstract class AbstractDiagnosticsWithJdk9Test extends AbstractDiagnostic
protected TestJdkKind getTestJdkKind(@NotNull File file) {
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));
}
else if (jdkKind == TestJdkKind.FULL_JDK_9) {
File home = getJdk9HomeIfPossible();
if (home != null) {
configuration.put(JVMConfigurationKeys.JDK_HOME, home);
}
configuration.put(JVMConfigurationKeys.JDK_HOME, getJdk9Home());
}
else if (SystemInfo.IS_AT_LEAST_JAVA9) {
configuration.put(JVMConfigurationKeys.JDK_HOME, new File(System.getProperty("java.home")));
@@ -587,26 +584,18 @@ public class KotlinTestUtils {
return configuration;
}
@Nullable
public static File getJdk9HomeIfPossible() {
String jdk9 = System.getenv("JDK_19");
@NotNull
public static File getJdk9Home() {
String jdk9 = System.getenv("JDK_9");
if (jdk9 == null) {
jdk9 = System.getenv("JDK_9");
}
if (jdk9 == null) {
// 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;
jdk9 = System.getenv("JDK_19");
if (jdk9 == null) {
throw new AssertionError("Environment variable JDK_9 is not set!");
}
}
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 {
List<String> paths = ContentRootsKt.getKotlinSourceRoots(environment.getConfiguration());
if (paths.isEmpty()) return;
@@ -982,11 +971,8 @@ public class KotlinTestUtils {
}
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<>();
command.add(new File(jdk9, "bin/javac").getPath());
command.add(new File(getJdk9Home(), "bin/javac").getPath());
command.addAll(options);
for (File file : files) {
command.add(file.getPath());
@@ -32,14 +32,12 @@ class Java9ModulesIntegrationTest : AbstractKotlinCompilerIntegrationTest() {
addModules: List<String> = emptyList(),
manifest: Manifest? = null
): File {
val jdk9Home = KotlinTestUtils.getJdk9HomeIfPossible() ?: return File("<test-skipped>")
val paths = (modulePath + ForTestCompileRuntime.runtimeJarForTests()).joinToString(separator = File.pathSeparator) { it.path }
val kotlinOptions = mutableListOf(
"-jdk-home", jdk9Home.path,
"-jvm-target", "1.8",
"-Xmodule-path=$paths"
"-jdk-home", KotlinTestUtils.getJdk9Home().path,
"-jvm-target", "1.8",
"-Xmodule-path=$paths"
)
if (addModules.isNotEmpty()) {
kotlinOptions += "-Xadd-modules=${addModules.joinToString()}"
@@ -160,11 +158,10 @@ class Java9ModulesIntegrationTest : AbstractKotlinCompilerIntegrationTest() {
fun testSpecifyPathToModuleInfoInArguments() {
val a = module("moduleA")
val jdk9Home = KotlinTestUtils.getJdk9HomeIfPossible() ?: return
val kotlinOptions = mutableListOf(
"$testDataDirectory/someOtherDirectoryWithTheActualModuleInfo/module-info.java",
"-jdk-home", jdk9Home.path,
"-Xmodule-path=${a.path}"
"$testDataDirectory/someOtherDirectoryWithTheActualModuleInfo/module-info.java",
"-jdk-home", KotlinTestUtils.getJdk9Home().path,
"-Xmodule-path=${a.path}"
)
compileLibrary(
"moduleB",
@@ -175,8 +172,6 @@ class Java9ModulesIntegrationTest : AbstractKotlinCompilerIntegrationTest() {
}
fun testMultiReleaseLibrary() {
val jdk9Home = KotlinTestUtils.getJdk9HomeIfPossible() ?: return
val librarySrc = FileUtil.findFilesByMask(JAVA_FILES, File(testDataDirectory, "library"))
val libraryOut = File(tmpdir, "out")
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"))
// 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))
}
@@ -103,10 +103,9 @@ public class PluginTestCaseBase {
case MOCK_JDK:
return mockJdk();
case FULL_JDK_9:
File jre9 = KotlinTestUtils.getJdk9HomeIfPossible();
assert jre9 != null : "JDK_19 environment variable is not set";
VfsRootAccess.allowRootAccess(jre9.getPath());
return getSdk(jre9.getPath(), "Full JDK 9");
String jre9 = KotlinTestUtils.getJdk9Home().getPath();
VfsRootAccess.allowRootAccess(jre9);
return getSdk(jre9, "Full JDK 9");
case FULL_JDK:
return fullJdk();
default:
@@ -26,49 +26,41 @@ import org.jetbrains.kotlin.test.TestJdkKind.FULL_JDK_9
class Java9MultiModuleHighlightingTest : AbstractMultiModuleHighlightingTest() {
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)
fun testSimpleModuleExportsPackage() = doTest {
fun testSimpleModuleExportsPackage() {
module("main").addDependency(module("dependency"))
checkHighlightingInAllFiles()
}
fun testSimpleLibraryExportsPackage() = doTest {
val jdk9Home = KotlinTestUtils.getJdk9HomeIfPossible() ?: return
fun testSimpleLibraryExportsPackage() {
// -Xallow-kotlin-package to avoid "require kotlin.stdlib" in module-info.java
val library = MockLibraryUtil.compileJvmLibraryToJar(
testDataPath + "${getTestName(true)}/library", "library",
extraOptions = listOf("-jdk-home", jdk9Home.path, "-Xallow-kotlin-package"),
useJava9 = true
testDataPath + "${getTestName(true)}/library", "library",
extraOptions = listOf("-jdk-home", KotlinTestUtils.getJdk9Home().path, "-Xallow-kotlin-package"),
useJava9 = true
)
module("main").addLibrary(library, "library")
checkHighlightingInAllFiles()
}
fun testNamedDependsOnUnnamed() = doTest {
fun testNamedDependsOnUnnamed() {
module("main").addDependency(module("dependency"))
checkHighlightingInAllFiles()
}
fun testUnnamedDependsOnNamed() = doTest {
fun testUnnamedDependsOnNamed() {
module("main").addDependency(module("dependency"))
checkHighlightingInAllFiles()
}
fun testDeclarationKinds() = doTest {
fun testDeclarationKinds() {
module("main").addDependency(module("dependency"))
checkHighlightingInAllFiles()
}
fun testExportsTo() = doTest {
fun testExportsTo() {
val d = module("dependency")
module("first").addDependency(d)
module("second").addDependency(d)
@@ -76,17 +68,17 @@ class Java9MultiModuleHighlightingTest : AbstractMultiModuleHighlightingTest() {
checkHighlightingInAllFiles()
}
fun testExportedPackageIsInaccessibleWithoutRequires() = doTest {
fun testExportedPackageIsInaccessibleWithoutRequires() {
module("main").addDependency(module("dependency"))
checkHighlightingInAllFiles()
}
fun testTypealiasToUnexported() = doTest {
fun testTypealiasToUnexported() {
module("main").addDependency(module("dependency"))
checkHighlightingInAllFiles()
}
fun testCyclicDependency() = doTest {
fun testCyclicDependency() {
val a = module("moduleA")
val b = module("moduleB")
val c = module("moduleC")
@@ -977,10 +977,10 @@ open class KotlinJpsBuildTest : AbstractKotlinJpsBuildTestCase() {
}
fun testJre9() {
val path = KotlinTestUtils.getJdk9HomeIfPossible()?.absolutePath ?: return
val jdk9Path = KotlinTestUtils.getJdk9Home().absolutePath
val jdk = myModel.global.addSdk(JDK_NAME, path, "9", JpsJavaSdkType.INSTANCE)
jdk.addRoot(StandardFileSystems.JRT_PROTOCOL_PREFIX + path + URLUtil.JAR_SEPARATOR + "java.base", JpsOrderRootType.COMPILED)
val jdk = myModel.global.addSdk(JDK_NAME, jdk9Path, "9", JpsJavaSdkType.INSTANCE)
jdk.addRoot(StandardFileSystems.JRT_PROTOCOL_PREFIX + jdk9Path + URLUtil.JAR_SEPARATOR + "java.base", JpsOrderRootType.COMPILED)
loadProject(workDir.absolutePath + File.separator + PROJECT_NAME + ".ipr")
addKotlinStdlibDependency()
@@ -32,11 +32,7 @@ interface Java9TestLauncher {
//TODO unmute after investigation (tests are failing on TeamCity)
if (SystemInfoRt.isWindows) return
val jdk9Home = KotlinTestUtils.getJdk9HomeIfPossible() ?: run {
println("JDK9 not found, the test was skipped")
return
}
val jdk9Home = KotlinTestUtils.getJdk9Home()
val javaExe = File(jdk9Home, "bin/java.exe").takeIf { it.exists() } ?: File(jdk9Home, "bin/java")
assert(javaExe.exists()) { "Can't find 'java' executable in $jdk9Home" }