[Gradle] Add a warning mode assertion for the old test DSL tests
#KT-55972 Fixed
This commit is contained in:
committed by
Space Team
parent
1e7cf5571b
commit
3373a1dd90
+22
-3
@@ -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 <T> Project.getModels(modelType: Class<T>): ModelContainer<T> {
|
||||
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
|
||||
}
|
||||
|
||||
+12
-9
@@ -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)
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user