script: Add -w flag to cmp and cmpenv to ignore whitespace - #78
Open
christarazi wants to merge 1 commit into
Open
script: Add -w flag to cmp and cmpenv to ignore whitespace#78christarazi wants to merge 1 commit into
christarazi wants to merge 1 commit into
Conversation
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
force-pushed
the
pr/christarazi/cmp-ignore-whitespace
branch
from
July 30, 2026 23:12
7574c9e to
2f03e01
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.