Skip to content

script: Add -w flag to cmp and cmpenv to ignore whitespace - #78

Open
christarazi wants to merge 1 commit into
mainfrom
pr/christarazi/cmp-ignore-whitespace
Open

script: Add -w flag to cmp and cmpenv to ignore whitespace#78
christarazi wants to merge 1 commit into
mainfrom
pr/christarazi/cmp-ignore-whitespace

Conversation

@christarazi

Copy link
Copy Markdown
Member

cmp and cmpenv do an exact byte comparison, which makes them awkward for
asserting on tabular command output: a tabwriter aligns columns to the
widest cell, so the actual output's column spacing shifts with the data
and no longer matches a hand-spaced golden file. This is worse with
cmpenv, where a ${var} placeholder in the golden is a different width
than the value it expands to.

Add a -w/--ignore-whitespace flag, mirroring diff --ignore-space-change.
Each line is trimmed and whitespace is collapsed to a single space
before comparing. Line structure is preserved, so real differences are
still reported. This lets tests dump an aligned table to stdout and
assert with cmp -w stdout expected.txt while keeping a readable golden.

cmp and cmpenv do an exact byte comparison, which makes them awkward for
asserting on tabular command output: a tabwriter aligns columns to the
widest cell, so the actual output's column spacing shifts with the data
and no longer matches a hand-spaced golden file. This is worse with
cmpenv, where a ${var} placeholder in the golden is a different width
than the value it expands to.

Add a -w/--ignore-whitespace flag, mirroring diff --ignore-space-change.
Each line is trimmed and whitespace is collapsed to a single space
before comparing. Line structure is preserved, so real differences are
still reported. This lets tests dump an aligned table to stdout and
assert with cmp -w stdout expected.txt while keeping a readable golden.

Signed-off-by: Chris Tarazi <chris@isovalent.com>
@christarazi
christarazi requested a review from a team as a code owner July 30, 2026 23:11
@christarazi
christarazi requested review from bimmlerd and removed request for a team July 30, 2026 23:11
@christarazi
christarazi force-pushed the pr/christarazi/cmp-ignore-whitespace branch from 7574c9e to 2f03e01 Compare July 30, 2026 23:12
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.

1 participant