Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Test-Simple CPAN distribution.

Report information
The Basics
Id: 35685
Status: resolved
Priority: 0/
Queue: Test-Simple

People
Owner: Nobody in particular
Requestors: mlf-bitcard [...] shoebox.net
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: [PATCH] Improving diagnostics for non-printable characters.
I am in the process of writing tests that compare binary data that includes non-printable characters. As it stands, Test::More does not provide very useful diagnostics for when these tests fail. The attached patch attempts to solve this problem by replacing non-printable characters with equivalent escape sequences in _is_diag. It also modifies t/fail-more.t to test the failure diagnostics. The patch should only affect is_eq tests.
Subject: is_diag-unprintables.patch
diff -urN Test-Simple-0.80~orig/lib/Test/Builder.pm Test-Simple-0.80~mod/lib/Test/Builder.pm --- Test-Simple-0.80~orig/lib/Test/Builder.pm 2008-04-06 07:26:10.000000000 -0800 +++ Test-Simple-0.80~mod/lib/Test/Builder.pm 2008-05-07 01:45:23.000000000 -0800 @@ -563,6 +563,14 @@ if( defined $$val ) { if( $type eq 'eq' ) { # quote and force string context + $$val =~ s{ + (\\)|([^[:print:]\n]) + }{ + defined $1 + ? "\\\\" + : sprintf('\\x%02X', ord $2) + }egx; + $$val = "'$$val'" } else { diff -urN Test-Simple-0.80~orig/t/fail-more.t Test-Simple-0.80~mod/t/fail-more.t --- Test-Simple-0.80~orig/t/fail-more.t 2007-09-13 19:12:35.000000000 -0800 +++ Test-Simple-0.80~mod/t/fail-more.t 2008-05-07 02:14:49.000000000 -0800 @@ -45,7 +45,7 @@ package main; require Test::More; -my $Total = 30; +my $Total = 33; Test::More->import(tests => $Total); # This should all work in the presence of a __DIE__ handler. @@ -66,10 +66,13 @@ ERR #line 40 -is( "foo", "bar", 'foo is bar?'); -is( undef, '', 'undef is empty string?'); -is( undef, 0, 'undef is 0?'); -is( '', 0, 'empty string is 0?' ); +is( "foo", "bar", 'foo is bar?'); +is( undef, '', 'undef is empty string?'); +is( undef, 0, 'undef is 0?'); +is( '', 0, 'empty string is 0?' ); +is( "\0", '', 'nul is ""?' ); +is( "\0", "\xFF", 'nul is \\xFF?' ); +is( "\1foo", "\1bar", '\\1foo is \\1bar?' ); err_ok( <<ERR ); # Failed test 'foo is bar?' # at $0 line 40. @@ -87,6 +90,18 @@ # at $0 line 43. # got: '' # expected: '0' +# Failed test 'nul is ""?' +# at $0 line 44. +# got: '\\x00' +# expected: '' +# Failed test 'nul is \\xFF?' +# at $0 line 45. +# got: '\\x00' +# expected: '\\xFF' +# Failed test '\\1foo is \\1bar?' +# at $0 line 46. +# got: '\\x01foo' +# expected: '\\x01bar' ERR #line 45 @@ -290,6 +305,9 @@ not ok - undef is empty string? not ok - undef is 0? not ok - empty string is 0? +not ok - nul is ""? +not ok - nul is \\xFF? +not ok - \\1foo is \\1bar? not ok - foo isnt foo? not ok - foo isn't foo? not ok - undef isnt undef?
On Wed May 07 03:38:07 2008, mlfowler wrote: Show quoted text
> I am in the process of writing tests that compare binary data that > includes non-printable characters. As it stands, Test::More does not > provide very useful diagnostics for when these tests fail. The attached > patch attempts to solve this problem by replacing non-printable > characters with equivalent escape sequences in _is_diag. It also > modifies t/fail-more.t to test the failure diagnostics. > > The patch should only affect is_eq tests.
is() as provided by Test2::Suite handled non-printable characters quite nicely. Changing how is() in Test::More works is risky. If you still want this done please re-open on github, a new patch is probably needed.