Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.0.2] - 2025-12-11

### Added

- TestKit properties support via `testKitPropertyName` parameter in `buildGradleRunner` function
- Integration with [CoverJet](https://github.com/gw-kit/cover-jet-plugin) plugin through `io.github.gwkit.coverjet.test-kit` system property
- Automatic injection of TestKit properties into test project's `gradle.properties`

## [0.0.1] - 2025-12-06

### Added
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group=io.github.gw-kit
version=0.0.1
version=0.0.2

kotlin.code.style=official

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,17 @@ val GRADLE_HOME: String
fun buildGradleRunner(
projectRoot: File,
testKitPropertyName: String? = null,
): GradleRunner {
return GradleRunner.create()
.withPluginClasspath()
.withProjectDir(projectRoot)
.withTestKitDir(
projectRoot.resolve(GRADLE_HOME).apply { mkdirs() }
)
.apply {
if (testKitPropertyName != null) {
val testKitPath: String? = System.getProperty(testKitPropertyName)
if (testKitPath != null) {
File(projectDir, "gradle.properties").appendText(
File(testKitPath).readText()
)
}
}
): GradleRunner = GradleRunner.create()
.withPluginClasspath()
.withProjectDir(projectRoot)
.withTestKitDir(projectRoot.resolve(GRADLE_HOME).apply { mkdirs() })
.apply { applyTestKit(testKitPropertyName) }

private fun GradleRunner.applyTestKit(testKitPropertyName: String?) {
testKitPropertyName
?.let(System::getProperty)
?.let { testKitFile -> File(testKitFile).readText() }
?.let { testKitContent ->
File(projectDir, "gradle.properties").appendText(testKitContent)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ class GradlePluginTestExtension : TestInstancePostProcessor {

with(testInstance) {
injectProperty<RootProjectDir, File>(rootProjectDir)
injectProperty<GradleRunnerInstance, GradleRunner>(buildGradleRunner(rootProjectDir))
injectProperty<GradleRunnerInstance, GradleRunner>(
buildGradleRunner(rootProjectDir, TEST_KIT_FILE_PROP),
)
injectProperty<ProjectFile, RestorableFile> {
val fileToBeRestored: File = resolveExistingFile(rootProjectDir, relativePath)
val originCopy: File = tempTestFile.resolve(UUID.randomUUID().toString())
Expand Down Expand Up @@ -141,6 +143,8 @@ class GradlePluginTestExtension : TestInstancePostProcessor {
const val GROOVY_BUILD_FILE_NAME = "build.gradle"
const val KOTLIN_BUILD_FILE_NAME = "build.gradle.kts"

const val TEST_KIT_FILE_PROP = "io.github.gwkit.coverjet.test-kit"

val GRADLE_BUILD_FILES = setOf(GROOVY_BUILD_FILE_NAME, KOTLIN_BUILD_FILE_NAME)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,19 @@ class RunTaskTest {
}

private fun createMinimalProject(): File {
val projectRoot = tempDir.resolve("project").apply { mkdirs() }
projectRoot.resolve("settings.gradle.kts").writeText("""rootProject.name = "test-project"""")
projectRoot.resolve("build.gradle.kts").writeText("""plugins { id("base") }""")
return projectRoot
return tempDir.resolve("project").apply {
mkdirs()
resolve("settings.gradle.kts").writeText("""rootProject.name = "test-project"""")
resolve("build.gradle.kts").writeText("""plugins { id("base") }""")
}
}

private fun createFailingProject(): File {
val projectRoot = tempDir.resolve("failing-project").apply { mkdirs() }
projectRoot.resolve("settings.gradle.kts").writeText("""rootProject.name = "failing-project"""")
projectRoot.resolve("build.gradle.kts").writeText(
"""
return tempDir.resolve("failing-project").apply {
mkdirs()
resolve("settings.gradle.kts").writeText("""rootProject.name = "failing-project"""")
resolve("build.gradle.kts").writeText(
"""
plugins { id("base") }

tasks.register("failingTask") {
Expand All @@ -61,7 +63,7 @@ class RunTaskTest {
}
}
""".trimIndent()
)
return projectRoot
)
}
}
}
Loading