Skip to content

cmp: match GNU usage errors messages - #392

Open
qezem wants to merge 3 commits into
uutils:mainfrom
qezem:fix/cmp-usage-error
Open

qezem wants to merge 3 commits into
uutils:mainfrom
qezem:fix/cmp-usage-error

Conversation

@qezem

@qezem qezem commented Nov 14, 2026

Copy link
Copy Markdown

Fixes #347
Fixes #177

This PR updates command-line usage error messages in cmp to match GNU cmp behavior:

  • Adds the executable name prefix (<executable>: ) to all usage error messages.
  • Appends the <executable>: Try '<executable> --help' for more information. hint line.
  • Reports specific operand and option errors (missing operand after '...', extra operand '...', unrecognized option '...', and option requires an argument -- '...') instead of a generic Usage: line.
  • Updates existing unit tests and adds integration tests verifying the GNU-compatible stderr output.

@codspeed

codspeed Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will degrade performance by 30.98%

1 warning

⚠️ 24 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

❌ 1 regressed benchmark
✅ 25 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ cmp_parser 10.5 µs 15.2 µs -30.98%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing qezem:fix/cmp-usage-error (f243fd2) with main (705c953)

Open in CodSpeed

@qezem

qezem commented Nov 14, 2026

Copy link
Copy Markdown
Author

i dont know how to optimize it...

Comment thread src/cmp.rs

while let Some(param) = opts.next() {
if to.is_none() {
last_arg = param.clone();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this clones every argument, probably the 30% regression on the cmp_parser bench.
it only matters while from is none, could you please clone only then?

Comment thread src/cmp.rs Outdated
let bytes = param.as_bytes();
let mut suffix_start = 0;

while suffix_start < bytes.len() && bytes[suffix_start].is_ascii_digit() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated to the error messages (same for saturating_mul and parse_skip), please split into another PR

Comment thread src/cmp.rs Outdated
return Err(usage_string(&executable_str));
return Err(usage_error(
&executable_str,
"invalid --ignore-initial value '-'",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with cmp a b 1 2 - this should be extra operand '-', no?

Comment thread tests/by-util/test_cmp.rs
.args(&["-l", "-s", "/etc/passwd", "/etc/group"])
.fails_with_code(2)
.stderr_str_check(|s| s.ends_with(": options -l and -s are incompatible\n"));
.stderr_str_check(|s| s.contains(": options -l and -s are incompatible\n"));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the description mentions new integration tests but i don't see them.
please add tests here for missing operand, extra operand (also after --), unrecognized option and -n/-i without argument

@qezem
qezem force-pushed the fix/cmp-usage-error branch from 6c210fd to 225f90d Compare November 15, 2026 03:48
@qezem
qezem force-pushed the fix/cmp-usage-error branch from 4d10ab8 to f243fd2 Compare November 15, 2026 04:00
@qezem

qezem commented Nov 15, 2026

Copy link
Copy Markdown
Author

@sylvestre i think ive done everything you said

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cmp - usage errors lack GNU's wording, cmp: prefix and "Try --help" line cmp argument parser rewrite

2 participants