From 9cb740bfdb8b5262ae28ab12862828430a29c04d Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Mon, 26 Apr 2021 10:19:43 +0300 Subject: [PATCH] Fix tests broken in c6fa3634 --- .../cli/jvm/conflictingProjection.out | 3 ++ .../testData/cli/jvm/extendedCheckers.out | 3 ++ .../cli/jvm/extendedCheckersNoWarning.out | 3 ++ compiler/testData/cli/jvm/firError.out | 3 ++ compiler/testData/cli/jvm/firHello.out | 3 ++ .../cli/jvm/inapplicableLateinitModifier.out | 3 ++ .../cli/jvm/instanceAccessBeforeSuperCall.out | 3 ++ .../AbstractKotlinCompilerIntegrationTest.kt | 50 +++++++++++-------- .../jetbrains/kotlin/gradle/BaseGradleIT.kt | 5 +- .../kotlin/gradle/KotlinGradlePluginIT.kt | 12 ++++- 10 files changed, 63 insertions(+), 25 deletions(-) diff --git a/compiler/testData/cli/jvm/conflictingProjection.out b/compiler/testData/cli/jvm/conflictingProjection.out index 3b8f7cc4d34..7c52b2f14c5 100644 --- a/compiler/testData/cli/jvm/conflictingProjection.out +++ b/compiler/testData/cli/jvm/conflictingProjection.out @@ -1,3 +1,6 @@ +warning: ATTENTION! + This build uses in-dev FIR: + -Xuse-fir compiler/testData/cli/jvm/conflictingProjection.kt:10:15: error: projection is conflicting with variance of the corresponding type parameter of Out. Remove the projection or replace it with '*' fun a8(value: Out) {} ^ diff --git a/compiler/testData/cli/jvm/extendedCheckers.out b/compiler/testData/cli/jvm/extendedCheckers.out index 892c5a5f895..aa7f09ef564 100644 --- a/compiler/testData/cli/jvm/extendedCheckers.out +++ b/compiler/testData/cli/jvm/extendedCheckers.out @@ -1,3 +1,6 @@ +warning: ATTENTION! + This build uses in-dev FIR: + -Xuse-fir compiler/testData/cli/jvm/extendedCheckers.kt:2:12: warning: redundant explicit type val i: Int = 1 ^ diff --git a/compiler/testData/cli/jvm/extendedCheckersNoWarning.out b/compiler/testData/cli/jvm/extendedCheckersNoWarning.out index d86bac9de59..b2e67e607be 100644 --- a/compiler/testData/cli/jvm/extendedCheckersNoWarning.out +++ b/compiler/testData/cli/jvm/extendedCheckersNoWarning.out @@ -1 +1,4 @@ +warning: ATTENTION! + This build uses in-dev FIR: + -Xuse-fir OK diff --git a/compiler/testData/cli/jvm/firError.out b/compiler/testData/cli/jvm/firError.out index 4b19f47a1fc..df1c018d1e8 100644 --- a/compiler/testData/cli/jvm/firError.out +++ b/compiler/testData/cli/jvm/firError.out @@ -1,3 +1,6 @@ +warning: ATTENTION! + This build uses in-dev FIR: + -Xuse-fir compiler/testData/cli/jvm/firError.kt:5:13: error: x must be initialized before access println(x) ^ diff --git a/compiler/testData/cli/jvm/firHello.out b/compiler/testData/cli/jvm/firHello.out index d86bac9de59..b2e67e607be 100644 --- a/compiler/testData/cli/jvm/firHello.out +++ b/compiler/testData/cli/jvm/firHello.out @@ -1 +1,4 @@ +warning: ATTENTION! + This build uses in-dev FIR: + -Xuse-fir OK diff --git a/compiler/testData/cli/jvm/inapplicableLateinitModifier.out b/compiler/testData/cli/jvm/inapplicableLateinitModifier.out index 656662915d1..f65dab31e01 100644 --- a/compiler/testData/cli/jvm/inapplicableLateinitModifier.out +++ b/compiler/testData/cli/jvm/inapplicableLateinitModifier.out @@ -1,3 +1,6 @@ +warning: ATTENTION! + This build uses in-dev FIR: + -Xuse-fir compiler/testData/cli/jvm/inapplicableLateinitModifier.kt:6:1: error: 'lateinit' modifier is not allowed on delegated properties lateinit var kest by Delegate ^ diff --git a/compiler/testData/cli/jvm/instanceAccessBeforeSuperCall.out b/compiler/testData/cli/jvm/instanceAccessBeforeSuperCall.out index 9027f0cc778..15fb869580c 100644 --- a/compiler/testData/cli/jvm/instanceAccessBeforeSuperCall.out +++ b/compiler/testData/cli/jvm/instanceAccessBeforeSuperCall.out @@ -1,3 +1,6 @@ +warning: ATTENTION! + This build uses in-dev FIR: + -Xuse-fir compiler/testData/cli/jvm/instanceAccessBeforeSuperCall.kt:2:26: error: unresolved reference: getSomeInt constructor(x: Int = getSomeInt(), other: A = this, header: String = keker) {} ^ diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/jvm/compiler/AbstractKotlinCompilerIntegrationTest.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/jvm/compiler/AbstractKotlinCompilerIntegrationTest.kt index a7a2c3df99f..7e85c2c0932 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/jvm/compiler/AbstractKotlinCompilerIntegrationTest.kt +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/jvm/compiler/AbstractKotlinCompilerIntegrationTest.kt @@ -51,15 +51,15 @@ abstract class AbstractKotlinCompilerIntegrationTest : TestCaseWithTmpdir() { * @return [destination] */ protected fun compileLibrary( - libraryName: String, - destination: File = File(tmpdir, "$libraryName.jar"), - additionalOptions: List = emptyList(), - compileJava: (sourceDir: File, javaFiles: List, outputDir: File) -> Boolean = { _, javaFiles, outputDir -> - KotlinTestUtils.compileJavaFiles(javaFiles, listOf("-d", outputDir.path)) - }, - checkKotlinOutput: (String) -> Unit = { actual -> assertEquals(normalizeOutput("" to ExitCode.OK), actual) }, - manifest: Manifest? = null, - extraClassPath: List = emptyList() + libraryName: String, + destination: File = File(tmpdir, "$libraryName.jar"), + additionalOptions: List = emptyList(), + compileJava: (sourceDir: File, javaFiles: List, outputDir: File) -> Boolean = { _, javaFiles, outputDir -> + KotlinTestUtils.compileJavaFiles(javaFiles, listOf("-d", outputDir.path)) + }, + checkKotlinOutput: (String) -> Unit = { actual -> assertEquals(normalizeOutput("" to ExitCode.OK), actual) }, + manifest: Manifest? = null, + extraClassPath: List = emptyList() ): File { val sourceDir = File(testDataDirectory, libraryName) val javaFiles = FileUtil.findFilesByMask(JAVA_FILES, sourceDir) @@ -84,13 +84,12 @@ abstract class AbstractKotlinCompilerIntegrationTest : TestCaseWithTmpdir() { if (isJar) { destination.delete() val stream = - if (manifest != null) JarOutputStream(destination.outputStream(), manifest) - else JarOutputStream(destination.outputStream()) + if (manifest != null) JarOutputStream(destination.outputStream(), manifest) + else JarOutputStream(destination.outputStream()) stream.use { jar -> ZipUtil.addDirToZipRecursively(jar, destination, outputDir, "", null, null) } - } - else assertNull("Manifest is ignored if destination is not a .jar file", manifest) + } else assertNull("Manifest is ignored if destination is not a .jar file", manifest) return destination } @@ -132,17 +131,26 @@ abstract class AbstractKotlinCompilerIntegrationTest : TestCaseWithTmpdir() { } protected fun normalizeOutput(output: Pair): String { - return AbstractCliTest.getNormalizedCompilerOutput(output.first, output.second, testDataDirectory.path) - .replace(FileUtil.toSystemIndependentName(tmpdir.absolutePath), "\$TMP_DIR\$") + return AbstractCliTest.getNormalizedCompilerOutput(output.first, output.second, testDataDirectory.path).removeFirWarning() + .replace(FileUtil.toSystemIndependentName(tmpdir.absolutePath), "\$TMP_DIR\$") + } + + private fun String.removeFirWarning(): String { + return this.replace( + """warning: ATTENTION! + This build uses in-dev FIR: + -Xuse-fir +""", "" + ) } protected fun compileKotlin( - fileName: String, - output: File, - classpath: List = emptyList(), - compiler: CLICompiler<*> = K2JVMCompiler(), - additionalOptions: List = emptyList(), - expectedFileName: String? = "output.txt" + fileName: String, + output: File, + classpath: List = emptyList(), + compiler: CLICompiler<*> = K2JVMCompiler(), + additionalOptions: List = emptyList(), + expectedFileName: String? = "output.txt" ): Pair { val args = mutableListOf() val sourceFile = File(testDataDirectory, fileName) diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/BaseGradleIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/BaseGradleIT.kt index 79501388d9a..e48799b8807 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/BaseGradleIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/BaseGradleIT.kt @@ -514,8 +514,9 @@ abstract class BaseGradleIT { assertNull(regex.find(output), "Output should not contain '$regex'") } - fun CompiledProject.assertNoWarnings() { - val warnings = "w: .*".toRegex().findAll(output).map { it.groupValues[0] } + fun CompiledProject.assertNoWarnings(sanitize: (String) -> String = { it }) { + val clearedOutput = sanitize(output) + val warnings = "w: .*".toRegex().findAll(clearedOutput).map { it.groupValues[0] } if (warnings.any()) { val message = (listOf("Output should not contain any warnings:") + warnings).joinToString(SYSTEM_LINE_SEPARATOR) diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/KotlinGradlePluginIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/KotlinGradlePluginIT.kt index f3fa5587838..81a159073c6 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/KotlinGradlePluginIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/KotlinGradlePluginIT.kt @@ -182,7 +182,7 @@ class KotlinGradleIT : BaseGradleIT() { project.build("build", options = options) { assertSuccessful() - assertNoWarnings() + assertNoWarnings { removeFirWarning(it) } } val greeterKt = project.projectDir.getFileByName("Greeter.kt") @@ -192,7 +192,7 @@ class KotlinGradleIT : BaseGradleIT() { project.build("build", options = options) { assertSuccessful() - assertNoWarnings() + assertNoWarnings { removeFirWarning(it) } val affectedSources = project.projectDir.getFilesByNames( "Greeter.kt", "KotlinGreetingJoiner.kt", "TestGreeter.kt", "TestKotlinGreetingJoiner.kt" @@ -201,6 +201,14 @@ class KotlinGradleIT : BaseGradleIT() { } } + private fun removeFirWarning(output: String): String { + return output.replace( + """w: ATTENTION! + This build uses in-dev FIR: + -Xuse-fir""", "" + ) + } + @Test fun testManyClassesIC() { val project = Project("manyClasses")