Hi all,
I asked this yesterday on the user@groovy mailing list, but since Spock users would be affected by this mostly (I believe Spock uses Groovy power asserts since they moved into groovy), I thought it might be wise to also ask here.
I am wondering whether the output of PowerAsserts should be increased
to help understand test failures more easily.
Here are some examples (column alignment will look bad with
non-monospace fonts):
groovy:000> def id(it) {it}
===> true
groovy:000> assert [false, false] == id(['false', 'false'])
assert [false, false] == id(['false', 'false'])
| |
| [false, false]
false
groovy:000> assert [1, 2, 3, 4] == id('1'..'4')
assert [1, 2, 3, 4] == id('1'..'4')
| |
| [1, 2, 3, 4]
false
groovy:000> assert [1, 2, 3, 4] == new HashSet([1, 2, 3, 4])
assert [1, 2, 3, 4] == new HashSet([1, 2, 3, 4])
| |
| [1, 2, 3, 4]
false
groovy:000> assert [1, 2, 3, 4] == id('[1, 2, 3, 4]')
assert [1, 2, 3, 4] == id('[1, 2, 3, 4]')
| |
| [1, 2, 3, 4]
false
groovy:000> assert [1, 2, 3, 4] == id([1, 2, '3, 4'])
assert [1, 2, 3, 4] == id([1, 2, '3, 4'])
| |
| [1, 2, 3, 4]
false
As you can see the output in these cases does not help the user
understand what went wrong (assume the right hand side of the == being
something like foo()). This could be helped e.g. by adding hyphens
around Strings.
Another problem is checking escape symbols:
groovy:000> assert '\\\' \\\'' == id('\\\'\\\' \'')
assert '\\\' \\\'' == id('\\\'\\\' \'')
| |
| \'\' '
false
Here the power assert output is the final form of the string, not the
code-form. And it is a pain to mentally (un)escape to compare and find
differences.
So I would suggest extending the output such that:
- String values generally get quoted (with escaped special symbols),
- non-List collections get Type information added like "[x, y] as Set"
- Ranges are printed in code notation (e.g. 1..4 instead of [1, 2, 3, 4])
One of the small problems is that Strings like
'one\ntwo\rthree\r\nfour', which are rendered as multiline values,
will be rendered using \n, looking a bit uglier maybe.
Would that change be helpful? Can the behavior be changed without
breaking user code unduly?
What do you think?
Should I post updates about this here as well?