bats-core / bats-assert

Common assertions for Bats
Creative Commons Zero v1.0 Universal
94 stars 39 forks source link

Print colorful diff between actual output and an expected output on test failure via smth like colordiff #60

Open EmilyGraceSeville7cf opened 1 year ago

EmilyGraceSeville7cf commented 1 year ago

It's really hard to detect the difference between actual and expected output right from the bats message when the test fails. Because bats doesn't indicate what the difference between expectation and real result:

image

Such a message doesn't really show what should be changed to make the test pass.

This issue is transferred from this repository.

brammeleman commented 10 months ago

A colorful diff seems a bit difficult as all failure output is supposed to be red. Looks like adding the output of just diff already seems to be helpful. This quick hack (probably not in bats' coding style) helps me to spot the differences in the expected and actual output. Apply this patch on assert_output.bash:

189a190
>       ( \
192c193,196
<       'actual'   "$output" \
---
>       'actual'   "$output"
>       echo "Diff:"
>       diff <(echo "$expected") <(echo "$output")
>       )\