Skip to content

Commit 72192bb

Browse files
amichneCopilot
andcommitted
Exclude opt-in test tags by default
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 31f6601 commit 72192bb

5 files changed

Lines changed: 93 additions & 6 deletions

File tree

build-logic/AGENTS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ Assume every edit in this unit can affect the whole repo.
2828

2929
Validate both the immediate target and the wider build impact.
3030

31+
- For test-tag selection behavior, run
32+
`./gradlew -p build-logic test --tests DefaultTestTagSelectionTest`.
33+
- Convention plugin test filtering supports `-PincludeTags=<tag1,tag2>` and
34+
`-PexcludeTags=<tag1,tag2>`. Default runs exclude `concurrency`,
35+
`performance`, and `parity` unless include tags are set.
3136
- Run the affected module tasks that consume the changed convention, starting
3237
with `./gradlew :kast:syncRuntimeLibs :kast:writeWrapperScript` for wrapper
3338
or runtime-lib changes.

build-logic/build.gradle.kts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,10 @@ dependencies {
1919
implementation(catalog.findLibrary("kotlin-gradle-plugin").get())
2020
implementation(catalog.findLibrary("kotlin-serialization-plugin").get())
2121
implementation("com.gradleup.shadow:com.gradleup.shadow.gradle.plugin:${catalog.findVersion("shadow").get().requiredVersion}")
22+
testImplementation(catalog.findLibrary("junit-jupiter").get())
23+
testRuntimeOnly(catalog.findLibrary("junit-platform-launcher").get())
24+
}
25+
26+
tasks.test {
27+
useJUnitPlatform()
2228
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
internal data class TestTagSelection(
2+
val included: Set<String>,
3+
val excluded: Set<String>,
4+
)
5+
6+
internal object DefaultTestTagSelection {
7+
private val defaultExcludedTags = linkedSetOf("concurrency", "performance", "parity")
8+
9+
fun from(includeTags: String?, excludeTags: String?): TestTagSelection {
10+
val included = parseTags(includeTags)
11+
val excluded = linkedSetOf<String>().apply {
12+
if (included.isEmpty()) {
13+
addAll(defaultExcludedTags)
14+
}
15+
addAll(parseTags(excludeTags))
16+
}
17+
return TestTagSelection(
18+
included = included,
19+
excluded = excluded,
20+
)
21+
}
22+
23+
private fun parseTags(rawTags: String?): LinkedHashSet<String> =
24+
rawTags
25+
?.split(",")
26+
?.asSequence()
27+
?.map(String::trim)
28+
?.filter(String::isNotEmpty)
29+
?.toCollection(linkedSetOf())
30+
?: linkedSetOf()
31+
}

build-logic/src/main/kotlin/kast.kotlin-library.gradle.kts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ kotlin {
1919

2020
tasks.withType<Test>().configureEach {
2121
useJUnitPlatform {
22-
val exclude = providers.gradleProperty("excludeTags").orNull
23-
val include = providers.gradleProperty("includeTags").orNull
24-
if (!exclude.isNullOrBlank()) {
25-
excludeTags(*exclude.split(",").map(String::trim).toTypedArray())
22+
val tagSelection = DefaultTestTagSelection.from(
23+
includeTags = providers.gradleProperty("includeTags").orNull,
24+
excludeTags = providers.gradleProperty("excludeTags").orNull,
25+
)
26+
if (tagSelection.excluded.isNotEmpty()) {
27+
excludeTags(*tagSelection.excluded.toTypedArray())
2628
}
27-
if (!include.isNullOrBlank()) {
28-
includeTags(*include.split(",").map(String::trim).toTypedArray())
29+
if (tagSelection.included.isNotEmpty()) {
30+
includeTags(*tagSelection.included.toTypedArray())
2931
}
3032
}
3133
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import org.junit.jupiter.api.Assertions.assertEquals
2+
import org.junit.jupiter.api.Test
3+
4+
class DefaultTestTagSelectionTest {
5+
@Test
6+
fun `default test runs exclude opt-in suites`() {
7+
val selection = DefaultTestTagSelection.from(
8+
includeTags = null,
9+
excludeTags = null,
10+
)
11+
12+
assertEquals(emptySet<String>(), selection.included)
13+
assertEquals(
14+
linkedSetOf("concurrency", "performance", "parity"),
15+
selection.excluded,
16+
)
17+
}
18+
19+
@Test
20+
fun `explicit include tags suppress default exclusions`() {
21+
val selection = DefaultTestTagSelection.from(
22+
includeTags = "concurrency",
23+
excludeTags = null,
24+
)
25+
26+
assertEquals(linkedSetOf("concurrency"), selection.included)
27+
assertEquals(emptySet<String>(), selection.excluded)
28+
}
29+
30+
@Test
31+
fun `explicit excludes merge with default opt-in exclusions`() {
32+
val selection = DefaultTestTagSelection.from(
33+
includeTags = null,
34+
excludeTags = "slow",
35+
)
36+
37+
assertEquals(emptySet<String>(), selection.included)
38+
assertEquals(
39+
linkedSetOf("concurrency", "performance", "parity", "slow"),
40+
selection.excluded,
41+
)
42+
}
43+
}

0 commit comments

Comments
 (0)