This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Allow more tries for t/op/time.t test 2.
[perl5.git] / t / op / time.t
CommitLineData
8d063cd8
LW
1#!./perl
2
79072805 3# $RCSfile: time.t,v $$Revision: 4.1 $$Date: 92/08/07 18:28:32 $
8d063cd8 4
26575770
MS
5if ( $does_gmtime = gmtime(time) ) {
6 print "1..7\n"
7}
8else {
9 print "1..4\n"
10}
11
12
13my $test = 1;
14sub ok ($$) {
15 my($ok, $name) = @_;
16
17 # You have to do it this way or VMS will get confused.
18 print $ok ? "ok $test - $name\n" : "not ok $test - $name\n";
19
20 printf "# Failed test at line %d\n", (caller)[2] unless $ok;
21
22 $test++;
23 return $ok;
24}
25
8d063cd8
LW
26
27($beguser,$begsys) = times;
28
29$beg = time;
30
463ee0b2 31while (($now = time) == $beg) { sleep 1 }
8d063cd8 32
26575770 33ok($now > $beg && $now - $beg < 10, 'very basic time test');
8d063cd8 34
5f80d426 35for ($i = 0; $i < 1_000_000; $i++) {
8d063cd8 36 ($nowuser, $nowsys) = times;
5f80d426 37 $i = 2_000_000 if $nowuser > $beguser && ( $nowsys >= $begsys ||
a0d0e21e 38 (!$nowsys && !$begsys));
8d063cd8
LW
39 last if time - $beg > 20;
40}
41
5f80d426 42ok($i >= 2_000_000, 'very basic times test');
8d063cd8
LW
43
44($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($beg);
45($xsec,$foo) = localtime($now);
46$localyday = $yday;
47
26575770
MS
48ok($sec != $xsec && $mday && $year, 'localtime() list context');
49
50ok(localtime() =~ /^(Sun|Mon|Tue|Wed|Thu|Fri|Sat)[ ]
51 (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[ ]
52 ([ \d]\d)\ (\d\d):(\d\d):(\d\d)\ (\d{4})$
53 /x,
54 'localtime(), scalar context'
55 );
8d063cd8 56
a0d0e21e
LW
57exit 0 unless $does_gmtime;
58
8d063cd8
LW
59($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime($beg);
60($xsec,$foo) = localtime($now);
61
26575770
MS
62ok($sec != $xsec && $mday && $year, 'gmtime() list context');
63
64my $day_diff = $localyday - $yday;
65ok( grep({ $day_diff == $_ } (0, 1, -1, 364, 365, -364, -365)),
66 'gmtime() and localtime() agree what day of year');
8d063cd8 67
f5a29b03
RB
68
69# This could be stricter.
26575770
MS
70ok(gmtime() =~ /^(Sun|Mon|Tue|Wed|Thu|Fri|Sat)[ ]
71 (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[ ]
72 ([ \d]\d)\ (\d\d):(\d\d):(\d\d)\ (\d{4})$
73 /x,
74 'gmtime(), scalar context'
75 );