From a044ad43d443b7a109dda1660f125a488949aa7c Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Wed, 19 Feb 2025 09:21:41 +0100 Subject: [PATCH] pgrep: don't show msg if pattern is 15 chars long --- src/uu/pgrep/src/process_matcher.rs | 2 +- tests/by-util/test_pgrep.rs | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/uu/pgrep/src/process_matcher.rs b/src/uu/pgrep/src/process_matcher.rs index ffb2474f..b9ff54b4 100644 --- a/src/uu/pgrep/src/process_matcher.rs +++ b/src/uu/pgrep/src/process_matcher.rs @@ -78,7 +78,7 @@ pub fn get_match_settings(matches: &ArgMatches) -> UResult { )); } - if !settings.full && pattern.len() >= 15 { + if !settings.full && pattern.len() > 15 { let msg = format!("pattern that searches for process name longer than 15 characters will result in zero matches\n\ Try `{} -f' option to match against the complete command line.", uucore::util_name()); return Err(USimpleError::new(1, msg)); diff --git a/tests/by-util/test_pgrep.rs b/tests/by-util/test_pgrep.rs index f4f93140..50a2a581 100644 --- a/tests/by-util/test_pgrep.rs +++ b/tests/by-util/test_pgrep.rs @@ -380,7 +380,13 @@ fn test_does_not_match_pid() { #[cfg(target_os = "linux")] fn test_too_long_pattern() { new_ucmd!() - .arg("THIS_IS_OVER_16_CHARS") + .arg("A".repeat(15)) + .fails() + .code_is(1) + .no_output(); + + new_ucmd!() + .arg("A".repeat(16)) .fails() .code_is(1) .stderr_contains("pattern that searches for process name longer than 15 characters will result in zero matches");