diff options
author | Jesse Vincent <jesse@bestpractical.com> | 2010-02-06 18:02:40 -0800 |
---|---|---|
committer | Jesse Vincent <jesse@bestpractical.com> | 2010-02-06 18:02:40 -0800 |
commit | 958ff85a3beda75133fa1f15afaccedc1ad73fa0 (patch) | |
tree | cf6c5f868557af51e299fa491136e19b70331d9e /t | |
parent | d963bf01c4c4db296760b1148f98bf668efcaf58 (diff) | |
parent | 6369c7393bb30f601a91122207e7cc0f0d72983f (diff) | |
download | perl-958ff85a3beda75133fa1f15afaccedc1ad73fa0.tar.gz |
Merge branch 'blead' of ssh://perl5.git.perl.org/gitroot/perl into blead
* 'blead' of ssh://perl5.git.perl.org/gitroot/perl:
move version details to version::Internals and other clean up
document version::is_strict/is_lax
Document usage of version regexps
Export and document is_lax and is_strict functions
note that delete/exists ARRAY_ELEM should be avoided
Don't try to calculate a time over the conservative failure boundary.
Diffstat (limited to 't')
-rw-r--r-- | t/op/time.t | 46 | ||||
-rw-r--r-- | t/op/time_loop.t | 16 |
2 files changed, 52 insertions, 10 deletions
diff --git a/t/op/time.t b/t/op/time.t index 5515634343..84eaf752f3 100644 --- a/t/op/time.t +++ b/t/op/time.t @@ -1,4 +1,4 @@ -#!./perl +#!./perl -w BEGIN { chdir 't' if -d 't'; @@ -6,7 +6,7 @@ BEGIN { require './test.pl'; } -plan tests => 56; +plan tests => 62; # These tests make sure, among other things, that we don't end up # burning tons of CPU for dates far in the future. @@ -36,9 +36,9 @@ ok($i >= 2_000_000, 'very basic times test'); ($xsec,$foo) = localtime($now); $localyday = $yday; -isnt($sec, $xsec), 'localtime() list context'; -ok $mday, ' month day'; -ok $year, ' year'; +isnt($sec, $xsec, 'localtime() list context'); +ok $mday, ' month day'; +ok $year, ' year'; ok(localtime() =~ /^(Sun|Mon|Tue|Wed|Thu|Fri|Sat)[ ] (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[ ] @@ -66,9 +66,9 @@ ok($hour != $hour2, 'changes to $ENV{TZ} respected') ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime($beg); ($xsec,$foo) = localtime($now); -isnt($sec, $xsec), 'gmtime() list conext'; -ok $mday, ' month day'; -ok $year, ' year'; +isnt($sec, $xsec, 'gmtime() list conext'); +ok $mday, ' month day'; +ok $year, ' year'; my $day_diff = $localyday - $yday; ok( grep({ $day_diff == $_ } (0, 1, -1, 364, 365, -364, -365)), @@ -142,12 +142,12 @@ ok(gmtime() =~ /^(Sun|Mon|Tue|Wed|Thu|Fri|Sat)[ ] { eval { $SIG{__WARN__} = sub { die @_; }; - localtime(1.23); + is( (localtime(1296000.23))[5] + 1900, 1970 ); }; is($@, '', 'Ignore fractional time'); eval { $SIG{__WARN__} = sub { die @_; }; - gmtime(1.23); + is( (gmtime(1.23))[5] + 1900, 1970 ); }; is($@, '', 'Ignore fractional time'); } @@ -174,3 +174,29 @@ ok(gmtime() =~ /^(Sun|Mon|Tue|Wed|Thu|Fri|Sat)[ ] is $have, $want, "year check, localtime($time)"; } } + + +# Test that Perl warns properly when it can't handle a time. +{ + my $warning; + local $SIG{__WARN__} = sub { $warning .= join "\n", @_; }; + + my $big_time = 2**60; + my $small_time = -2**60; + + $warning = ''; + my $date = gmtime($big_time); + like $warning, qr/^gmtime(.*) too large/; + + $warning = ''; + $date = localtime($big_time); + like $warning, qr/^localtime(.*) too large/; + + $warning = ''; + $date = gmtime($small_time); + like $warning, qr/^gmtime(.*) too small/; + + $warning = ''; + $date = localtime($small_time); + like $warning, qr/^localtime(.*) too small/; +} diff --git a/t/op/time_loop.t b/t/op/time_loop.t new file mode 100644 index 0000000000..6f4acdc1f9 --- /dev/null +++ b/t/op/time_loop.t @@ -0,0 +1,16 @@ +#!perl -w + +# d95a2ea538e6c332f36c34ca45b78d6ad93c3a1f allowed times greater than +# 2**63 to be handed to gm/localtime() which caused an internal overflow +# and an excessively long loop. Test this does not happen. + +use strict; + +BEGIN { require './test.pl'; } + +plan tests => 2; +watchdog(2); + +local $SIG{__WARN__} = sub {}; +is gmtime(2**69), undef; +is localtime(2**69), undef; |