Add initial setup to build common options.
^KT-45744 In Progress
This commit is contained in:
committed by
TeamCityServer
parent
7549d14a36
commit
710287920b
+30
@@ -5,6 +5,9 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.testbase
|
||||
|
||||
import org.gradle.api.logging.LogLevel
|
||||
import org.gradle.api.logging.configuration.WarningMode
|
||||
import org.jetbrains.kotlin.gradle.KOTLIN_VERSION
|
||||
import org.junit.jupiter.api.io.TempDir
|
||||
import java.nio.file.Path
|
||||
|
||||
@@ -12,10 +15,37 @@ import java.nio.file.Path
|
||||
* Base class for all Kotlin Gradle plugin integration tests.
|
||||
*/
|
||||
abstract class KGPBaseTest {
|
||||
open val defaultBuildOptions = BuildOptions()
|
||||
|
||||
companion object {
|
||||
@TempDir
|
||||
@JvmStatic
|
||||
lateinit var workingDir: Path
|
||||
}
|
||||
|
||||
data class BuildOptions(
|
||||
val logLevel: LogLevel = LogLevel.INFO,
|
||||
val kotlinVersion: String = KOTLIN_VERSION,
|
||||
val warningMode: WarningMode = WarningMode.Fail
|
||||
) {
|
||||
fun toArguments(): List<String> {
|
||||
val arguments = mutableListOf<String>()
|
||||
when (logLevel) {
|
||||
LogLevel.DEBUG -> arguments.add("--debug")
|
||||
LogLevel.INFO -> arguments.add("--info")
|
||||
LogLevel.WARN -> arguments.add("--warn")
|
||||
LogLevel.QUIET -> arguments.add("--quiet")
|
||||
else -> Unit
|
||||
}
|
||||
arguments.add("-Pkotlin_version=$kotlinVersion")
|
||||
when (warningMode) {
|
||||
WarningMode.Fail -> arguments.add("--warning-mode=fail")
|
||||
WarningMode.All -> arguments.add("--warning-mode=all")
|
||||
WarningMode.Summary -> arguments.add("--warning-mode=summary")
|
||||
WarningMode.None -> arguments.add("--warning-mode=none")
|
||||
}
|
||||
|
||||
return arguments.toList()
|
||||
}
|
||||
}
|
||||
}
|
||||
+26
-7
@@ -19,9 +19,11 @@ import java.nio.file.attribute.BasicFileAttributes
|
||||
* Create new test project.
|
||||
*
|
||||
* @param [projectName] test project name in 'src/test/resources/testProject` directory.
|
||||
* @param [buildOptions] common Gradle build options
|
||||
*/
|
||||
fun KGPBaseTest.project(
|
||||
projectName: String,
|
||||
buildOptions: KGPBaseTest.BuildOptions = defaultBuildOptions,
|
||||
test: TestProject.() -> Unit
|
||||
): TestProject {
|
||||
val projectPath = setupProjectFromTestResources(projectName, KGPBaseTest.workingDir)
|
||||
@@ -32,7 +34,11 @@ fun KGPBaseTest.project(
|
||||
.withProjectDir(projectPath.toFile())
|
||||
.withTestKitDir(KGPBaseTest.workingDir.testKitDir.toFile())
|
||||
|
||||
val testProject = TestProject(gradleRunner, projectName)
|
||||
val testProject = TestProject(
|
||||
gradleRunner,
|
||||
projectName,
|
||||
buildOptions
|
||||
)
|
||||
testProject.test()
|
||||
return testProject
|
||||
}
|
||||
@@ -44,10 +50,10 @@ fun TestProject.build(
|
||||
vararg buildArguments: String,
|
||||
assertions: BuildResult.() -> Unit = {}
|
||||
) {
|
||||
println("<=== Test build: ${this.projectName} ===>")
|
||||
val buildResult = gradleRunner
|
||||
.withArguments(*buildArguments, "-Pkotlin_version=1.5.255-SNAPSHOT")
|
||||
.withArguments(commonBuildSetup(buildArguments.toList()))
|
||||
.build()
|
||||
|
||||
assertions(buildResult)
|
||||
}
|
||||
|
||||
@@ -58,18 +64,31 @@ fun TestProject.buildAndFail(
|
||||
vararg buildArguments: String,
|
||||
assertions: BuildResult.() -> Unit = {}
|
||||
) {
|
||||
println("<=== Test build: ${this.projectName} ===>")
|
||||
val buildResult = gradleRunner
|
||||
.withArguments(*buildArguments, "-Pkotlin_version=1.5.255-SNAPSHOT")
|
||||
.withArguments(commonBuildSetup(buildArguments.toList()))
|
||||
.buildAndFail()
|
||||
|
||||
assertions(buildResult)
|
||||
}
|
||||
|
||||
class TestProject(
|
||||
val gradleRunner: GradleRunner,
|
||||
val projectName: String
|
||||
val projectName: String,
|
||||
val buildOptions: KGPBaseTest.BuildOptions
|
||||
)
|
||||
|
||||
private fun TestProject.commonBuildSetup(
|
||||
buildArguments: List<String>
|
||||
): List<String> {
|
||||
val buildOptionsArguments = buildOptions.toArguments()
|
||||
val allBuildArguments = buildOptionsArguments + buildArguments + "--full-stacktrace"
|
||||
|
||||
println("<=== Test build: ${this.projectName} ===>")
|
||||
println("<=== Run arguments: ${allBuildArguments.joinToString()} ===>")
|
||||
|
||||
return allBuildArguments
|
||||
}
|
||||
|
||||
private val Path.testKitDir get() = resolve("testKitDir")
|
||||
|
||||
private fun setupProjectFromTestResources(
|
||||
@@ -113,4 +132,4 @@ private fun Path.copyRecursively(dest: Path) {
|
||||
return FileVisitResult.CONTINUE
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user