From: Jarkko Hietaniemi Date: Thu, 8 Nov 2001 22:06:31 +0000 (+0000) Subject: Quote the variables in failures messages more nicely. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b3c72391994409d4c0de25d67a0871d34a225923;p=p5sagit%2Fp5-mst-13.2.git Quote the variables in failures messages more nicely. p4raw-id: //depot/perl@12907 --- diff --git a/t/test.pl b/t/test.pl index 3a5db4d..eaf9d86 100644 --- a/t/test.pl +++ b/t/test.pl @@ -72,12 +72,20 @@ sub ok { _ok($pass, _where(), $name, @mess); } +sub _q { + my $x = shift; + return 'undef' unless defined $x; + my $q = $x; + $q =~ s/'/\\'/; + return "'$q'"; +} + sub is { my ($got, $expected, $name, @mess) = @_; my $pass = $got eq $expected; unless ($pass) { - unshift(@mess, "# got '$got'\n", - "# expected '$expected'\n"); + unshift(@mess, "# got "._q($got)."\n", + "# expected "._q($expected)."\n"); } _ok($pass, _where(), $name, @mess); } @@ -86,7 +94,7 @@ sub isnt { my ($got, $isnt, $name, @mess) = @_; my $pass = $got ne $isnt; unless( $pass ) { - unshift(@mess, "# it should not be $got\n", + unshift(@mess, "# it should not be "._q($got)."\n", "# but it is.\n"); } _ok($pass, _where(), $name, @mess);