Skip to content

cmp: use the larger of -i and the positional skip, like GNU - #371

Merged
sylvestre merged 2 commits into
uutils:mainfrom
emirmrkaljevic:cmp-skip-max
Nov 11, 2026
Merged

sylvestre merged 2 commits into
uutils:mainfrom
emirmrkaljevic:cmp-skip-max

Conversation

@emirmrkaljevic

Copy link
Copy Markdown
Contributor

GNU cmp uses the largest skip given for each file, whether it comes from -i or from the positional SKIP operands (and also when -i is repeated). We dropped the positional skips as soon as -i was given, and a repeated -i kept only the last value.

Now the positional operands are always read (also after --) and each file gets the max of all values. I updated the parse test that expected the old behaviour and added cases for -i with positional skips, after --, and repeated -i. Checked the issue's example and a few combinations against GNU cmp, output matches.

Fixes #346

GNU cmp applies the largest of all skip values given for each file, from
-i (also when repeated) and from the positional SKIP operands. Positional
skips were dropped whenever -i was given, and a repeated -i kept only the
last value.

Fixes uutils#346
@sylvestre

Copy link
Copy Markdown
Collaborator

thanks for this PR!
Please add an end-to-end test in tests/by-util/test_cmp.rs (see inline). The unit tests only cover parse_params.
Please also run the upstream test: TESTS=cmp ./tests/run-upstream-testsuite.sh

@emirmrkaljevic

Copy link
Copy Markdown
Contributor Author

Thanks, done. Added cmp_skip_uses_larger_of_option_and_positional in tests/by-util/test_cmp.rs (6645f50). It covers a larger positional skip winning over -i, repeated -i, and a case that still differs. It fails on main and passes with this change. I also updated the old "Positional skips should be ignored" comment since that is no longer the behavior.

TESTS=cmp ./tests/run-upstream-testsuite.sh passes (1/1).

@sylvestre
sylvestre merged commit b0d9d45 into uutils:main Nov 11, 2026
31 checks passed
@sylvestre

Copy link
Copy Markdown
Collaborator

Thanks for your PR

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 - positional SKIP operands are ignored when -i is also given

2 participants