From df0a93015678879d93b3d432417d729500aee138 Mon Sep 17 00:00:00 2001 From: xenoninja Date: Wed, 7 May 2025 17:25:11 +0800 Subject: [PATCH 1/5] add test files for the fix --- tests/files.rs | 9 +++++++++ tests/patternfile.rs | 37 +++++++++++++++++++++++++++++++++++++ tests/tests.rs | 4 ++++ 3 files changed, 50 insertions(+) create mode 100644 tests/files.rs create mode 100644 tests/patternfile.rs diff --git a/tests/files.rs b/tests/files.rs new file mode 100644 index 000000000..e54eea314 --- /dev/null +++ b/tests/files.rs @@ -0,0 +1,9 @@ +pub const ONETWOTHREE: &'static str = "\ +one +two +three +"; + +pub const NEWLINE: &'static str = "\ + +"; diff --git a/tests/patternfile.rs b/tests/patternfile.rs new file mode 100644 index 000000000..d9bfa56e0 --- /dev/null +++ b/tests/patternfile.rs @@ -0,0 +1,37 @@ +use crate::files::{NEWLINE, ONETWOTHREE}; +use crate::hay::SHERLOCK; +use crate::util::{cmd_exists, sort_lines, Dir, TestCommand}; + +// This file contains specified to-fix tests. +// $ rg -f /dev/null <<< "wat" +// $ rg -v -f /dev/null <<< "wat" +// $ grep -f /dev/null <<< "wat" +// $ grep -v -f /dev/null <<< "wat" +// wat +// $ rg -f <(echo) <<< "wat" +// wat +// $ rg -v -f <(echo) <<< "wat" +// + +rgtest!(empty_file, |dir: Dir, mut cmd: TestCommand| { + dir.create("onetwothree", ONETWOTHREE); + dir.create("empty", ""); + + let expected = "\ +one +two +three +"; + eqnice!( + expected, + cmd.args(&["-v", "-f", "onetwothree", "empty",]).stdout() + ); +}); + +rgtest!(new_line, |dir: Dir, mut cmd: TestCommand| { + dir.create("onetwothree", ONETWOTHREE); + dir.create("newline", NEWLINE); + + cmd.args(&["-v", "-f", "onetwothree", "newline"]); + cmd.assert_err(); +}); diff --git a/tests/tests.rs b/tests/tests.rs index 81e40f806..5bc3dd84f 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -20,3 +20,7 @@ mod misc; mod multiline; // Regression tests. mod regression; + +mod patternfile; + +mod files; From d29a48fa7cde7a50aa196f2e2a29957544581a41 Mon Sep 17 00:00:00 2001 From: xenoninja Date: Wed, 7 May 2025 17:25:11 +0800 Subject: [PATCH 2/5] add test files for the fix --- tests/files.rs | 9 +++++++++ tests/patternfile.rs | 36 ++++++++++++++++++++++++++++++++++++ tests/tests.rs | 4 ++++ 3 files changed, 49 insertions(+) create mode 100644 tests/files.rs create mode 100644 tests/patternfile.rs diff --git a/tests/files.rs b/tests/files.rs new file mode 100644 index 000000000..e54eea314 --- /dev/null +++ b/tests/files.rs @@ -0,0 +1,9 @@ +pub const ONETWOTHREE: &'static str = "\ +one +two +three +"; + +pub const NEWLINE: &'static str = "\ + +"; diff --git a/tests/patternfile.rs b/tests/patternfile.rs new file mode 100644 index 000000000..1c6e24e22 --- /dev/null +++ b/tests/patternfile.rs @@ -0,0 +1,36 @@ +use crate::files::{NEWLINE, ONETWOTHREE}; +use crate::util::{Dir, TestCommand}; + +// This file contains specified to-fix tests. +// $ rg -f /dev/null <<< "wat" +// $ rg -v -f /dev/null <<< "wat" +// $ grep -f /dev/null <<< "wat" +// $ grep -v -f /dev/null <<< "wat" +// wat +// $ rg -f <(echo) <<< "wat" +// wat +// $ rg -v -f <(echo) <<< "wat" +// + +rgtest!(empty_file, |dir: Dir, mut cmd: TestCommand| { + dir.create("onetwothree", ONETWOTHREE); + dir.create("empty", ""); + + let expected = "\ +one +two +three +"; + eqnice!( + expected, + cmd.args(&["-v", "-f", "onetwothree", "empty",]).stdout() + ); +}); + +rgtest!(new_line, |dir: Dir, mut cmd: TestCommand| { + dir.create("onetwothree", ONETWOTHREE); + dir.create("newline", NEWLINE); + + cmd.args(&["-v", "-f", "onetwothree", "newline"]); + cmd.assert_err(); +}); diff --git a/tests/tests.rs b/tests/tests.rs index 81e40f806..5bc3dd84f 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -20,3 +20,7 @@ mod misc; mod multiline; // Regression tests. mod regression; + +mod patternfile; + +mod files; From 006730cf370231f1e0b810e37aa95e5ca8f55b92 Mon Sep 17 00:00:00 2001 From: xenoninja Date: Thu, 8 May 2025 14:48:19 +0800 Subject: [PATCH 3/5] fix the problem --- crates/core/flags/hiargs.rs | 3 --- tests/files.rs | 9 --------- tests/patternfile.rs | 36 ------------------------------------ tests/tests.rs | 4 ---- 4 files changed, 52 deletions(-) delete mode 100644 tests/files.rs delete mode 100644 tests/patternfile.rs diff --git a/crates/core/flags/hiargs.rs b/crates/core/flags/hiargs.rs index df09dceda..8b3fc2d77 100644 --- a/crates/core/flags/hiargs.rs +++ b/crates/core/flags/hiargs.rs @@ -517,9 +517,6 @@ impl HiArgs { /// When this returns false, it is impossible for ripgrep to ever report /// a match. pub(crate) fn matches_possible(&self) -> bool { - if self.patterns.patterns.is_empty() { - return false; - } if self.max_count == Some(0) { return false; } diff --git a/tests/files.rs b/tests/files.rs deleted file mode 100644 index e54eea314..000000000 --- a/tests/files.rs +++ /dev/null @@ -1,9 +0,0 @@ -pub const ONETWOTHREE: &'static str = "\ -one -two -three -"; - -pub const NEWLINE: &'static str = "\ - -"; diff --git a/tests/patternfile.rs b/tests/patternfile.rs deleted file mode 100644 index 1c6e24e22..000000000 --- a/tests/patternfile.rs +++ /dev/null @@ -1,36 +0,0 @@ -use crate::files::{NEWLINE, ONETWOTHREE}; -use crate::util::{Dir, TestCommand}; - -// This file contains specified to-fix tests. -// $ rg -f /dev/null <<< "wat" -// $ rg -v -f /dev/null <<< "wat" -// $ grep -f /dev/null <<< "wat" -// $ grep -v -f /dev/null <<< "wat" -// wat -// $ rg -f <(echo) <<< "wat" -// wat -// $ rg -v -f <(echo) <<< "wat" -// - -rgtest!(empty_file, |dir: Dir, mut cmd: TestCommand| { - dir.create("onetwothree", ONETWOTHREE); - dir.create("empty", ""); - - let expected = "\ -one -two -three -"; - eqnice!( - expected, - cmd.args(&["-v", "-f", "onetwothree", "empty",]).stdout() - ); -}); - -rgtest!(new_line, |dir: Dir, mut cmd: TestCommand| { - dir.create("onetwothree", ONETWOTHREE); - dir.create("newline", NEWLINE); - - cmd.args(&["-v", "-f", "onetwothree", "newline"]); - cmd.assert_err(); -}); diff --git a/tests/tests.rs b/tests/tests.rs index 5bc3dd84f..81e40f806 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -20,7 +20,3 @@ mod misc; mod multiline; // Regression tests. mod regression; - -mod patternfile; - -mod files; From 8d45a21b1fea4eeeb36784ef2b856155c22e5685 Mon Sep 17 00:00:00 2001 From: xenoninja Date: Thu, 8 May 2025 15:26:29 +0800 Subject: [PATCH 4/5] add pcre2 condition --- crates/core/flags/hiargs.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crates/core/flags/hiargs.rs b/crates/core/flags/hiargs.rs index 8b3fc2d77..3ea4a84cc 100644 --- a/crates/core/flags/hiargs.rs +++ b/crates/core/flags/hiargs.rs @@ -517,6 +517,11 @@ impl HiArgs { /// When this returns false, it is impossible for ripgrep to ever report /// a match. pub(crate) fn matches_possible(&self) -> bool { + if cfg!(feature="pcre2") { + if self.patterns.patterns.is_empty() { + return false; + } + } if self.max_count == Some(0) { return false; } From 8a53eb89a943265ed9359b525219a136f6a18b44 Mon Sep 17 00:00:00 2001 From: xenoninja Date: Thu, 8 May 2025 15:29:46 +0800 Subject: [PATCH 5/5] format the code --- crates/core/flags/hiargs.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/core/flags/hiargs.rs b/crates/core/flags/hiargs.rs index 3ea4a84cc..8612b82f8 100644 --- a/crates/core/flags/hiargs.rs +++ b/crates/core/flags/hiargs.rs @@ -517,7 +517,7 @@ impl HiArgs { /// When this returns false, it is impossible for ripgrep to ever report /// a match. pub(crate) fn matches_possible(&self) -> bool { - if cfg!(feature="pcre2") { + if cfg!(feature = "pcre2") { if self.patterns.patterns.is_empty() { return false; }