Add simple JDK15 BlackBox test
^KT-43677 In Progress
This commit is contained in:
@@ -0,0 +1,20 @@
|
|||||||
|
// FILE: MyRec.java
|
||||||
|
public record MyRec(String name) implements KI {
|
||||||
|
public String getName() {
|
||||||
|
return "OK";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: main.kt
|
||||||
|
|
||||||
|
interface KI {
|
||||||
|
val name: String
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val r = MyRec("fail")
|
||||||
|
if (r.name() != "fail") return "fail 1"
|
||||||
|
if ((r as KI).name != "OK") return "fail 2"
|
||||||
|
|
||||||
|
return r.name
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
// FILE: MyRec.java
|
||||||
|
public record MyRec(String name) {
|
||||||
|
public String getName() {
|
||||||
|
return "OK";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: main.kt
|
||||||
|
fun box(): String {
|
||||||
|
val r = MyRec("fail")
|
||||||
|
if (r.name() != "fail") return "fail 1"
|
||||||
|
if (r.getName() != "OK") return "fail 2"
|
||||||
|
|
||||||
|
return r.name
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
// FILE: MyRec.java
|
||||||
|
public record MyRec(String name) {}
|
||||||
|
|
||||||
|
// FILE: recordPropertyAccess.kt
|
||||||
|
fun box(): String {
|
||||||
|
val r = MyRec("OK")
|
||||||
|
if (r.name() != "OK") return "fail 1"
|
||||||
|
|
||||||
|
return r.name
|
||||||
|
}
|
||||||
+1
-1
@@ -136,7 +136,7 @@ public abstract class AbstractBlackBoxCodegenTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private static String getFacadeFqName(@NotNull KtFile file) {
|
protected static String getFacadeFqName(@NotNull KtFile file) {
|
||||||
return CodegenUtil.getMemberDeclarationsToGenerate(file).isEmpty()
|
return CodegenUtil.getMemberDeclarationsToGenerate(file).isEmpty()
|
||||||
? null
|
? null
|
||||||
: JvmFileClassUtil.getFileClassInfoNoResolve(file).getFacadeClassFqName().asString();
|
: JvmFileClassUtil.getFileClassInfoNoResolve(file).getFacadeClassFqName().asString();
|
||||||
|
|||||||
+81
@@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* 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
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.cli.common.output.writeAll
|
||||||
|
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime
|
||||||
|
import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils
|
||||||
|
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.concurrent.TimeUnit
|
||||||
|
|
||||||
|
abstract class AbstractCustomJDKBlackBoxCodegenTest : AbstractBlackBoxCodegenTest() {
|
||||||
|
@Throws(Exception::class)
|
||||||
|
override fun doTest(filePath: String) {
|
||||||
|
val file = File(filePath)
|
||||||
|
val expectedText =
|
||||||
|
KotlinTestUtils.doLoadFile(file) +
|
||||||
|
"\n" +
|
||||||
|
"""
|
||||||
|
fun main() {
|
||||||
|
val res = box()
|
||||||
|
if (res != "OK") throw AssertionError(res)
|
||||||
|
}
|
||||||
|
""".trimIndent()
|
||||||
|
val testFiles = createTestFilesFromFile(file, expectedText)
|
||||||
|
doMultiFileTest(file, testFiles)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun extractConfigurationKind(files: List<TestFile>): ConfigurationKind {
|
||||||
|
return ConfigurationKind.NO_KOTLIN_REFLECT
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun runJavacTask(files: MutableCollection<File>, options: List<String>) {
|
||||||
|
KotlinTestUtils.compileJavaFilesExternally(files, options + getAdditionalJavacArgs(), getJdkHome())
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getTestJdkKind(files: List<TestFile>): TestJdkKind {
|
||||||
|
return getTestJdkKind()
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract fun getTestJdkKind(): TestJdkKind
|
||||||
|
abstract fun getJdkHome(): File
|
||||||
|
|
||||||
|
open fun getAdditionalJavacArgs(): List<String> = emptyList()
|
||||||
|
open fun getAdditionalJvmArgs(): List<String> = emptyList()
|
||||||
|
|
||||||
|
abstract override fun getPrefix(): String
|
||||||
|
|
||||||
|
override fun blackBox(reportProblems: Boolean, unexpectedBehaviour: Boolean) {
|
||||||
|
val tmpdir = KotlinTestUtils.tmpDirForTest(this)
|
||||||
|
val fileFactory = generateClassesInFile()
|
||||||
|
fileFactory.writeAll(tmpdir, null)
|
||||||
|
|
||||||
|
val jdkHome = getJdkHome()
|
||||||
|
val javaExe = File(jdkHome, "bin/java.exe").takeIf(File::exists)
|
||||||
|
?: File(jdkHome, "bin/java").takeIf(File::exists)
|
||||||
|
?: error("Can't find 'java' executable in $jdkHome")
|
||||||
|
|
||||||
|
|
||||||
|
val command = arrayOf(
|
||||||
|
javaExe.absolutePath,
|
||||||
|
"-ea",
|
||||||
|
*getAdditionalJvmArgs().toTypedArray(),
|
||||||
|
"-classpath",
|
||||||
|
listOfNotNull(
|
||||||
|
tmpdir, ForTestCompileRuntime.runtimeJarForTests(),
|
||||||
|
javaClassesOutputDirectory
|
||||||
|
).joinToString(File.pathSeparator, transform = File::getAbsolutePath),
|
||||||
|
getFacadeFqName(myFiles.psiFile)
|
||||||
|
)
|
||||||
|
|
||||||
|
val process = ProcessBuilder(*command).inheritIO().start()
|
||||||
|
process.waitFor(1, TimeUnit.MINUTES)
|
||||||
|
assertEquals(0, process.exitValue())
|
||||||
|
}
|
||||||
|
}
|
||||||
+20
@@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* 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
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.jvm.compiler.ADDITIONAL_JAVAC_ARGS_FOR_15
|
||||||
|
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||||
|
import org.jetbrains.kotlin.test.TestJdkKind
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
abstract class AbstractJdk15BlackBoxCodegenTest : AbstractCustomJDKBlackBoxCodegenTest() {
|
||||||
|
override fun getTestJdkKind(): TestJdkKind = TestJdkKind.FULL_JDK_15
|
||||||
|
override fun getJdkHome(): File = KotlinTestUtils.getJdk15Home()
|
||||||
|
override fun getPrefix(): String = "java15/box"
|
||||||
|
|
||||||
|
override fun getAdditionalJavacArgs(): List<String> = ADDITIONAL_JAVAC_ARGS_FOR_15
|
||||||
|
override fun getAdditionalJvmArgs(): List<String> = listOf("--enable-preview")
|
||||||
|
}
|
||||||
@@ -58,6 +58,7 @@ import java.net.MalformedURLException;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.jetbrains.kotlin.cli.common.output.OutputUtilsKt.writeAllTo;
|
import static org.jetbrains.kotlin.cli.common.output.OutputUtilsKt.writeAllTo;
|
||||||
import static org.jetbrains.kotlin.codegen.CodegenTestUtil.*;
|
import static org.jetbrains.kotlin.codegen.CodegenTestUtil.*;
|
||||||
@@ -529,10 +530,24 @@ public abstract class CodegenTestCase extends KotlinBaseTest<KotlinBaseTest.Test
|
|||||||
|
|
||||||
javaClassesOutputDirectory = getJavaClassesOutputDirectory();
|
javaClassesOutputDirectory = getJavaClassesOutputDirectory();
|
||||||
List<String> javacOptions = extractJavacOptions(files, configuration.get(JVMConfigurationKeys.JVM_TARGET));
|
List<String> javacOptions = extractJavacOptions(files, configuration.get(JVMConfigurationKeys.JVM_TARGET));
|
||||||
compileJava(findJavaSourcesInDirectory(javaSourceDir), javaClasspath, javacOptions, javaClassesOutputDirectory);
|
List<String> finalJavacOptions = prepareJavacOptions(javaClasspath, javacOptions, javaClassesOutputDirectory);
|
||||||
|
|
||||||
|
try {
|
||||||
|
runJavacTask(
|
||||||
|
findJavaSourcesInDirectory(javaSourceDir).stream().map(File::new).collect(Collectors.toList()),
|
||||||
|
finalJavacOptions
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
throw ExceptionUtilsKt.rethrow(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void runJavacTask(@NotNull Collection<File> files, @NotNull List<String> options) throws IOException {
|
||||||
|
KotlinTestUtils.compileJavaFiles(files, options);
|
||||||
|
}
|
||||||
|
|
||||||
protected void updateJavaClasspath(@NotNull List<String> javaClasspath) {}
|
protected void updateJavaClasspath(@NotNull List<String> javaClasspath) {}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -101,18 +101,7 @@ public class CodegenTestUtil {
|
|||||||
@NotNull File outDirectory
|
@NotNull File outDirectory
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
List<String> classpath = new ArrayList<>();
|
List<String> options = prepareJavacOptions(additionalClasspath, additionalOptions, outDirectory);
|
||||||
classpath.add(ForTestCompileRuntime.runtimeJarForTests().getPath());
|
|
||||||
classpath.add(ForTestCompileRuntime.reflectJarForTests().getPath());
|
|
||||||
classpath.add(KotlinTestUtils.getAnnotationsJar().getPath());
|
|
||||||
classpath.addAll(additionalClasspath);
|
|
||||||
|
|
||||||
List<String> options = new ArrayList<>(Arrays.asList(
|
|
||||||
"-classpath", StringsKt.join(classpath, File.pathSeparator),
|
|
||||||
"-d", outDirectory.getPath()
|
|
||||||
));
|
|
||||||
options.addAll(additionalOptions);
|
|
||||||
|
|
||||||
KotlinTestUtils.compileJavaFiles(CollectionsKt.map(fileNames, File::new), options);
|
KotlinTestUtils.compileJavaFiles(CollectionsKt.map(fileNames, File::new), options);
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
@@ -120,6 +109,27 @@ public class CodegenTestUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static List<String> prepareJavacOptions(
|
||||||
|
@NotNull List<String> additionalClasspath,
|
||||||
|
@NotNull List<String> additionalOptions,
|
||||||
|
@NotNull File outDirectory
|
||||||
|
) {
|
||||||
|
List<String> classpath = new ArrayList<>();
|
||||||
|
classpath.add(ForTestCompileRuntime.runtimeJarForTests().getPath());
|
||||||
|
classpath.add(ForTestCompileRuntime.reflectJarForTests().getPath());
|
||||||
|
classpath.add(KotlinTestUtils.getAnnotationsJar().getPath());
|
||||||
|
classpath.addAll(additionalClasspath);
|
||||||
|
|
||||||
|
List<String> options = new ArrayList<>(Arrays.asList(
|
||||||
|
"-classpath", StringsKt.join(classpath, File.pathSeparator),
|
||||||
|
"-d", outDirectory.getPath()
|
||||||
|
));
|
||||||
|
options.addAll(additionalOptions);
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static Method findTheOnlyMethod(@NotNull Class<?> aClass) {
|
public static Method findTheOnlyMethod(@NotNull Class<?> aClass) {
|
||||||
Method r = null;
|
Method r = null;
|
||||||
|
|||||||
+45
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import com.intellij.testFramework.TestDataPath;
|
||||||
|
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
|
||||||
|
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||||
|
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/codegen/java15/box")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
public class Jdk15BlackBoxCodegenTestGenerated extends AbstractJdk15BlackBoxCodegenTest {
|
||||||
|
private void runTest(String testDataFilePath) throws Exception {
|
||||||
|
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAllFilesPresentInBox() throws Exception {
|
||||||
|
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/java15/box"), Pattern.compile("^(.+)\\.kt$"), null, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("recordDifferentPropertyOverride.kt")
|
||||||
|
public void testRecordDifferentPropertyOverride() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/java15/box/recordDifferentPropertyOverride.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("recordDifferentSyntheticProperty.kt")
|
||||||
|
public void testRecordDifferentSyntheticProperty() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/java15/box/recordDifferentSyntheticProperty.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("recordPropertyAccess.kt")
|
||||||
|
public void testRecordPropertyAccess() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/java15/box/recordPropertyAccess.kt");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -211,6 +211,10 @@ fun main(args: Array<String>) {
|
|||||||
model("codegen/boxAgainstJava")
|
model("codegen/boxAgainstJava")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testClass<AbstractJdk15BlackBoxCodegenTest> {
|
||||||
|
model("codegen/java15/box")
|
||||||
|
}
|
||||||
|
|
||||||
testClass<AbstractScriptCodegenTest> {
|
testClass<AbstractScriptCodegenTest> {
|
||||||
model("codegen/script", extension = "kts")
|
model("codegen/script", extension = "kts")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user