X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fop%2Ftime.t;h=870a8dcf03925c1608ec91b8a9f3ebe839644bb1;hb=0bc0ad857ef0ded50c72fba42503c958a1579a5a;hp=28635219fe801791b0d4d599471c198686c65441;hpb=fe14fcc35f78a371a174a1d14256c2f35ae4262b;p=p5sagit%2Fp5-mst-13.2.git diff --git a/t/op/time.t b/t/op/time.t old mode 100644 new mode 100755 index 2863521..870a8dc --- a/t/op/time.t +++ b/t/op/time.t @@ -1,43 +1,75 @@ #!./perl -# $Header: time.t,v 4.0 91/03/20 01:55:09 lwall Locked $ +# $RCSfile: time.t,v $$Revision: 4.1 $$Date: 92/08/07 18:28:32 $ + +if ( $does_gmtime = gmtime(time) ) { + print "1..7\n" +} +else { + print "1..4\n" +} + + +my $test = 1; +sub ok ($$) { + my($ok, $name) = @_; + + # You have to do it this way or VMS will get confused. + print $ok ? "ok $test - $name\n" : "not ok $test - $name\n"; + + printf "# Failed test at line %d\n", (caller)[2] unless $ok; + + $test++; + return $ok; +} -print "1..5\n"; ($beguser,$begsys) = times; $beg = time; -while (($now = time) == $beg) {} +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++) { ($nowuser, $nowsys) = times; - $i = 200000 if $nowuser > $beguser && $nowsys > $begsys; + $i = 200000 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 >= 200000, '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' + ); + +exit 0 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:365:366:-365:-366:",':' . ($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' + );