From: Michael G. Schwern Date: Fri, 6 Sep 2002 14:03:16 +0000 (-0700) Subject: Re: [PATCH t/test.pl] Let is/isnt() handle undef without warnings X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c831d34fb12f71d1bffb73fbcf1d43a945de63bd;p=p5sagit%2Fp5-mst-13.2.git Re: [PATCH t/test.pl] Let is/isnt() handle undef without warnings Message-ID: <20020906210315.GC808@ool-18b93024.dyn.optonline.net> p4raw-id: //depot/perl@17861 --- diff --git a/t/test.pl b/t/test.pl index 427a64f..735d966 100644 --- a/t/test.pl +++ b/t/test.pl @@ -133,7 +133,16 @@ sub display { sub is { my ($got, $expected, $name, @mess) = @_; - my $pass = $got eq $expected; + + my $pass; + if( !defined $got || !defined $expected ) { + # undef only matches undef + $pass = !defined $got && !defined $expected; + } + else { + $pass = $got eq $expected; + } + unless ($pass) { unshift(@mess, "# got "._q($got)."\n", "# expected "._q($expected)."\n"); @@ -143,7 +152,16 @@ sub is { sub isnt { my ($got, $isnt, $name, @mess) = @_; - my $pass = $got ne $isnt; + + my $pass; + if( !defined $got || !defined $isnt ) { + # undef only matches undef + $pass = defined $got || defined $isnt; + } + else { + $pass = $got ne $isnt; + } + unless( $pass ) { unshift(@mess, "# it should not be "._q($got)."\n", "# but it is.\n");