[Gradle] Add a warning mode assertion for the new test DSL tests
#KT-55972 In Progress
This commit is contained in:
committed by
Space Team
parent
dc24582a0b
commit
1e7cf5571b
+24
-3
@@ -5,18 +5,19 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.testbase
|
||||
|
||||
import org.gradle.api.logging.LogLevel
|
||||
import org.gradle.api.logging.configuration.WarningMode
|
||||
import org.gradle.testkit.runner.BuildResult
|
||||
|
||||
/**
|
||||
* Asserts Gradle output contains [expectedSubString] string.
|
||||
*/
|
||||
fun BuildResult.assertOutputContains(
|
||||
expectedSubString: String
|
||||
expectedSubString: String,
|
||||
message: String = "Build output does not contain \"$expectedSubString\""
|
||||
) {
|
||||
assert(output.contains(expectedSubString)) {
|
||||
printBuildOutput()
|
||||
"Build output does not contain \"$expectedSubString\""
|
||||
message
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,4 +191,24 @@ fun BuildResult.assertKotlinDaemonJvmOptions(
|
||||
|
||||
fun BuildResult.assertBuildReportPathIsPrinted() {
|
||||
assertOutputContains("Kotlin build report is written to file://")
|
||||
}
|
||||
|
||||
/**
|
||||
* 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] 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}`"
|
||||
)
|
||||
}
|
||||
+9
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.testbase
|
||||
|
||||
import org.gradle.api.logging.configuration.WarningMode
|
||||
import org.gradle.testkit.runner.BuildResult
|
||||
import org.gradle.testkit.runner.GradleRunner
|
||||
import org.gradle.tooling.GradleConnector
|
||||
@@ -151,6 +152,7 @@ fun TestProject.build(
|
||||
val buildResult = gradleRunnerForBuild.build()
|
||||
if (enableBuildScan) buildResult.printBuildScanUrl()
|
||||
assertions(buildResult)
|
||||
buildResult.additionalAssertions(buildOptions)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,10 +187,17 @@ fun TestProject.buildAndFail(
|
||||
val buildResult = gradleRunnerForBuild.buildAndFail()
|
||||
if (enableBuildScan) buildResult.printBuildScanUrl()
|
||||
assertions(buildResult)
|
||||
buildResult.additionalAssertions(buildOptions)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun BuildResult.additionalAssertions(buildOptions: BuildOptions) {
|
||||
if (buildOptions.warningMode != WarningMode.Fail) {
|
||||
assertDeprecationWarningsArePresent(buildOptions.warningMode)
|
||||
}
|
||||
}
|
||||
|
||||
internal inline fun <reified T> TestProject.getModels(
|
||||
crossinline assertions: ModelContainer<T>.() -> Unit
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user