t/50-cgi: optionally use Test::LongString to format failures
authorMischa POSLAWSKY <perl@shiar.org>
Tue, 21 Feb 2012 00:34:04 +0000 (01:34 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Tue, 19 Nov 2013 00:53:21 +0000 (01:53 +0100)
Pretty-print string comparison to directly pinpoint differences
instead of drowning us in full contents.

t/50-cgi.t

index 111e112beeede499f056d763c356f8649ee33a85..58e36d16c108ac5b9b996de38a7619e87049b7c3 100644 (file)
@@ -5,6 +5,20 @@ use Cwd;
 use File::Spec;
 use Test::More;
 
+eval {
+       require Test::LongString;
+       Test::LongString->import(max => 128);
+
+       no warnings 'redefine';  # override module to not escape newlines
+       my $formatter = *Test::LongString::_display;
+       my $parent = \&{$formatter};
+       *{$formatter} = sub {
+               my $s = &{$parent};
+               $s =~ s/\Q\x{0a}/\n              /g;  # revert newline quoting
+               return $s;
+       };
+} or *is_string = \&is;  # fallback to ugly unformatted is()
+
 eval { require PerlIO::scalar };
 plan skip_all => "PerlIO required (perl 5.8) to test PLP" if $@;
 
@@ -57,7 +71,7 @@ sub plp_is {
                return;
        }
        $output =~ s{((?:.+\n)*)}{ join "", sort split /(?<=\n)/, $1 }e; # order headers
-       is($output, $expect, $test);
+       is_string($output, $expect, $test);
 }
 
 sub getwarning {