Show coloured tree-diff output in ImpTests
Description
We use tree-diff to show the difference between actual and expected output in tests, and although tree-diff very helpfully colours the insertions and deletions the output is currently entirely red.
There are two main reasons for this:
-
hspecforces a red colour on every line when it outputs the text of a failure message.This can be overcome by adding
--no-colorto the command-line test options. Unfortunately, this also drops using colour in the progress messages, but in most circumstances that's an acceptable tradeoff. When it's fairly certain that all tests will pass (eg when doing a final test run before pushing) omitting--no-colorcan be helpful.More investigation is needed to determine whether there's a way to defeat
hspec's aggressive colourization of failure messages. -
The messages are rendered to
Stringin order to become expectation failures, and this throws away all of the text attributes such as colour.This can be overcome by changing the method of rendering the
Doc AnsiStyleproduced bytree-diffso that the escape codes are embedded in the failure message.At the same time, it's also helpful to allow our own
ImpTestlogging functions to acceptDoc AnsiStyleinstead ofStringso that coloured text can be output to the log.
This PR makes the changes necessary for (2), and few other quality-of-life improvements related to the use of colour.
Closes #4471
Checklist
- [x] Commit sequence broadly makes sense and commits have useful messages
- [ ] New tests are added if needed and existing tests are updated
- [ ] When applicable, versions are updated in
.cabalandCHANGELOG.mdfiles according to the versioning process. - [ ] The version bounds in
.cabalfiles for all affected packages are updated. If you change the bounds in a cabal file, that package itself must have a version increase. (See RELEASING.md) - [ ] All visible changes are prepended to the latest section of a
CHANGELOG.mdfor the affected packages. New section is never added with the code changes. (See RELEASING.md) - [x] Code is formatted with
fourmolu(usescripts/fourmolize.sh) - [x] Cabal files are formatted (use
scripts/cabal-format.sh) - [x]
hie.yamlhas been updated (usescripts/gen-hie.sh) - [x] Self-reviewed the diff
This is based on the branch from #4440 because otherwise they would conflict with each other. I'm assuming that #4440 will be merged first.
We may want to include changing the CI workflow to use --no-color