Repository navigation
grep: don't read the inputs when the pattern list is empty - #215
Conversation
Merging this PR will not alter performance1 warning
Comparing Footnotes
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #215 +/- ##
==========================================
+ Coverage 95.28% 97.19% +1.91%
==========================================
Files 6 6
Lines 1422 2106 +684
Branches 140 230 +90
==========================================
+ Hits 1355 2047 +692
+ Misses 66 59 -7
+ Partials 1 0 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Thanks for your PR |
Fixes #204
An empty pattern list (
-f /dev/null, or-fon an empty file) can't match any line, so GNU grep exits 1 without opening any input, as with-m 0.uu_grepsearched every file anyway: it reported missing files (exit 2) and printed a0count per file with-c.This returns the "no match" status right after compiling the matcher, next to the existing
-m 0and-v ''short-circuits. It only applies without-vand-L: with-vevery line is selected and with-Levery file is listed, so both still read the inputs (the issue notes both tools already agree there). A pattern file holding one empty line is not an empty list (it matches every line), and-fon an empty file combined with-estill searches.Tests
New tests in
tests/test_grep.rs:-c -f none.pat birds.txt gone.txtexits 1 with no output-G,-Eand-Fwith a missing file (GNU'sskip-readtest)-vstill prints every line,-Lstill lists every file-fcombined with-estill searchesWithout the fix, 3 of them fail.
cargo test: all passcargo fmt --all -- --checkcargo clippy --all-targets -- -D warnings