diff options
author | Jarkko Hietaniemi <jhi@iki.fi> | 2001-11-08 22:06:31 +0000 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 2001-11-08 22:06:31 +0000 |
commit | b3c72391994409d4c0de25d67a0871d34a225923 (patch) | |
tree | dd42f85849734de4df265ff0eb33662c96f98f54 | |
parent | e6c299c8c7a701ab02a228bf041af3efe6d81afb (diff) | |
download | perl-b3c72391994409d4c0de25d67a0871d34a225923.tar.gz |
Quote the variables in failures messages more nicely.
p4raw-id: //depot/perl@12907
-rw-r--r-- | t/test.pl | 14 |
1 files changed, 11 insertions, 3 deletions
@@ -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); |