diff options
author | Nicholas Clark <nick@ccl4.org> | 2008-01-12 22:20:39 +0000 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2008-01-12 22:20:39 +0000 |
commit | 9f621bb00a11fa3741b155ff668ae147fed95cf0 (patch) | |
tree | 7b5b39f40f93859c7938b76462590a705d7a4147 /t | |
parent | d06445298904613950b0410a2f3b1125ab58c7b5 (diff) | |
download | perl-9f621bb00a11fa3741b155ff668ae147fed95cf0.tar.gz |
For 5.12: saner behaviour for `length`
(Make C<length undef> return undef).
Patch mostly by Rafael, with some fine tuning by me.
p4raw-id: //depot/perl@32969
Diffstat (limited to 't')
-rw-r--r-- | t/lib/warnings/9uninit | 7 | ||||
-rw-r--r-- | t/lib/warnings/mg | 8 | ||||
-rw-r--r-- | t/op/length.t | 37 | ||||
-rwxr-xr-x | t/op/vec.t | 2 |
4 files changed, 44 insertions, 10 deletions
diff --git a/t/lib/warnings/9uninit b/t/lib/warnings/9uninit index e2e6ef9fec..1e4344ae3b 100644 --- a/t/lib/warnings/9uninit +++ b/t/lib/warnings/9uninit @@ -826,8 +826,8 @@ $v = eval {log $m1}; $v = sqrt $m1; $v = hex $m1; $v = oct $m1; -$v = length $m1; -$v = length; +$v = oct; +$v = length; # does not warn EXPECT Use of uninitialized value $g1 in atan2 at - line 5. Use of uninitialized value $m1 in atan2 at - line 5. @@ -840,8 +840,7 @@ Use of uninitialized value $m1 in log at - line 11. Use of uninitialized value $m1 in sqrt at - line 12. Use of uninitialized value $m1 in hex at - line 13. Use of uninitialized value $m1 in oct at - line 14. -Use of uninitialized value $m1 in length at - line 15. -Use of uninitialized value $_ in length at - line 16. +Use of uninitialized value $_ in oct at - line 15. ######## use warnings 'uninitialized'; my ($m1, $v); diff --git a/t/lib/warnings/mg b/t/lib/warnings/mg index 2e2d4aa0f3..8915c2866b 100644 --- a/t/lib/warnings/mg +++ b/t/lib/warnings/mg @@ -46,15 +46,15 @@ EXPECT # mg.c use warnings 'uninitialized'; 'foo' =~ /(foo)/; -length $3; +oct $3; EXPECT -Use of uninitialized value $3 in length at - line 4. +Use of uninitialized value $3 in oct at - line 4. ######## # mg.c use warnings 'uninitialized'; -length $3; +oct $3; EXPECT -Use of uninitialized value $3 in length at - line 3. +Use of uninitialized value $3 in oct at - line 3. ######## # mg.c use warnings 'uninitialized'; diff --git a/t/op/length.t b/t/op/length.t index 41d34aee8e..eb357203ec 100644 --- a/t/op/length.t +++ b/t/op/length.t @@ -6,7 +6,7 @@ BEGIN { @INC = '../lib'; } -plan (tests => 22); +plan (tests => 28); print "not " unless length("") == 0; print "ok 1\n"; @@ -161,3 +161,38 @@ tie $u, 'Tie::StdScalar', chr 256; is(length $u, 1, "Length of a UTF-8 scalar returned from tie"); is(length $u, 1, "Again! Again!"); +$^W = 1; + +my $warnings = 0; + +$SIG{__WARN__} = sub { + $warnings++; + warn @_; +}; + +is(length(undef), undef, "Length of literal undef"); + +my $u; + +is(length($u), undef, "Length of regular scalar"); + +$u = "Gotcha!"; + +tie $u, 'Tie::StdScalar'; + +is(length($u), undef, "Length of tied scalar (MAGIC)"); + +is($u, undef); + +{ + package U; + use overload '""' => sub {return undef;}; +} + +my $uo = bless [], 'U'; + +is(length($uo), undef, "Length of overloaded reference"); + +# ok(!defined $uo); Turns you can't test this. FIXME for pp_defined? + +is($warnings, 0, "There were no warnings"); diff --git a/t/op/vec.t b/t/op/vec.t index 4ca23f1a94..aed1d0f170 100755 --- a/t/op/vec.t +++ b/t/op/vec.t @@ -11,7 +11,7 @@ plan( tests => 31 ); my $Is_EBCDIC = (ord('A') == 193) ? 1 : 0; is(vec($foo,0,1), 0); -is(length($foo), 0); +is(length($foo), undef); vec($foo,0,1) = 1; is(length($foo), 1); is(unpack('C',$foo), 1); |