grep - `-v -o` with `-A`/`-B`/`-C` prints nothing; GNU prints the matches found in the context lines

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

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

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

调研方向

先阅读 Rust grep 实现中对 -v 和 -o 的处理以及上下文输出路径,然后运行提供的回归测试,并将其输出与 GNU grep 进行比较。为使用 -A、-B 和 -C 的反向匹配添加测试覆盖;当上下文行中的匹配部分使用上下文分隔符输出,且现有 GNU yesno 用例通过时,即表示完成。

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

描述

bug gnu-compat good first issue

With -v -o, the selected lines are the non-matching ones, so they have nothing to print.
When context is also requested, GNU grep prints, for each context line (a line that does
match), its matching parts with the context separator - (2-dog), plus -- between
non-adjacent groups. uu_grep drops the context entirely whenever -o is given, so it
prints nothing.

Related: #175 / PR #188 restore the -- separators for -o with context, but keep skipping
context lines, so they do not cover this case.

Exposed by the GNU test yesno (tests #24 -v -C 1 -o and #38 -m 3 -v -C 1 -o). The other
yesno failures are #175 (tests #4, #20) and #156 (--group=XYZ, --no-gr, tests #5, #6,
#8, #9, #25, #26).

Reproduction

$ printf 'cat\ndog\ncat\ncat\ncat\ndog\n' > pets

Rust (incorrect)

$ ./target/release/grep -n -v -A 1 -o dog pets
# Output: (none)
# Exit code: 0

GNU (correct)

$ LC_ALL=C /usr/bin/grep -n -v -A 1 -o dog pets
2-dog
6-dog
# Exit code: 0

Test

#[test]
fn invert_only_matching_prints_context_matches() {
    let (_s, mut c) = ucmd();
    c.args(&["-n", "-v", "-B", "1", "-o", "ant"])
        .pipe_in("ant\nbee\nwasp\nbee\nant\n")
        .succeeds()
        .stdout_only("1-ant\n");
}

Exposed by the GNU grep test suite: yesno.

主要语言
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 摘要。