Test::LongString


Test::LongString of Rafael Garcia-Suarez for better error reporting when comparing strings. Especially long strings.


examples/test-perl/t/test_longstring.t
use strict;
use warnings;

use Test::More;
use Test::LongString;

plan tests => 2;

my ($expected, $actual) = generate(200, 170);
is $actual, $expected;

is_string $actual, $expected;




sub generate {
  my ($cnt, $loc) = @_;

  my @chars = ('a' .. 'z', 'A' .. 'Z');
  my $str = '';
  $str .= $chars[ rand scalar @chars ] for 1..$cnt;

  my $actual   = $str;
  substr($actual, $loc, 1, ' ');

  return ($str, $actual);
}

1..2
not ok 1
#   Failed test at t/test_longstring.t line 10.
#          got: 'qgjVLTjmhSKWoIZIAiCNSBkJQOOrLUYVihtrBehKKtUEozKzZvJDwClTCgHayvbrPsZojPiNGrzwXNDtuEpHuBcSDepTsoNlzPWMezBhuCJJZPbsLVMDWvuMZfXjtDhSrAsfrciXuJuZVCEXTBxkLXwklcgrqXMPoPloZhdoxu iTGjygbCuiSpNTgrdrkpONiEVfAEa'
#     expected: 'qgjVLTjmhSKWoIZIAiCNSBkJQOOrLUYVihtrBehKKtUEozKzZvJDwClTCgHayvbrPsZojPiNGrzwXNDtuEpHuBcSDepTsoNlzPWMezBhuCJJZPbsLVMDWvuMZfXjtDhSrAsfrciXuJuZVCEXTBxkLXwklcgrqXMPoPloZhdoxuBiTGjygbCuiSpNTgrdrkpONiEVfAEa'
not ok 2
#   Failed test at t/test_longstring.t line 12.
#          got: ..."oPloZhdoxu iTGjygbCuiSpNTgrdrkpONiEVfAEa"...
#       length: 200
#     expected: ..."oPloZhdoxuBiTGjygbCuiSpNTgrdrkpONiEVfAEa"...
#       length: 200
#     strings begin to differ at char 171 (line 1 column 171)
# Looks like you failed 2 tests of 2.