Behave: black-box differential tests for CLI rewrites (found 40 bugs in uutils)

2026-11-14来源 Rust Users ForumEnglish

Hi all. I have been sending small fixes to the uutils projects (the Rust rewrites of coreutils, findutils, sed and procps), and most of the bugs I found came from one tool I built for it, so I thought it might be useful to others here who are porting a CLI to Rust.

behave runs the original binary (for example GNU sort) as a black box with lots of inputs: flags, stdin, files, empty arguments, error paths. It records stdout, stderr and the exit code of each run as plain YAML test cases. Then it replays the same cases against the rewrite and prints every difference.

So far that has led to 40 upstream bug reports and 47 fix PRs, 33 of them merged. Most differences are small: a missing error message, a different exit code, an empty-operand edge case. Those are the ones a hand-written test suite tends to skip.

behave itself is written in Go (single binary, MIT), but it does not care what language either side is in. The recorded cases are just YAML, so they can live in your repo and run in CI against your Rust build.

Repo: GitHub - emirmrkaljevic/behave: Record how any CLI behaves (flags, stdin, exit codes, edge cases) and prove your Rust/Go rewrite behaves the same. CLI + MCP server. · GitHub
List of the upstream findings: behave/docs/upstream-findings.md at main · emirmrkaljevic/behave · GitHub

If you are rewriting a CLI tool in Rust, I would like to hear whether this fits your workflow and what is missing.

1 post - 1 participant

Read full topic

原文:https://www.a8q9.cn/en/article/behave-black-box-differential-tests-for-cli-rewrites-found-40-bugs-in-uutils-a96792.html

相关文章