grep - `-L` with `-m 0` or `-v ''` prints nothing; GNU still lists every file

未关闭 适合新手
#213 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

@yunusarda-sudo 已经在做这个了。

开始于 2026年11月17日。

  • #216 来自 @yunusarda-sudo —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
83/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
rust
领域
cli, testing

调研方向

issue指出了 uu_grep 的提前退出,并包含一个 Rust 回归测试,但没有提供源文件或测试文件路径。首先找到该提前退出的位置以及现有针对 -L 的 grep 测试;添加给出的 -m 0 和 -v -e '' 用例,检查可读文件会被列出,同时退出代码仍为 1。GNU 的 skip-read 用例也需要覆盖 -G、-E 和 -F。

由索引模型根据 Issue 内容生成。

描述

bug gnu-compat good first issue

When no line can be selected (-m 0, or -v with an empty pattern) uu_grep exits 1 before
opening any file. That is right for plain output, -c, -l and -q, but not for
-L/--files-without-match: every file then has no selected line, and GNU grep lists each
readable file (and still reports files it cannot open). uu_grep prints nothing.

Exposed by the GNU test skip-read (grep -L -m0 y /dev/null and grep -L -v "" /dev/null must print /dev/null, with -G, -E and -F).

Reproduction

$ printf 'red\n' > colors

Rust (incorrect)

$ ./target/release/grep -L -m 0 red colors
# Output: (none)
# Exit code: 1

$ ./target/release/grep -L -v -e '' colors
# Output: (none)
# Exit code: 1

GNU (correct)

$ LC_ALL=C /usr/bin/grep -L -m 0 red colors
colors
# Exit code: 1

$ LC_ALL=C /usr/bin/grep -L -v -e '' colors
colors
# Exit code: 1

$ LC_ALL=C /usr/bin/grep -L -m 0 red colors nosuch
colors
/usr/bin/grep: nosuch: No such file or directory
# Exit code: 2

Test

#[test]
fn files_without_match_with_nothing_selectable() {
    for args in [&["-L", "-m", "0", "pine"][..], &["-L", "-v", "-e", ""][..]] {
        let (scene, mut c) = ucmd();
        scene.fixtures.write("trees.txt", "pine\noak\n");
        c.args(args)
            .arg("trees.txt")
            .fails_with_code(1)
            .stdout_only("trees.txt\n");
    }
}

Exposed by the GNU grep test suite: skip-read.

主要语言
Rust
星标
147
派生
34
平均合并
3 天 18 小时
30 天内合并 PR
21

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

uutils/grep 的其他 Issue

查看 uutils/grep 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。