diff options
author | Michael G Schwern <schwern@pobox.com> | 2008-09-13 19:26:38 -0700 |
---|---|---|
committer | Rafael Garcia-Suarez <rgarciasuarez@gmail.com> | 2009-01-03 18:36:58 +0100 |
commit | 769448c3cab313c28d3bb9ef48e54401476b9607 (patch) | |
tree | 78fd5f9234bd658f69077ae682eb11f04cfad60f /lib/Time | |
parent | af9b2bf51b38ba7606ef7abea6125f33702020ab (diff) | |
download | perl-769448c3cab313c28d3bb9ef48e54401476b9607.tar.gz |
Cleaning up the Time::gmtime and Time::localtime tests and make them go past 2038.
I'm a little nervous about assuming negative times are going to work with
localtime(), but gmtime() is safe.
Diffstat (limited to 'lib/Time')
-rw-r--r-- | lib/Time/gmtime.t | 56 | ||||
-rw-r--r-- | lib/Time/localtime.t | 56 |
2 files changed, 27 insertions, 85 deletions
diff --git a/lib/Time/gmtime.t b/lib/Time/gmtime.t index 853ec3b6e3..0e3855c8db 100644 --- a/lib/Time/gmtime.t +++ b/lib/Time/gmtime.t @@ -3,55 +3,19 @@ BEGIN { chdir 't' if -d 't'; @INC = '../lib'; -} -BEGIN { - our $hasgm; - eval { my $n = gmtime 0 }; - $hasgm = 1 unless $@ && $@ =~ /unimplemented/; - unless ($hasgm) { print "1..0 # Skip: no gmtime\n"; exit 0 } -} - -BEGIN { - our @gmtime = gmtime 0; # This is the function gmtime. - unless (@gmtime) { print "1..0 # Skip: gmtime failed\n"; exit 0 } + require "./test.pl"; } -print "1..10\n"; - -use Time::gmtime; - -print "ok 1\n"; - -my $gmtime = gmtime 0 ; # This is the OO gmtime. - -print "not " unless $gmtime->sec == $gmtime[0]; -print "ok 2\n"; - -print "not " unless $gmtime->min == $gmtime[1]; -print "ok 3\n"; - -print "not " unless $gmtime->hour == $gmtime[2]; -print "ok 4\n"; - -print "not " unless $gmtime->mday == $gmtime[3]; -print "ok 5\n"; - -print "not " unless $gmtime->mon == $gmtime[4]; -print "ok 6\n"; - -print "not " unless $gmtime->year == $gmtime[5]; -print "ok 7\n"; - -print "not " unless $gmtime->wday == $gmtime[6]; -print "ok 8\n"; - -print "not " unless $gmtime->yday == $gmtime[7]; -print "ok 9\n"; - -print "not " unless $gmtime->isdst == $gmtime[8]; -print "ok 10\n"; - +BEGIN { plan tests => 37; } +BEGIN { use_ok Time::gmtime; } +for my $time (0, 2**31-1, 2**33, time) { + my $gmtime = gmtime $time; # This is the OO gmtime. + my @gmtime = CORE::gmtime $time; # This is the gmtime function + for my $method (qw(sec min hour mday mon year wday yday isdst)) { + is $gmtime->$method, shift @gmtime, "gmtime($time)->$method"; + } +} diff --git a/lib/Time/localtime.t b/lib/Time/localtime.t index 357615c780..5d935e76b8 100644 --- a/lib/Time/localtime.t +++ b/lib/Time/localtime.t @@ -3,55 +3,33 @@ BEGIN { chdir 't' if -d 't'; @INC = '../lib'; + + require "./test.pl"; } BEGIN { - our $haslocal; + my $haslocal; eval { my $n = localtime 0 }; $haslocal = 1 unless $@ && $@ =~ /unimplemented/; - unless ($haslocal) { print "1..0 # Skip: no localtime\n"; exit 0 } -} -BEGIN { - our @localtime = localtime 0; # This is the function localtime. - unless (@localtime) { print "1..0 # Skip: localtime failed\n"; exit 0 } + skip_all("no localtime") unless $haslocal; } -print "1..10\n"; - -use Time::localtime; - -print "ok 1\n"; - -my $localtime = localtime 0 ; # This is the OO localtime. - -print "not " unless $localtime->sec == $localtime[0]; -print "ok 2\n"; - -print "not " unless $localtime->min == $localtime[1]; -print "ok 3\n"; - -print "not " unless $localtime->hour == $localtime[2]; -print "ok 4\n"; - -print "not " unless $localtime->mday == $localtime[3]; -print "ok 5\n"; - -print "not " unless $localtime->mon == $localtime[4]; -print "ok 6\n"; - -print "not " unless $localtime->year == $localtime[5]; -print "ok 7\n"; - -print "not " unless $localtime->wday == $localtime[6]; -print "ok 8\n"; - -print "not " unless $localtime->yday == $localtime[7]; -print "ok 9\n"; +BEGIN { + my @localtime = CORE::localtime 0; # This is the function localtime. -print "not " unless $localtime->isdst == $localtime[8]; -print "ok 10\n"; + skip_all("localtime failed") unless @localtime; +} +BEGIN { plan tests => 37; } +BEGIN { use_ok Time::localtime; } +for my $time (0, 2**31-1, 2**33, time) { + my $localtime = localtime $time; # This is the OO localtime. + my @localtime = CORE::localtime $time; # This is the localtime function + for my $method (qw(sec min hour mday mon year wday yday isdst)) { + is $localtime->$method, shift @localtime, "localtime($time)->$method"; + } +} |