This adds an ok() function to t/op/time.t and names each test.
I also added a test for the scalar version of localtime.

It also turns this really interesting way to say "grep"

index(" :0:1:-1:364:365:-364:-365:",':' . ($localyday - $yday) . ':') > 0)

into a grep.

Once I sync up Test::More I can do proper skip testing on this instead
of that exit-in-the-middle.


--- t/op/time.t 2001/09/03 10:04:44     1.1
+++ t/op/time.t 2001/09/03 10:19:08
@@ -2,8 +2,27 @@
 
 # $RCSfile: time.t,v $$Revision: 1.1 $$Date: 2001/09/03 10:04:44 $
 
-if ($does_gmtime = gmtime(time)) { print "1..6\n" }
-else { print "1..3\n" }
+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;
+}
+
 
 ($beguser,$begsys) = times;
 
@@ -11,7 +30,7 @@
 
 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;
@@ -20,34 +39,37 @@
     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";}
-
-if (index(" :0:1:-1:364:365:-364:-365:",':' . ($localyday - $yday) . ':') > 0)
-    {print "ok 5\n";}
-else
-    {print "not ok 5\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');
+
 
 # This could be stricter.
-if (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\d\d\d)$/)
-    {print "ok 6\n";}
-else
-    {print "not ok 6\n";}
+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'
+  );

-- 

Michael G. Schwern   <[EMAIL PROTECTED]>    http://www.pobox.com/~schwern/
Perl6 Quality Assurance     <[EMAIL PROTECTED]>       Kwalitee Is Job One
<mendel>         ScHWeRnsChweRN    sChWErN   SchweRN  SCHWErNSChwERnsCHwERN    
  sChWErn  ScHWeRn      schweRn           sCHWErN           schWeRn    scHWeRN 
   SchWeRN      scHWErn SchwErn       scHWErn       ScHweRN       sChwern      
scHWerN        scHWeRn           scHWerN        ScHwerN       SChWeRN scHWeRn  
        SchwERNschwERn        SCHwern  sCHWErN   SCHWErN           sChWeRn 

Reply via email to