Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update time.t to blead's as it was occasionally failing
git-svn-id: http://perl5005.googlecode.com/svn/trunk@16 e77bdc90-ac31-0410-a84a-cbf48518d05f
  • Loading branch information
acme committed Oct 2, 2007
1 parent 0216dfb commit 0600390
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 20 deletions.
5 changes: 5 additions & 0 deletions Changes
Expand Up @@ -79,6 +79,11 @@ Version 5.005_04 Fourth maintenance release of 5.005
----------------


____________________________________________________________________________
[ ] By: acme on 2007/09/02 08:19:41
Log: Update time.t to blead's as it was occasionally failing
Branch: maint-5.005/perl
! t/op/time.t
____________________________________________________________________________
[ ] By: acme on 2007/09/01 21:07:49
Log: Fix IPC::SysV test under VC++ 6.0 (Thanks to Steve Hay)
Expand Down
72 changes: 52 additions & 20 deletions t/op/time.t
@@ -1,47 +1,79 @@
#!./perl

# $RCSfile: time.t,v $$Revision: 4.1 $$Date: 92/08/07 18:28:32 $
$does_gmtime = gmtime(time);

if ($does_gmtime = gmtime(time)) { print "1..5\n" }
else { print "1..3\n" }
BEGIN {
chdir 't' if -d 't';
@INC = '../lib';
require './test.pl';
}

plan tests => 8;

($beguser,$begsys) = times;

$beg = time;

while (($now = time) == $beg) { sleep 1 }

if ($now > $beg && $now - $beg < 10){print "ok 1\n";} else {print "not ok 1\n";}
ok($now > $beg && $now - $beg < 10, 'very basic time test');

for ($i = 0; $i < 100000; $i++) {
for ($i = 0; $i < 1_000_000; $i++) {
for my $j (1..100) {}; # burn some user cycles
($nowuser, $nowsys) = times;
$i = 200000 if $nowuser > $beguser && ( $nowsys > $begsys ||
$i = 2_000_000 if $nowuser > $beguser && ( $nowsys >= $begsys ||
(!$nowsys && !$begsys));
last if time - $beg > 20;
}

if ($i >= 200000) {print "ok 2\n";} else {print "not ok 2\n";}
ok($i >= 2_000_000, 'very basic times test');

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($beg);
($xsec,$foo) = localtime($now);
$localyday = $yday;

if ($sec != $xsec && $mday && $year)
{print "ok 3\n";}
else
{print "not ok 3\n";}
ok($sec != $xsec && $mday && $year, 'localtime() list context');

ok(localtime() =~ /^(Sun|Mon|Tue|Wed|Thu|Fri|Sat)[ ]
(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[ ]
([ \d]\d)\ (\d\d):(\d\d):(\d\d)\ (\d{4})$
/x,
'localtime(), scalar context'
);

SKIP: {
# This conditional of "No tzset()" is stolen from ext/POSIX/t/time.t
skip "No tzset()", 1
if $^O eq "MacOS" || $^O eq "VMS" || $^O eq "cygwin" ||
$^O eq "djgpp" || $^O eq "MSWin32" || $^O eq "dos" ||
$^O eq "interix";

# check that localtime respects changes to $ENV{TZ}
$ENV{TZ} = "GMT-5";
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($beg);
$ENV{TZ} = "GMT+5";
($sec,$min,$hour2,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($beg);
ok($hour != $hour2, 'changes to $ENV{TZ} respected');
}

exit 0 unless $does_gmtime;
SKIP: {
skip "No gmtime()", 3 unless $does_gmtime;

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime($beg);
($xsec,$foo) = localtime($now);

if ($sec != $xsec && $mday && $year)
{print "ok 4\n";}
else
{print "not ok 4\n";}
ok($sec != $xsec && $mday && $year, 'gmtime() list context');

my $day_diff = $localyday - $yday;
ok( grep { $day_diff == $_ } (0, 1, -1, 364, 365, -364, -365),
'gmtime() and localtime() agree what day of year');

if (index(" :0:1:-1:364:365:-364:-365:",':' . ($localyday - $yday) . ':') > 0)
{print "ok 5\n";}
else
{print "not ok 5\n";}

# This could be stricter.
ok(gmtime() =~ /^(Sun|Mon|Tue|Wed|Thu|Fri|Sat)[ ]
(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[ ]
([ \d]\d)\ (\d\d):(\d\d):(\d\d)\ (\d{4})$
/x,
'gmtime(), scalar context'
);
}

0 comments on commit 0600390

Please sign in to comment.