Skip to content

cmp - usage errors lack GNU's wording, cmp: prefix and "Try --help" line #347

Open

Description

@sylvestre

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' > c2

Rust (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: 2

GNU (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: 2

cmp 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

  1. added
    good first issue
    oss-scanner
    gnu-compat
    on Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    gnu-compatgood first issueoss-scanner

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions