diff options
author | Leon Brocard <acme@astray.com> | 2007-10-02 07:20:07 +0000 |
---|---|---|
committer | Leon Brocard <acme@astray.com> | 2007-10-02 07:20:07 +0000 |
commit | 0600390d2dc4cba49f523aa97e556bf8ae6a5bdf (patch) | |
tree | 34dafd06a2562be3f8146785df88e91650a2b9e0 | |
parent | 0216dfb289f79e57ae7edc7da153f85069966141 (diff) | |
download | perl-0600390d2dc4cba49f523aa97e556bf8ae6a5bdf.tar.gz |
Update time.t to blead's as it was occasionally failingGitLive-maint-5.005
git-svn-id: http://perl5005.googlecode.com/svn/trunk@16 e77bdc90-ac31-0410-a84a-cbf48518d05f
-rw-r--r-- | Changes | 5 | ||||
-rwxr-xr-x | t/op/time.t | 72 |
2 files changed, 57 insertions, 20 deletions
@@ -80,6 +80,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) Branch: maint-5.005/perl diff --git a/t/op/time.t b/t/op/time.t index 1bec442fe2..8489d891b9 100755 --- a/t/op/time.t +++ b/t/op/time.t @@ -1,9 +1,14 @@ #!./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; @@ -11,37 +16,64 @@ $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' + ); +} |