tagged release 0.6.4
[parrot.git] / t / op / time.t
blobeb5a1ace8222e25d20d67d212b7e075cb04afc8d
1 #!perl
2 # Copyright (C) 2001-2007, The Perl Foundation.
3 # $Id$
5 use strict;
6 use warnings;
7 use lib qw( . lib ../lib ../../lib );
8 use Test::More;
9 use Parrot::Test tests => 6;
11 =head1 NAME
13 t/op/time.t - Time and Sleep
15 =head1 SYNOPSIS
17         % prove t/op/time.t
19 =head1 DESCRIPTION
21 Tests the C<time> and C<sleep> operations.
23 =cut
25 pasm_output_is( <<'CODE', <<'OUTPUT', "time_i" );
26         time    I0
27         time    I1
28         ge      I0, 0, OK1
29         branch  FAIL
30 OK1:    print "ok, (!= 1970) Grateful Dead not\n"
31         ge      I1, I0, OK2
32         branch FAIL
33 OK2:    print "ok, (now>before) timelords need not apply\n"
34         branch  OK_ALL
35 FAIL:   print "failure\n"
36         print "I0 was: "
37         print I0
38         print "\nI1 was: "
39         print I0
40         print "\n"
41 OK_ALL:
42         end
43 CODE
44 ok, (!= 1970) Grateful Dead not
45 ok, (now>before) timelords need not apply
46 OUTPUT
48 pasm_output_is( <<'CODE', <<'OUTPUT', "time_n" );
49         time    N0
50         time    N1
51         ge      N0, 0.0, OK1
52         branch  FAIL
53 OK1:    print "ok, (!= 1970) Grateful Dead not\n"
54         ge      N1, N0, OK2
55         branch FAIL
56 OK2:    print "ok, (now>before) timelords need not apply\n"
57         branch  OK_ALL
58 FAIL:   print "failure\n"
59 OK_ALL:
60         end
61 CODE
62 ok, (!= 1970) Grateful Dead not
63 ok, (now>before) timelords need not apply
64 OUTPUT
66 SKIP: {
67     skip 'failling on win32' => 1 if $^O =~ m/win32/i;
69 pasm_output_is( <<CODE, <<OUTPUT, "sleep" );
70         print   "start\\n"
72         time    I1
74         sleep   1
75         set     I0, 1
76         sleep   I0
78         time    I0
80         gt      I0, I1, ALLOK
81         print   "no, sleeping made time go the wrong way "
83 ALLOK:
84         print   "done\\n"
85         end
86 CODE
87 start
88 done
89 OUTPUT
93 pasm_error_output_like( <<CODE, <<OUT , "sleep" );
94         sleep   -1
95         end
96 CODE
97 /Cannot go back in time/
98 OUT
100 my $year;
101 ( undef, undef, undef, undef, undef, $year ) = gmtime(time);
102 $year += 1900;
104 # don't run this test 1 tick before the year changes #'
106 pasm_output_is( <<'CODE', $year, "decodelocaltime" );
107     time I0
108     decodelocaltime P0, I0
109     .include "tm.pasm"
110     set I0, P0[.TM_YEAR]
111     print I0
112     end
113 CODE
115 pir_output_is(<<'CODE', "Tue Jan  1 00:00:00 2008\n25", "gmtime string length");
116 .sub _ :main
117 $I0 = 1199145600
118 $S0 = gmtime $I0
119 print $S0
120 $I1 = length $S0
121 print $I1
122 .end
123 CODE
125 # Local Variables:
126 #   mode: cperl
127 #   cperl-indent-level: 4
128 #   fill-column: 100
129 # End:
130 # vim: expandtab shiftwidth=4: