From: Vincent Pit Date: Fri, 24 Dec 2010 17:15:02 +0000 (+0100) Subject: Only is() should treat undef specially X-Git-Tag: v0.01~25 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=1f18a8970afb90a780a29c9839e3ffee0bc2d5ba;p=perl%2Fmodules%2FTest-Leaner.git Only is() should treat undef specially --- diff --git a/lib/Test/Leaner.pm b/lib/Test/Leaner.pm index 5e2f0a5..a022c92 100644 --- a/lib/Test/Leaner.pm +++ b/lib/Test/Leaner.pm @@ -296,11 +296,7 @@ BEGIN { eval <<"IS_BINOP"; sub is_$name (\$\$;\$) { my (\$x, \$y, \$desc) = \@_; - no warnings 'uninitialized'; - \@_ = ( - (not(defined \$x xor defined \$y) and \$x $op \$y), - \$desc, - ); + \@_ = ((\$x $op \$y), \$desc); goto &ok; } IS_BINOP @@ -308,11 +304,14 @@ IS_BINOP } } -{ - no warnings 'once'; - *is = \&is_eq; - *like = \&is_like; - *unlike = \&is_unlike; +sub is ($$;$) { + my ($got, $expected, $desc) = @_; + no warnings 'uninitialized'; + @_ = ( + (not(defined $got xor defined $expected) and $got eq $expected), + $desc, + ); + goto &ok; } sub isnt ($$;$) { @@ -325,6 +324,12 @@ sub isnt ($$;$) { goto &ok; } +{ + no warnings 'once'; + *like = \&is_like; + *unlike = \&is_unlike; +} + sub cmp_ok ($$$;$) { my ($x, $op, $y, $desc) = @_; my $name = $binops{$op}; diff --git a/t/21-is.t b/t/21-is.t index 97dc57a..2059fca 100644 --- a/t/21-is.t +++ b/t/21-is.t @@ -5,11 +5,12 @@ use warnings; use Test::Leaner; -plan tests => 7; +plan tests => 8; is undef, undef, 'undef is undef'; -isnt 1, undef, 'one is not undef'; -isnt undef, 1, 'undef is not one'; +isnt 0, undef, 'zero is not undef'; +isnt undef, 0, 'undef is not zero'; +is 0, 0, 'zero is zero'; is 1, 1, 'one is one'; isnt '1.0', 1, '1.0 is not one string-wise';