Skip to content

Commit

Permalink
test: use cmp.Diff for comparing output (google#558)
Browse files Browse the repository at this point in the history
This makes it easier to determine what is wrong in CLI tests by showing
an actual diff; while in most cases this is an improvement, I have found
it's sometimes useful to have the raw output printed so I've included an
env variable to allow switching easily with `cmp.Diff` being the
default.

In order to reduce the diff noise when a test does fail, this also
switches to replacing occurrences of the current working directory in
the _actual_ output with `<rootdir>`; this also means that the output
will be what should be in the test cases, rather than the absolute path
that people would have to replace with `<rootdir>`.

While this could be used throughout the whole test suite, I've just
applied this to the CLI tests for now because I think they've got the
most to gain whereas it'd be a lot of tedious work to switch to using it
everywhere; it should be easy to switch to using it in other places over
time.

I have also confirmed that `dedent` correctly handles both spaces and
tabs - you can mix and match them without issue (and in fact a few of
the tests are using spaces instead of tabs).
  • Loading branch information
G-Rath authored Sep 27, 2023
1 parent 195e57b commit 8113801
Showing 1 changed file with 112 additions and 85 deletions.
Loading

0 comments on commit 8113801

Please sign in to comment.