Skip to content

grep: report file errors with -q - #128

Merged
lhecker merged 2 commits into
uutils:mainfrom
SichenLiang:quiet-file-errors
Oct 1, 2026
Merged

lhecker merged 2 commits into
uutils:mainfrom
SichenLiang:quiet-file-errors

Conversation

@SichenLiang

Copy link
Copy Markdown
Contributor

-q suppresses match output, but it should not suppress file errors. Remove the quiet-mode check from report_io_error; -s continues 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_error test expected empty stderr for grep -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

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.
@codspeed

codspeed Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 10 untouched benchmarks
⏩ 17 skipped benchmarks1


Comparing SichenLiang:quiet-file-errors (009af81) with main (be2f5c2)

Open in CodSpeed

Footnotes

  1. 17 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

Comment thread tests/test_grep.rs Outdated
}

#[test]
fn quiet_file_errors_and_no_messages() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this test separate from quiet_match_overrides_file_error? It seems like this is a strict superset.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 directory diagnostic.

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.

@lhecker lhecker left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@lhecker
lhecker merged commit 381695b into uutils:main Oct 1, 2026
27 of 28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

grep: -q suppresses file error diagnostics

2 participants