Repository navigation
Description
Known: #177 (open issue) — #177
For command-line usage errors GNU cmp prints a specific message prefixed with the
program name, followed by cmp: Try 'cmp --help' for more information.. uutils prints a
bare Usage: cmp <from> <to> or an unprefixed message, and never the "Try" line. Scripts
and test suites that match stderr see different text (the exit status, 2, is already right).
Reproduction
printf 'abcdefghij' > c1; printf 'abcdeXghiY' > c2Rust (incorrect)
$ ./target/release/diffutils cmp
Usage: cmp <from> <to>
# Exit code: 2
$ ./target/release/diffutils cmp --bogus c1 c2
unrecognized option '--bogus'
# Exit code: 2
$ ./target/release/diffutils cmp c1 c2 3 4 extra
Usage: cmp <from> <to>
# Exit code: 2GNU (correct)
$ LC_ALL=C cmp
cmp: missing operand after 'cmp'
cmp: Try 'cmp --help' for more information.
# Exit code: 2
$ LC_ALL=C cmp --bogus c1 c2
cmp: unrecognized option '--bogus'
cmp: Try 'cmp --help' for more information.
# Exit code: 2
$ LC_ALL=C cmp c1 c2 3 4 extra
cmp: extra operand 'extra'
cmp: Try 'cmp --help' for more information.
# Exit code: 2cmp a b c d e (invalid skip) already prints cmp: invalid --ignore-initial value 'c'
but is also missing the "Try" line.
Root cause
src/cmp.rs: usage_string (line 42) is used for every operand error, and the
unrecognized-option error at line 211 has no program-name prefix:
fn usage_string(executable: &str) -> String {
format!("Usage: {executable} <from> <to>")
}
...
return Err(format!("unrecognized option '{}'", param.to_string_lossy()));Test
Add to tests/by-util/test_cmp.rs:
#[test]
fn cmp_usage_errors_match_gnu() -> Result<(), Box<dyn std::error::Error>> {
let mut cmd = cargo_bin_cmd!("diffutils");
cmd.arg("cmp");
cmd.assert().code(predicate::eq(2)).stderr(predicate::eq(
"cmp: missing operand after 'cmp'\ncmp: Try 'cmp --help' for more information.\n",
));
let mut cmd = cargo_bin_cmd!("diffutils");
cmd.arg("cmp").arg("--bogus").arg("a").arg("b");
cmd.assert().code(predicate::eq(2)).stderr(predicate::eq(
"cmp: unrecognized option '--bogus'\ncmp: Try 'cmp --help' for more information.\n",
));
Ok(())
}Reported by Anthropic's OSS Scanner (ANT-2026-VNGOYIV8).
Activity