Skip to content

Commit cafd6a5

Browse files
jbachorikclaude
andcommitted
Fix test execution: handle system properties and test filtering
- Move test properties into plugin (avoid doFirst ordering issues) - Fix test filter: use --select-class instead of --scan-classpath when filtering - Simplify build.gradle.kts (plugin now handles all properties) - Tests now execute successfully with -Ptests filter Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 33f41e2 commit cafd6a5

3 files changed

Lines changed: 15 additions & 21 deletions

File tree

build-logic/conventions/src/main/kotlin/com/datadoghq/profiler/ProfilerTestPlugin.kt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,6 @@ class ProfilerTestPlugin : Plugin<Project> {
156156

157157
// Configure JVM arguments and test execution
158158
testTask.doFirst {
159-
// Preserve any args added by build scripts (doFirst blocks run in LIFO order)
160-
val buildScriptArgs = testTask.args.toList()
161159
val allArgs = mutableListOf<String>()
162160

163161
// Standard JVM args
@@ -167,8 +165,11 @@ class ProfilerTestPlugin : Plugin<Project> {
167165
}
168166
allArgs.addAll(extension.extraJvmArgs.get())
169167

170-
// Add any args from build scripts (e.g., -Dddprof_test.* properties)
171-
allArgs.addAll(buildScriptArgs)
168+
// Test-specific system properties (extracted from config name)
169+
val keepRecordings = project.hasProperty("keepJFRs") || System.getenv("KEEP_JFRS")?.toBoolean() ?: false
170+
allArgs.add("-Dddprof_test.keep_jfrs=$keepRecordings")
171+
allArgs.add("-Dddprof_test.config=$configName")
172+
allArgs.add("-Dddprof_test.ci=${project.hasProperty("CI")}")
172173

173174
// System properties
174175
allArgs.add("-DDDPROF_TEST_DISABLE_RATE_LIMIT=1")
@@ -185,11 +186,9 @@ class ProfilerTestPlugin : Plugin<Project> {
185186

186187
// JUnit Platform Console Launcher
187188
allArgs.add("org.junit.platform.console.ConsoleLauncher")
188-
allArgs.add("--scan-classpath")
189-
allArgs.add("--details=verbose")
190-
allArgs.add("--details-theme=unicode")
191189

192190
// Support Gradle's --tests filter by mapping to JUnit's selection options
191+
// Note: Cannot use --scan-classpath with explicit selectors
193192
if (project.hasProperty("tests")) {
194193
val testFilter = project.property("tests") as String
195194
// Only use --select-method if filter contains '#' (method separator)
@@ -199,8 +198,14 @@ class ProfilerTestPlugin : Plugin<Project> {
199198
} else {
200199
allArgs.add("--select-class=$testFilter")
201200
}
201+
} else {
202+
// No filter specified, scan the entire classpath
203+
allArgs.add("--scan-classpath")
202204
}
203205

206+
allArgs.add("--details=verbose")
207+
allArgs.add("--details-theme=unicode")
208+
204209
testTask.args = allArgs
205210
}
206211

ddprof-test/build.gradle.kts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,6 @@ dependencies {
5555
tasks.withType<org.gradle.api.tasks.Exec>().matching { it.name.startsWith("test") }.configureEach {
5656
// Ensure native test library is built before running tests
5757
dependsOn(":ddprof-test-native:linkLib")
58-
59-
// Extract config name from task name for test-specific system properties
60-
val configName = name.replace("test", "")
61-
val keepRecordings = project.hasProperty("keepJFRs") || System.getenv("KEEP_JFRS")?.toBoolean() ?: false
62-
63-
// Pass test configuration as system properties
64-
// The plugin's doFirst preserves args added here (doFirst blocks run in LIFO order)
65-
doFirst {
66-
args("-Dddprof_test.keep_jfrs=$keepRecordings")
67-
args("-Dddprof_test.config=$configName")
68-
args("-Dddprof_test.ci=${project.hasProperty("CI")}")
69-
}
7058
}
7159

7260
// Disable the default 'test' task - we use config-specific tasks instead

gradle/libs.versions.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
[versions]
44
cpp-standard = "17"
55
kotlin = "1.9.22"
6-
spotless = "6.11.0"
6+
spotless = "7.0.2"
77

88
# Testing
99
junit = "5.9.2"
10+
junit-platform = "1.9.2" # JUnit Platform version corresponding to JUnit Jupiter 5.9.2
1011
junit-pioneer = "1.9.1"
1112
slf4j = "1.7.32"
1213

@@ -28,7 +29,7 @@ jmh = "1.36"
2829
junit-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit" }
2930
junit-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit" }
3031
junit-params = { module = "org.junit.jupiter:junit-jupiter-params", version.ref = "junit" }
31-
junit-platform-console = { module = "org.junit.platform:junit-platform-console", version = "1.9.2" }
32+
junit-platform-console = { module = "org.junit.platform:junit-platform-console", version.ref = "junit-platform" }
3233
junit-pioneer = { module = "org.junit-pioneer:junit-pioneer", version.ref = "junit-pioneer" }
3334

3435
# Logging

0 commit comments

Comments
 (0)