From 5b8900267ff93688fad2a7ab0b25dc57b42ea9e7 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 19 Nov 2016 01:02:08 -0800 Subject: [PATCH 09/10] grep -f /dev/null -L PAT FILE outputs FILE * NEWS: Document this. * src/grep.c (main): Do not exit right away with -L. * tests/skip-read: Test for the fix. --- NEWS | 2 ++ src/grep.c | 5 +++-- tests/skip-read | 13 +++++++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/NEWS b/NEWS index 06a186a..29a0e8d 100644 --- a/NEWS +++ b/NEWS @@ -14,6 +14,8 @@ GNU grep NEWS -*- outline -*- more cautious about special patterns like (?-m) and (*FAIL). [bug introduced in grep-2.23] + grep -m0 -L PAT FILE now outputs "FILE". [bug introduced in grep-2.5] + grep's use of getprogname no longer causes a build failure on HP-UX. ** Improvements diff --git a/src/grep.c b/src/grep.c index 066df8c..a794af4 100644 --- a/src/grep.c +++ b/src/grep.c @@ -2818,8 +2818,9 @@ main (int argc, char **argv) /* If it is easy to see that matching cannot succeed (e.g., 'grep -f /dev/null'), fail without reading the input. */ - if (max_count == 0 - || (keycc == 0 && out_invert && !match_lines && !match_words)) + if ((max_count == 0 + || (keycc == 0 && out_invert && !match_lines && !match_words)) + && list_files != LISTFILES_NONMATCHING) return EXIT_FAILURE; if (color_option == 2) diff --git a/tests/skip-read b/tests/skip-read index 627d362..1eef87e 100755 --- a/tests/skip-read +++ b/tests/skip-read @@ -5,11 +5,20 @@ fail=0 +echo /dev/null >exp || framework_failure_ + for opts in '-m0 y' '-f /dev/null' '-v ""'; do for matcher in '' -E -F; do - eval returns_ 1 grep $opts $matcher no-such-file > out || fail=1 - compare /dev/null out || fail=1 + for file in /dev/null no-such-file; do + eval returns_ 1 grep $opts $matcher no-such-file > out || fail=1 + compare /dev/null out || fail=1 + eval returns_ 1 grep -l $opts $matcher /dev/null > out || fail=1 + compare /dev/null out || fail=1 + done + eval returns_ 1 grep -L $opts $matcher /dev/null > out || fail=1 + compare exp out || fail=1 done done + Exit $fail -- 2.7.4