grep - `-v -o` with `-A`/`-B`/`-C` prints nothing; GNU prints the matches found in the context lines
维护者通常 2 天内回复
还没有人认领这个 Issue。
评估
调研方向
先阅读 Rust grep 实现中对 -v 和 -o 的处理以及上下文输出路径,然后运行提供的回归测试,并将其输出与 GNU grep 进行比较。为使用 -A、-B 和 -C 的反向匹配添加测试覆盖;当上下文行中的匹配部分使用上下文分隔符输出,且现有 GNU yesno 用例通过时,即表示完成。
由索引模型根据 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 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
uutils/grep 的其他 Issue
-
grep - `-L` with `-m 0` or `-v ''` prints nothing; GNU still lists every file可能已有人在做 @yunusarda-sudo 于 5 天前认领。 未关闭bug gnu-compat good first issue
难度 2/5 1-3 小时 新手友好度 83/100
维护者通常 2 天内回复
-
grep - interval counts above 32767 are accepted; GNU rejects them with `Regular expression too big`可能已有人在做 @yunusarda-sudo 于 5 天前认领。 未关闭bug gnu-compat good first issue
难度 2/5 1-3 小时 新手友好度 79/100
维护者通常 2 天内回复
-
grep - `--exclude-dir=./dir` does not exclude the operand `./dir`可能已有人在做 @yunusarda-sudo 于 5 天前认领。 未关闭bug gnu-compat good first issue
难度 2/5 1-3 小时 新手友好度 84/100
维护者通常 2 天内回复
-
bug gnu-compat good first issue
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 2 天内回复
-
gnu-compat good first issue oss-scanner
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 2 天内回复
相似的 Issue
-
marketing
难度 2/5 半天 新手友好度 62/100
维护者通常 1 天内回复
-
S: Untriaged T: Bug
难度 2/5 1-3 小时 新手友好度 72/100
libnyanpasu/clash-nyanpasu#6537 ·
维护者通常 1 天内回复
-
难度 2/5 1 小时以内 新手友好度 62/100
tauri-apps/tao#1445 ·
维护者通常 1 天内回复
-
bug P3
难度 1/5 1-3 小时 新手友好度 88/100
-
go good first issue test
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 2 天内回复