Skip to content
Open
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
34 changes: 34 additions & 0 deletions src/core/toml_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1693,4 +1693,38 @@ expected = "output line 1\noutput line 2"
);
assert_eq!(found.unwrap().name, "my-new-tool");
}

/// Verify the gradle filter matches the normalized lookup string RTK actually
/// produces at runtime. RTK strips leading `./` and uses the basename, so
/// `rtk ./gradlew tasks` produces lookup `"gradlew tasks"`, not `"./gradlew tasks"`.
/// Regression test for #1177: the old regex `^(gradle|gradlew|\\./)gradlew?\b`
/// never matched the basename form and caused every Gradle invocation to fall
/// through to passthrough.
#[test]
fn test_gradle_filter_matches_normalized_lookup() {
let filters = make_filters(BUILTIN_TOML);

// These are the exact strings RTK's basename-normalisation produces at runtime.
for lookup in &["gradlew tasks", "gradle build", "gradlew --version"] {
let found = find_filter_in(lookup, &filters);
assert!(
found.is_some(),
"gradle filter must match normalized lookup {:?} (basename, no ./)",
lookup
);
assert_eq!(
found.unwrap().name,
"gradle",
"wrong filter matched for {:?}",
lookup
);
}

// Must NOT match unrelated commands.
assert!(
find_filter_in("gradlewrapper build", &filters).map(|f| f.name.as_str())
!= Some("gradle"),
"gradle filter must not match 'gradlewrapper'"
);
}
}
15 changes: 14 additions & 1 deletion src/filters/gradle.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[filters.gradle]
description = "Compact Gradle build output — strip progress, keep tasks and errors"
match_command = "^(gradle|gradlew|\\./)gradlew?\\b"
match_command = "^gradlew?\\b"
strip_ansi = true
strip_lines_matching = [
"^\\s*$",
Expand All @@ -14,6 +14,9 @@ strip_lines_matching = [
"^> Task :.*FROM-CACHE$",
"^Starting a Gradle Daemon",
"^Daemon will be stopped",
"^Calculating task graph",
"^Reusing configuration cache",
"^Configuration cache",
]
truncate_lines_at = 150
max_lines = 50
Expand All @@ -33,3 +36,13 @@ expected = "BUILD SUCCESSFUL in 8s\n7 actionable tasks: 7 executed"
name = "empty after stripping"
input = "> Configuring project :app\n"
expected = "gradle: ok"

[[tests.gradle]]
name = "strips configuration cache chatter, keeps task output"
input = "Calculating task graph as no cached configuration is available for tasks: build\nReusing configuration cache.\nConfiguration cache entry stored.\n> Task :compileJava\n> Task :test\nBUILD SUCCESSFUL in 5s"
expected = "> Task :compileJava\n> Task :test\nBUILD SUCCESSFUL in 5s"

[[tests.gradle]]
name = "gradlew help output — daemon and daemon-stopped stripped"
input = "Starting a Gradle Daemon (subsequent builds will be faster)\n> Task :help\n\nWelcome to Gradle 8.6.\n\nDaemon will be stopped at the end of the build stopping after idling timeout of 3 hours"
expected = "> Task :help\nWelcome to Gradle 8.6."
Loading