Pester: Error messages with long strings could be displayed better

Created on 13 May 2016  路  4Comments  路  Source: pester/Pester

Scenario

Tests with pattern

$CreatedLongString | Should Be $ExpectedLongString

Problem

The error message is cumbersome to read (text is too long and spreads multiply lines).
So sometimes I'm trying to split it with `n and then compare each line.
For example in platyPS

But then I need to carry around the line number and display it somehow additionaly.
It's becoming hairy pretty fast.

Proposal

We can take the same approach as xUnit: show a short snippet from the place in the stirng, where it's different (like 32 chars) with additional offset for the beginning of the snippet.

Feature Help Wanted good first issue

All 4 comments

I think this should be relatively simple to add to the code that prints Should -Be output of strings. There is arrow that points to the difference, so the output needs to be shortened around that. We should either detect how wide the window is, or (probably better) set some maximum length for the output.

@vors Do I understand it correctly that this:

Expected strings to be the same, but they were different.
Expected length: 107
Actual length:   120
Strings differ at index 64.
Expected: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'
But was:  'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'
---------------------------------------------------------------------------^

Would become this:

Expected strings to be the same, but they were different.
Expected length: 107
Actual length:   120
Strings differ at index 64.
Expected: 'aaaa...aaaaaaaaabbbbbbbbbb...bbbb'
But was:  'aaaa...aaaaaaaaabbbbbbbbbb....bbbb'
---------------...------------^

The problem is better illustrated by this example. Notice how the wrapping is hard to follow

It 'long string' {
    $a = ('a' * 1300) + ('b' * 1200)
    $b = ('a' * 1301) + ('b' * 1199)
    $a | Should Be $b
}

image

In xUnit it's done very good: it always uses same length for the ellipses and only deletes the same context, so the final result is representative (I think it also includes the offsets after the ellipsis).

I think I can take this one -- looking at xUnit, the final output should be something like:

Expected strings to be the same, but they were different.
String lengths are both 2500.
Strings differ at index 1300.
Expected: '...aaaaaabbbb...'
But was:  '...aaaaabbbbb...'
-------------------^

@jd-porter nice, thank you for working on it!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nohwnd picture nohwnd  路  22Comments

nohwnd picture nohwnd  路  17Comments

iRon7 picture iRon7  路  20Comments

Stephanevg picture Stephanevg  路  26Comments

rkeithhill picture rkeithhill  路  18Comments