grep: report file errors with -q - #128
Conversation
Quiet mode suppresses normal output and lets a match determine exit status, but it does not suppress file error diagnostics. Remove the quiet check from report_io_error so only -s suppresses those diagnostics. GNU grep 3.12 reports a missing or unreadable file encountered before a quiet match, while -s removes that diagnostic. The existing quiet_match_overrides_file_error test (added in uutils#11) needs only its stderr expectation changed for the -q case; retain its status and other cases. Add separate exact-byte tests for operand order and -s.
Merging this PR will not alter performance
Comparing Footnotes
|
| } | ||
|
|
||
| #[test] | ||
| fn quiet_file_errors_and_no_messages() { |
There was a problem hiding this comment.
Why is this test separate from quiet_match_overrides_file_error? It seems like this is a strict superset.
There was a problem hiding this comment.
Done. I removed the standalone test and folded the new cases into Sylvestre’s existing quiet_match_overrides_file_error test.
I kept the original cases because the new test was not a strict replacement: they still check the exit status without -q and exercise stdin as an input. I added only the three cases that were missing:
- a match before a missing operand: status 0, no output, and the later operand is never opened;
-qs: status 2 with no output;- a directory operand: status 2 with the
Is a directorydiagnostic.
The two cases already covered by the existing test were dropped.
I also removed the separate -s test. error_outranks_match_in_exit_code already covers -s; this change only needs to test its interaction with -q.
The separate quiet_file_errors_and_no_messages test overlapped with quiet_match_overrides_file_error: both covered a missing file followed by a match, and a missing file with no match. Keep those two in quiet_match_overrides_file_error, where the no-match case now also asserts empty stdout and the diagnostic, as printed by GNU grep 3.12. Move in the cases it lacked (a match before the missing file, -qs, and a directory operand) and drop the separate test.
-qsuppresses match output, but it should not suppress file errors. Remove the quiet-mode check fromreport_io_error;-scontinues to control whether those diagnostics are shown.Add stderr tests for a missing operand before and after a match, a run with no match,
-s, and directory errors.The existing
quiet_match_overrides_file_errortest expected empty stderr forgrep -q abc no-such-file -. GNU returns 0 when stdin later matches, but still reports the missing file. Only that stderr expectation changes.Checked against GNU grep 3.12. Formatting, Clippy, the full test suite in parallel and single-threaded mode, and a release build pass.
Fixes #127