[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
|
var result: ProcessRunResult? = null
|
||||||
try {
|
try {
|
||||||
result = runProcess(cmd, projectDir, env, buildOptions)
|
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) {
|
} catch (t: Throwable) {
|
||||||
println("<=== Test build: $projectName $cmd ===>")
|
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> {
|
fun <T> Project.getModels(modelType: Class<T>): ModelContainer<T> {
|
||||||
if (!projectDir.exists()) {
|
if (!projectDir.exists()) {
|
||||||
setupWorkingDir()
|
setupWorkingDir()
|
||||||
@@ -484,9 +503,9 @@ abstract class BaseGradleIT {
|
|||||||
return this
|
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) {
|
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
|
return this
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-9
@@ -193,22 +193,25 @@ fun BuildResult.assertBuildReportPathIsPrinted() {
|
|||||||
assertOutputContains("Kotlin build report is written to file://")
|
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.
|
* 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]
|
* Expected to be executed only for the case when [BuildOptions.warningMode] is not set to [WarningMode.Fail]
|
||||||
*/
|
*/
|
||||||
fun BuildResult.assertDeprecationWarningsArePresent(warningMode: WarningMode) {
|
fun BuildResult.assertDeprecationWarningsArePresent(warningMode: WarningMode) {
|
||||||
assertOutputContains(
|
assertOutputContains("[GradleWarningsDetectorPlugin] The plugin is being applied", NO_GRADLE_WARNINGS_DETECTOR_PLUGIN_ERROR_MESSAGE)
|
||||||
"[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(
|
assertOutputContains(
|
||||||
"[GradleWarningsDetectorPlugin] Some deprecation warnings were found during this build.",
|
"[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