This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Integrate:
authorNicholas Clark <nick@ccl4.org>
Sat, 10 Feb 2007 13:00:46 +0000 (13:00 +0000)
committerNicholas Clark <nick@ccl4.org>
Sat, 10 Feb 2007 13:00:46 +0000 (13:00 +0000)
[ 26206]
Additional tests for B and POSIX.  The POSIX ones concern me a bit,
but I don't expect any black smokes because of testing on OpenBSD,
Linux, Win32, an Cygwin.

[ 26207]
Hmmm...strftime() does work on Win32, but tzset() is having problems
on OpenBSD.

[ 26208]
Just be explicit about $TZ.

[ 26213]
Deal with differences in what clock() does between POSIX and BSD.

[ 26221]
Mac OS X/Darwin seems to have problems with tzname().

[ 26222]
Fix ext/POSIX/t/time.t on Win32

According to MSDN, "The string result produced by ctime contains
exactly 26 characters and has the form: Wed Jan 02 02:03:55 1980\n\0"
so we *do* want the leading zero on the day returned by strftime

[ 26384]
Fix for ext/POSIX/t/time.t so the strftime() test works on systems
that aren't quite up to SUS3.  Based on a patch by David Dyck in
RT #37960: POSIX/t/time fails bleadperl

[ 26424]
Fix typos in regular expressions
p4raw-link: @26424 on //depot/perl: 0bcc798661c94fefec5a89ff3321c5a519313444
p4raw-link: @26384 on //depot/perl: 018eeb1214fceb5fc2491b2c0cf4420b79b385ad
p4raw-link: @26222 on //depot/perl: 0be3c6f7a4944de19c9556f549685e4972fa6fdd
p4raw-link: @26221 on //depot/perl: 6f3614c8320db76979938c6971fe23038d034f76
p4raw-link: @26213 on //depot/perl: 439787adcd53f9bf3c626f16cfde7d00fa72ed23
p4raw-link: @26208 on //depot/perl: 31b629d65d5e0d901333fb112fa2c268291e631f
p4raw-link: @26207 on //depot/perl: 34dd738f0e7d53b99c5f6225cfd5603222c0660a
p4raw-link: @26206 on //depot/perl: 2da668d2d17f61b6470fb3f362b4703ae4b6e6e1

p4raw-id: //depot/maint-5.8/perl@30189
p4raw-branched: from //depot/perl@30187 'branch in' ext/POSIX/t/time.t
(@26384..)
p4raw-integrated: from //depot/perl@26206 'copy in' ext/B/t/b.t
(@23691..) 'merge in' MANIFEST (@26200..)

MANIFEST
ext/B/t/b.t
ext/POSIX/t/time.t [new file with mode: 0644]

index 7fe51a5..610668c 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -793,6 +793,7 @@ ext/POSIX/t/is.t            See if POSIX isxxx() work
 ext/POSIX/t/posix.t            See if POSIX works
 ext/POSIX/t/sigaction.t                See if POSIX::sigaction works
 ext/POSIX/t/taint.t            See if POSIX works with taint
+ext/POSIX/t/time.t             See if POSIX time-related functions work
 ext/POSIX/t/waitpid.t          See if waitpid works
 ext/POSIX/typemap              POSIX extension interface types
 ext/re/hints/mpeix.pl          Hints for re for named architecture
index 70f4f59..4337109 100755 (executable)
@@ -22,7 +22,7 @@ BEGIN {
 $|  = 1;
 use warnings;
 use strict;
-use Test::More tests => 41;
+use Test::More tests => 53;
 
 BEGIN { use_ok( 'B' ); }
 
@@ -147,3 +147,19 @@ ok(! $gv_ref->is_empty(), "Test is_empty()");
 is($gv_ref->NAME(), "gv", "Test NAME()");
 is($gv_ref->SAFENAME(), "gv", "Test SAFENAME()");
 like($gv_ref->FILE(), qr/b\.t$/, "Testing FILE()");
+
+# The following return B::SPECIALs.
+is(ref B::sv_yes(), "B::SPECIAL", "B::sv_yes()");
+is(ref B::sv_no(), "B::SPECIAL", "B::sv_no()");
+is(ref B::sv_undef(), "B::SPECIAL", "B::sv_undef()");
+
+# More utility functions
+is(B::ppname(0), "pp_null", "Testing ppname (this might break if opnames.h is changed)");
+is(B::opnumber("null"), 0, "Testing opnumber with opname (null)");
+is(B::opnumber("pp_null"), 0, "Testing opnumber with opname (pp_null)");
+like(B::hash("wibble"), qr/0x[0-9a-f]*/, "Testing B::hash()");
+is(B::cstring("wibble"), '"wibble"', "Testing B::cstring()");
+is(B::perlstring("wibble"), '"wibble"', "Testing B::perlstring()");
+is(B::class(bless {}, "Wibble::Bibble"), "Bibble", "Testing B::class()");
+is(B::cast_I32(3.14), 3, "Testing B::cast_I32()");
+is(B::opnumber("localtime"), 294);
diff --git a/ext/POSIX/t/time.t b/ext/POSIX/t/time.t
new file mode 100644 (file)
index 0000000..103a161
--- /dev/null
@@ -0,0 +1,59 @@
+#!perl -w
+
+use strict;
+
+use Config;
+use POSIX;
+use Test::More tests => 9;
+
+# go to UTC to avoid DST issues around the world when testing.  SUS3 says that
+# null should get you UTC, but some environments want the explicit names.
+# Those with a working tzset() should be able to use the TZ below.
+$ENV{TZ} = "UTC0UTC";
+
+SKIP: {
+    # It looks like POSIX.xs claims that only VMS and Mac OS traditional
+    # don't have tzset().  Win32 works to call the function, but it doesn't
+    # actually do anything.  Cygwin works in some places, but not others.  The
+    # other Win32's below are guesses.
+    skip "No tzset()", 2
+       if $^O eq "MacOS" || $^O eq "VMS" || $^O eq "cygwin" || $^O eq "djgpp" ||
+          $^O eq "MSWin32" || $^O eq "dos" || $^O eq "interix";
+    tzset();
+    my @tzname = tzname();
+    like($tzname[0], qr/(GMT|UTC)/i, "tzset() to GMT/UTC");
+    SKIP: {
+        skip "Mac OS X/Darwin doesn't handle this", 1 if $^O =~ /darwin/i;
+        like($tzname[1], qr/(GMT|UTC)/i, "The whole year?");
+    }
+}
+
+# asctime and ctime...Let's stay below INT_MAX for 32-bits and
+# positive for some picky systems.
+
+is(asctime(localtime(0)), ctime(0), "asctime() and ctime() at zero");
+is(asctime(localtime(12345678)), ctime(12345678), "asctime() and ctime() at 12345678");
+
+# Careful!  strftime() is locale sensative.  Let's take care of that
+my $orig_loc = setlocale(LC_TIME, "C") || die "Cannot setlocale() to C:  $!";
+my $jan_16 = 15 * 86400;
+is(ctime($jan_16), strftime("%a %b %d %H:%M:%S %Y\n", localtime($jan_16)),
+        "get ctime() equal to strftime()");
+setlocale(LC_TIME, $orig_loc) || die "Cannot setlocale() back to orig: $!";
+
+# clock() seems to have different definitions of what it does between POSIX
+# and BSD.  Cygwin, Win32, and Linux lean the BSD way.  So, the tests just
+# check the basics.
+like(clock(), qr/\d*/, "clock() returns a numeric value");
+ok(clock() >= 0, "...and it returns something >= 0");
+
+SKIP: {
+    skip "No difftime()", 1 if $Config{d_difftime} ne 'define';
+    is(difftime(2, 1), 1, "difftime()");
+}
+
+SKIP: {
+    skip "No mktime()", 1 if $Config{d_mktime} ne 'define';
+    my $time = time();
+    is(mktime(localtime($time)), $time, "mktime()");
+}