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 2ce8e0bdd64..0de104480b3 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 @@ -425,7 +425,9 @@ abstract class BaseGradleIT { var result: ProcessRunResult? = null try { result = runProcess(cmd, projectDir, env, buildOptions) - CompiledProject(this, result.output, result.exitCode).check() + val compiledProject = CompiledProject(this, result.output, result.exitCode) + compiledProject.check() + compiledProject.additionalAssertions(buildOptions) } catch (t: Throwable) { println("<=== Test build: $projectName $cmd ===>") @@ -441,6 +443,23 @@ abstract class BaseGradleIT { } } + private fun CompiledProject.additionalAssertions(options: BuildOptions) { + if (options.warningMode != WarningMode.Fail) { + assertDeprecationWarningsArePresent(options.warningMode) + } + } + + private fun CompiledProject.assertDeprecationWarningsArePresent(warningMode: WarningMode) { + assertContains( + "[GradleWarningsDetectorPlugin] The plugin is being applied", + errorMessage = NO_GRADLE_WARNINGS_DETECTOR_PLUGIN_ERROR_MESSAGE + ) + assertContains( + "[GradleWarningsDetectorPlugin] Some deprecation warnings were found during this build.", + errorMessage = getWarningModeChangeAdvice(warningMode) + ) + } + fun Project.getModels(modelType: Class): ModelContainer { if (!projectDir.exists()) { setupWorkingDir() @@ -484,9 +503,9 @@ abstract class BaseGradleIT { return this } - fun CompiledProject.assertContains(vararg expected: String, ignoreCase: Boolean = false): CompiledProject { + fun CompiledProject.assertContains(vararg expected: String, ignoreCase: Boolean = false, errorMessage: String? = null): CompiledProject { for (str in expected) { - assertTrue(output.contains(str.normalize(), ignoreCase), "Output should contain '$str'") + assertTrue(output.contains(str.normalize(), ignoreCase), errorMessage ?: "Output should contain '$str'") } return this } diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/testbase/outputAssertions.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/testbase/outputAssertions.kt index 6d02ea2a79a..c27bff6a655 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/testbase/outputAssertions.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/testbase/outputAssertions.kt @@ -193,22 +193,25 @@ fun BuildResult.assertBuildReportPathIsPrinted() { assertOutputContains("Kotlin build report is written to file://") } +val NO_GRADLE_WARNINGS_DETECTOR_PLUGIN_ERROR_MESSAGE = + """ + The build uses warning mode other than `${WarningMode.Fail}` and uses a non-default project settings file. + Please apply the `org.jetbrains.kotlin.test.gradle-warnings-detector` plugin to the settings. + + """.trimIndent() + +fun getWarningModeChangeAdvice(warningMode: WarningMode) = + "Warning mode is set to `$warningMode`, but the build produced no deprecation warnings. Please set it to `${WarningMode.Fail}`" + /** * Asserts that the build produced some deprecation warnings. * * Expected to be executed only for the case when [BuildOptions.warningMode] is not set to [WarningMode.Fail] */ fun BuildResult.assertDeprecationWarningsArePresent(warningMode: WarningMode) { - assertOutputContains( - "[GradleWarningsDetectorPlugin] The plugin is being applied", - """ - The build uses warning mode other than `${WarningMode.Fail}` and uses a non-default project settings file. - Please apply the `org.jetbrains.kotlin.test.gradle-warnings-detector` plugin to the settings. - - """.trimIndent() - ) + assertOutputContains("[GradleWarningsDetectorPlugin] The plugin is being applied", NO_GRADLE_WARNINGS_DETECTOR_PLUGIN_ERROR_MESSAGE) assertOutputContains( "[GradleWarningsDetectorPlugin] Some deprecation warnings were found during this build.", - "Warning mode is set to `$warningMode`, but the build produced no deprecation warnings. Please set it to `${WarningMode.Fail}`" + getWarningModeChangeAdvice(warningMode) ) } \ No newline at end of file