groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thibault Kruse <tibokr...@googlemail.com>
Subject Should PowerAsserts be more verbose?
Date Tue, 25 Aug 2015 08:50:47 GMT
Hi all,

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] == '[1, 2, 3, 4]'
assert [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?

Mime
View raw message