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
|
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 org.junit.jupiter.api.io.TempDir
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
|
|
||||||
@@ -12,10 +15,37 @@ import java.nio.file.Path
|
|||||||
* Base class for all Kotlin Gradle plugin integration tests.
|
* Base class for all Kotlin Gradle plugin integration tests.
|
||||||
*/
|
*/
|
||||||
abstract class KGPBaseTest {
|
abstract class KGPBaseTest {
|
||||||
|
open val defaultBuildOptions = BuildOptions()
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@TempDir
|
@TempDir
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
lateinit var workingDir: Path
|
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.
|
* Create new test project.
|
||||||
*
|
*
|
||||||
* @param [projectName] test project name in 'src/test/resources/testProject` directory.
|
* @param [projectName] test project name in 'src/test/resources/testProject` directory.
|
||||||
|
* @param [buildOptions] common Gradle build options
|
||||||
*/
|
*/
|
||||||
fun KGPBaseTest.project(
|
fun KGPBaseTest.project(
|
||||||
projectName: String,
|
projectName: String,
|
||||||
|
buildOptions: KGPBaseTest.BuildOptions = defaultBuildOptions,
|
||||||
test: TestProject.() -> Unit
|
test: TestProject.() -> Unit
|
||||||
): TestProject {
|
): TestProject {
|
||||||
val projectPath = setupProjectFromTestResources(projectName, KGPBaseTest.workingDir)
|
val projectPath = setupProjectFromTestResources(projectName, KGPBaseTest.workingDir)
|
||||||
@@ -32,7 +34,11 @@ fun KGPBaseTest.project(
|
|||||||
.withProjectDir(projectPath.toFile())
|
.withProjectDir(projectPath.toFile())
|
||||||
.withTestKitDir(KGPBaseTest.workingDir.testKitDir.toFile())
|
.withTestKitDir(KGPBaseTest.workingDir.testKitDir.toFile())
|
||||||
|
|
||||||
val testProject = TestProject(gradleRunner, projectName)
|
val testProject = TestProject(
|
||||||
|
gradleRunner,
|
||||||
|
projectName,
|
||||||
|
buildOptions
|
||||||
|
)
|
||||||
testProject.test()
|
testProject.test()
|
||||||
return testProject
|
return testProject
|
||||||
}
|
}
|
||||||
@@ -44,10 +50,10 @@ fun TestProject.build(
|
|||||||
vararg buildArguments: String,
|
vararg buildArguments: String,
|
||||||
assertions: BuildResult.() -> Unit = {}
|
assertions: BuildResult.() -> Unit = {}
|
||||||
) {
|
) {
|
||||||
println("<=== Test build: ${this.projectName} ===>")
|
|
||||||
val buildResult = gradleRunner
|
val buildResult = gradleRunner
|
||||||
.withArguments(*buildArguments, "-Pkotlin_version=1.5.255-SNAPSHOT")
|
.withArguments(commonBuildSetup(buildArguments.toList()))
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
assertions(buildResult)
|
assertions(buildResult)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,18 +64,31 @@ fun TestProject.buildAndFail(
|
|||||||
vararg buildArguments: String,
|
vararg buildArguments: String,
|
||||||
assertions: BuildResult.() -> Unit = {}
|
assertions: BuildResult.() -> Unit = {}
|
||||||
) {
|
) {
|
||||||
println("<=== Test build: ${this.projectName} ===>")
|
|
||||||
val buildResult = gradleRunner
|
val buildResult = gradleRunner
|
||||||
.withArguments(*buildArguments, "-Pkotlin_version=1.5.255-SNAPSHOT")
|
.withArguments(commonBuildSetup(buildArguments.toList()))
|
||||||
.buildAndFail()
|
.buildAndFail()
|
||||||
|
|
||||||
assertions(buildResult)
|
assertions(buildResult)
|
||||||
}
|
}
|
||||||
|
|
||||||
class TestProject(
|
class TestProject(
|
||||||
val gradleRunner: GradleRunner,
|
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 val Path.testKitDir get() = resolve("testKitDir")
|
||||||
|
|
||||||
private fun setupProjectFromTestResources(
|
private fun setupProjectFromTestResources(
|
||||||
@@ -113,4 +132,4 @@ private fun Path.copyRecursively(dest: Path) {
|
|||||||
return FileVisitResult.CONTINUE
|
return FileVisitResult.CONTINUE
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user