forked from schacon/perl
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
2 changed files
with
57 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' | ||
); | ||
} |