From c6d61346dd4e8463428d5988e5892be9a8e68b5d Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Wed, 5 Jun 2019 18:55:34 +0200 Subject: [PATCH] Avoid compiling Java files twice in boxAgainstJava tests After b602c08773, this test started to put all .java files to the dependencies when compiling .kt files, _in addition_ to the already compiled class files from those Java sources. This is incorrect because the test should actually check how Kotlin compiles _against_ Java binaries. The other behavior (compiling against Java sources) is already supported and used in normal box tests with .java sources. However, we can't simply filter out all .java files before calling `super.doMultiFileTest` because many of those contain directives (WITH_RUNTIME, FULL_JDK, etc.) and we should load them in `CodegenTestCase.compile`. As a workaround, remove '.java' file extension to prevent their compilation but still be able to resolve directives. --- .../codegen/AbstractBlackBoxAgainstJavaCodegenTest.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/AbstractBlackBoxAgainstJavaCodegenTest.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/AbstractBlackBoxAgainstJavaCodegenTest.kt index 06d9573617a..072c5c51f89 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/AbstractBlackBoxAgainstJavaCodegenTest.kt +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/AbstractBlackBoxAgainstJavaCodegenTest.kt @@ -27,7 +27,12 @@ abstract class AbstractBlackBoxAgainstJavaCodegenTest : AbstractBlackBoxCodegenT CodegenTestUtil.compileJava(CodegenTestUtil.findJavaSourcesInDirectory(directory), emptyList(), extractJavacOptions(files)) } - super.doMultiFileTest(wholeFile, files) + super.doMultiFileTest(wholeFile, files.map { file -> + // This is a hack which allows to avoid compiling Java sources for the second time (which would be incorrect in this test), + // while also retaining content of all Java sources so that we could find and use test directives in Java sources + // in CodegenTestCase.compile. + if (file.name.endsWith(".java")) TestFile("${file.name}.disabled", file.content) else file + }) } override fun updateConfiguration(configuration: CompilerConfiguration) {