Ticket #1268: time_t.patch

File time_t.patch, 5.1 KB (added by bubaflub, 12 years ago)

patch for t/op/time.t

  • t/op/time.t

    diff --git t/op/time.t t/op/time.t
    index 0547900..3a05b97 100644
     
    1 #!perl 
     1#!parrot 
    22# Copyright (C) 2001-2009, Parrot Foundation. 
    33# $Id$ 
    44 
    5 use strict; 
    6 use warnings; 
    7 use lib qw( . lib ../lib ../../lib ); 
    8 use Test::More; 
    9 use Parrot::Test tests => 7; 
    10  
    115=head1 NAME 
    126 
    137t/op/time.t - Time and Sleep 
     
    2216 
    2317=cut 
    2418 
    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 
    47  
    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 
     19.sub main :main 
     20    .include 'test_more.pir' 
     21    plan(10) 
     22 
     23    test_time_i_1() 
     24    test_time_i_2() 
     25    test_time_n_1() 
     26    test_time_n_2() 
     27    test_sleep_1() 
     28    test_sleep_2() 
     29    test_decodelocaltime() 
     30    test_gmtime_string_length() 
     31    test_time_float_vs_time_int() 
     32.end 
     33 
     34.sub test_time_i_1 
     35    time    $I0 
     36    time    $I1 
     37    ge      $I0, 0, OK 
     38    branch  FAIL 
     39  OK: 
     40    ok(1, "(!= 1970) Grateful Dead not") 
     41    .return() 
     42  FAIL: 
     43    ok(0, "failure: current time is 0 (and it is not 1970)") 
     44.end 
     45 
     46.sub test_time_i_2 
     47    time    $I0 
     48    time    $I1 
     49    ge      $I1, $I0, OK 
     50    branch FAIL 
     51  OK: 
     52    ok(1, "(now>before) timelords need not apply") 
     53    .return() 
     54  FAIL: 
     55    ok(0, "failure: now < before. wait, how is that possible?") 
     56.end 
     57 
     58.sub test_time_n_1 
     59    time    $N0 
     60    time    $N1 
     61    ge      $N0, 0.0, OK 
     62    branch  FAIL 
     63  OK:     
     64    ok(1, "(!= 1970) Grateful Dead not") 
     65    .return() 
     66  FAIL: 
     67    ok(0, "failure: current time is 0 (and it is not 1970)") 
     68.end 
     69 
     70.sub test_time_n_2 
     71    time    $N0 
     72    time    $N1 
     73    ge      $N1, $N0, OK 
     74    branch FAIL 
     75  OK: 
     76    ok(1, "(now>before) timelords need not apply") 
     77    .return() 
     78  FAIL: 
     79    ok(0, "failure: now < before. wait, how is that possible?") 
     80.end 
    6581 
    66 pasm_output_is( <<CODE, <<OUTPUT, "sleep" ); 
    67         print   "start\\n" 
     82.sub test_sleep_1 
    6883 
    69         time    I1 
     84    time    $I1 
    7085 
    71         sleep   1 
    72         set     I0, 1 
    73         sleep   I0 
     86    sleep   1 
     87    set     $I0, 1 
     88    sleep   $I0 
    7489 
    75         time    I0 
     90    time    $I0 
    7691 
    77         gt      I0, I1, ALLOK 
    78         print   "no, sleeping made time go the wrong way " 
     92    gt      $I0, $I1, ALLOK 
     93    ok(0, "no, sleeping made time go the wrong way") 
    7994 
    8095ALLOK: 
    81         print   "done\\n" 
    82         end 
    83 CODE 
    84 start 
    85 done 
    86 OUTPUT 
     96    ok(1, "sleep works") 
     97.end 
    8798 
    88 pasm_error_output_like( <<CODE, <<OUT , "sleep" ); 
    89         sleep   -1 
    90         end 
    91 CODE 
    92 /Cannot go back in time/ 
    93 OUT 
    94  
    95 my $year; 
    96 ( undef, undef, undef, undef, undef, $year ) = localtime(); 
    97 $year += 1900; 
    98  
    99 # don't run this test 1 tick before the year changes #' 
    100  
    101 pasm_output_is( <<'CODE', $year, "decodelocaltime" ); 
    102     time I0 
    103     decodelocaltime P0, I0 
    104     .include "tm.pasm" 
    105     set I0, P0[.TM_YEAR] 
    106     print I0 
    107     end 
     99.sub test_sleep_2 
     100    dies_ok( <<'CODE', 'should not be able to go back in time') 
     101.sub main 
     102    sleep   -1 
     103.end 
    108104CODE 
     105.end 
    109106 
    110 pir_output_is(<<'CODE', "Tue Jan  1 00:00:00 2008\n25", "gmtime string length"); 
    111 .sub _ :main 
    112 $I0 = 1199145600 
    113 $S0 = gmtime $I0 
    114 print $S0 
    115 $I1 = length $S0 
    116 print $I1 
     107.sub test_decodelocaltime 
     108    $I0 = 1258153536 
     109    decodelocaltime $P0, $I0 
     110    .include 'tm.pasm' 
     111    set $I0, $P0[.TM_YEAR] 
     112    is($I0, 2009, 'decodelocaltime') 
    117113.end 
    118 CODE 
    119114 
    120 pir_output_is(<<'CODE', <<OUTPUT, "time(FLOATVAL) vs time(INTVAL)"); 
    121 .sub main :main 
     115.sub test_gmtime_string_length 
     116    $I0 = 1199145600 
     117    $S0 = gmtime $I0 
     118    is($S0, "Tue Jan  1 00:00:00 2008\n", 'gmtime string') 
     119    $I1 = length $S0 
     120    is($I1, 25, 'gmtime length') 
     121.end 
     122 
     123.sub test_time_float_vs_time_int 
    122124    .local int time_int 
    123125    time time_int 
    124126 
     
    133135    time_int_upper = time_int + 5 
    134136    if time_float > time_int_upper goto FAIL 
    135137 
    136     print "ok\n" 
    137     goto END 
     138    ok(1, "time_float is within [time_int - 5; time_int + 5]") 
     139    .return() 
     140  FAIL: 
     141    ok(0, "time_float is within [time_int - 5; time_int + 5]") 
    138142 
    139 FAIL: print "not ok\n" 
    140     goto END 
    141  
    142 END: 
    143143.end 
    144 CODE 
    145 ok 
    146 OUTPUT 
    147  
    148144 
    149145# Local Variables: 
    150146#   mode: cperl 
    151147#   cperl-indent-level: 4 
    152148#   fill-column: 100 
    153149# End: 
    154 # vim: expandtab shiftwidth=4: 
     150# vim: expandtab shiftwidth=4 filetype=pir: