diff --git a/compiler/testData/diagnostics/testsWithJava9/kt11167.kt b/compiler/testData/diagnostics/testsWithJava9/kt11167.kt new file mode 100644 index 00000000000..18b016c0f84 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJava9/kt11167.kt @@ -0,0 +1,13 @@ +import java.util.stream.IntStream + +fun foo(s: IntStream) { + val n = 1000000000 + val delta = 1.0 / n + val startTimeNanos = System.nanoTime() + val pi = 4.0 * delta * s.mapToDouble { i -> + val x = (i - 0.5) * delta + 1.0 / (1.0 + x * x) + }.sum() + val elapseTime = (System.nanoTime() - startTimeNanos) / 1e9 + println("Parallel Streams $pi $n $elapseTime") +} diff --git a/compiler/testData/diagnostics/testsWithJava9/kt11167.txt b/compiler/testData/diagnostics/testsWithJava9/kt11167.txt new file mode 100644 index 00000000000..3df4f0756f8 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJava9/kt11167.txt @@ -0,0 +1,3 @@ +package + +public fun foo(/*0*/ s: java.util.stream.IntStream): kotlin.Unit diff --git a/compiler/tests-common/org/jetbrains/kotlin/test/KotlinTestUtils.java b/compiler/tests-common/org/jetbrains/kotlin/test/KotlinTestUtils.java index 30311527209..4e5c0b3cfbf 100644 --- a/compiler/tests-common/org/jetbrains/kotlin/test/KotlinTestUtils.java +++ b/compiler/tests-common/org/jetbrains/kotlin/test/KotlinTestUtils.java @@ -459,7 +459,18 @@ public class KotlinTestUtils { JvmContentRootsKt.addJvmClasspathRoot(configuration, findAndroidApiJar()); } else if (jdkKind == TestJdkKind.FULL_JDK_6) { - JvmContentRootsKt.addJvmClasspathRoots(configuration, PathUtil.getJdkClassesRootsFromJre(getJre6Home())); + String jdk6 = System.getenv("JDK_16"); + assert jdk6 != null : "Environment variable JDK_16 is not set"; + JvmContentRootsKt.addJvmClasspathRoots(configuration, PathUtil.getJdkClassesRootsFromJre(getJreHome(jdk6))); + } + else if (jdkKind == TestJdkKind.FULL_JDK_9) { + String jdk9 = System.getenv("JDK_9"); + if (jdk9 != null) { + JvmContentRootsKt.addJvmClasspathRoots(configuration, PathUtil.getJdkClassesRootsFromJre(getJreHome(jdk9))); + } + else { + System.err.println("Environment variable JDK_9 is not set, the test will be skipped"); + } } else { JvmContentRootsKt.addJvmClasspathRoots(configuration, PathUtil.getJdkClassesRootsFromCurrentJre()); @@ -484,12 +495,9 @@ public class KotlinTestUtils { } @NotNull - private static String getJre6Home() { - String home = System.getenv("JDK_16"); - if (home == null) throw new AssertionError("Environment variable JDK_16 is not set"); - - File jre = new File(home, "jre"); - return jre.isDirectory() ? jre.getPath() : home; + 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 { diff --git a/compiler/tests-common/org/jetbrains/kotlin/test/TestJdkKind.java b/compiler/tests-common/org/jetbrains/kotlin/test/TestJdkKind.java index 32592eb9675..701ff5ecbc5 100644 --- a/compiler/tests-common/org/jetbrains/kotlin/test/TestJdkKind.java +++ b/compiler/tests-common/org/jetbrains/kotlin/test/TestJdkKind.java @@ -23,6 +23,8 @@ public enum TestJdkKind { MODIFIED_MOCK_JDK, // JDK found at $JDK_16 FULL_JDK_6, + // JDK found at $JDK_9 + FULL_JDK_9, // JDK found at java.home FULL_JDK, ANDROID_API, diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/AbstractDiagnosticsWithJdk9Test.java b/compiler/tests/org/jetbrains/kotlin/checkers/AbstractDiagnosticsWithJdk9Test.java new file mode 100644 index 00000000000..5ff32218e4f --- /dev/null +++ b/compiler/tests/org/jetbrains/kotlin/checkers/AbstractDiagnosticsWithJdk9Test.java @@ -0,0 +1,52 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.checkers; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.kotlin.test.ConfigurationKind; +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 + @Override + protected ConfigurationKind getConfigurationKind() { + return ConfigurationKind.ALL; + } + + @NotNull + @Override + protected TestJdkKind getTestJdkKind() { + return TestJdkKind.FULL_JDK_9; + } + + @Override + protected void doMultiFileTest( + @NotNull File file, + @NotNull Map modules, + @NotNull List testFiles + ) { + if (System.getenv("JDK_9") == null) { + // Skip this test if no environment variable JDK_9 is set up + return; + } + super.doMultiFileTest(file, modules, testFiles); + } +} diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsWithJdk9TestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsWithJdk9TestGenerated.java new file mode 100644 index 00000000000..388ce15042d --- /dev/null +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsWithJdk9TestGenerated.java @@ -0,0 +1,44 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.checkers; + +import com.intellij.testFramework.TestDataPath; +import org.jetbrains.kotlin.test.JUnit3RunnerWithInners; +import org.jetbrains.kotlin.test.KotlinTestUtils; +import org.jetbrains.kotlin.test.TargetBackend; +import org.jetbrains.kotlin.test.TestMetadata; +import org.junit.runner.RunWith; + +import java.io.File; +import java.util.regex.Pattern; + +/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ +@SuppressWarnings("all") +@TestMetadata("compiler/testData/diagnostics/testsWithJava9") +@TestDataPath("$PROJECT_ROOT") +@RunWith(JUnit3RunnerWithInners.class) +public class DiagnosticsWithJdk9TestGenerated extends AbstractDiagnosticsWithJdk9Test { + public void testAllFilesPresentInTestsWithJava9() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/testsWithJava9"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("kt11167.kt") + public void testKt11167() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJava9/kt11167.kt"); + doTest(fileName); + } +} diff --git a/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt b/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt index 31b04ea10c2..f557ffb8332 100755 --- a/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt +++ b/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt @@ -205,6 +205,10 @@ fun main(args: Array) { model("diagnostics/testWithModifiedMockJdk") } + testClass { + model("diagnostics/testsWithJava9") + } + testClass { model("multiplatform", extension = null, recursive = true, excludeParentDirs = true) }