Make C<undef ~~ 0> and C<undef ~~ ""> not match (like in 5.10.0)
[p5sagit/p5-mst-13.2.git] / t / op / chdir.t
index 5b5ca3f..7fc7665 100644 (file)
@@ -9,11 +9,28 @@ BEGIN {
 
 use Config;
 require "test.pl";
-plan(tests => 41);
+plan(tests => 48);
 
 my $IsVMS   = $^O eq 'VMS';
 my $IsMacOS = $^O eq 'MacOS';
 
+my $vms_unix_rpt = 0;
+my $vms_efs = 0;
+if ($IsVMS) {
+    if (eval 'require VMS::Feature') {
+        $vms_unix_rpt = VMS::Feature::current("filename_unix_report");
+        $vms_efs = VMS::Feature::current("efs_charset");
+    } else {
+        my $unix_rpt = $ENV{'DECC$FILENAME_UNIX_REPORT'} || '';
+        my $efs_charset = $ENV{'DECC$EFS_CHARSET'} || '';
+        $vms_unix_rpt = $unix_rpt =~ /^[ET1]/i; 
+        $vms_efs = $efs_charset =~ /^[ET1]/i; 
+    }
+}
+
+# For an op regression test, I don't want to rely on "use constant" working.
+my $has_fchdir = ($Config{d_fchdir} || "") eq "define";
+
 # Might be a little early in the testing process to start using these,
 # but I can't think of a way to write this test without them.
 use File::Spec::Functions qw(:DEFAULT splitdir rel2abs splitpath);
@@ -22,8 +39,6 @@ use File::Spec::Functions qw(:DEFAULT splitdir rel2abs splitpath);
 # path separators than File::Spec.
 sub abs_path {
     my $d = rel2abs(curdir);
-
-    $d = uc($d) if $IsVMS;
     $d = lc($d) if $^O =~ /^uwin/;
     $d;
 }
@@ -33,8 +48,14 @@ my $Cwd = abs_path;
 # Let's get to a known position
 SKIP: {
     my ($vol,$dir) = splitpath(abs_path,1);
-    my $test_dir = $IsVMS ? 'T' : 't';
-    skip("Already in t/", 2) if (splitdir($dir))[-1] eq $test_dir;
+    my $test_dir = 't';
+    my $compare_dir = (splitdir($dir))[-1];
+
+    # VMS is case insensitive but will preserve case in EFS mode.
+    # So we must normalize the case for the compare.
+    $compare_dir = lc($compare_dir) if $IsVMS;
+    skip("Already in t/", 2) if $compare_dir eq $test_dir;
 
     ok( chdir($test_dir),     'chdir($test_dir)');
     is( abs_path, catdir($Cwd, $test_dir),    '  abs_path() agrees' );
@@ -43,18 +64,19 @@ SKIP: {
 $Cwd = abs_path;
 
 SKIP: {
-    skip("no fchdir", 9) unless ($Config{d_fchdir} || "") eq "define";
+    skip("no fchdir", 16) unless $has_fchdir;
+    my $has_dirfd = ($Config{d_dirfd} || $Config{d_dir_dd_fd} || "") eq "define";
     ok(opendir(my $dh, "."), "opendir .");
     ok(open(my $fh, "<", "op"), "open op");
     ok(chdir($fh), "fchdir op");
     ok(-f "chdir.t", "verify that we are in op");
-    if (($Config{d_dirfd} || "") eq "define") {
+    if ($has_dirfd) {
        ok(chdir($dh), "fchdir back");
     }
     else {
        eval { chdir($dh); };
        like($@, qr/^The dirfd function is unimplemented at/, "dirfd is unimplemented");
-       chdir "..";
+       chdir ".." or die $!;
     }
 
     # same with bareword file handles
@@ -63,19 +85,43 @@ SKIP: {
     *FH = $fh;
     ok(chdir FH, "fchdir op bareword");
     ok(-f "chdir.t", "verify that we are in op");
-    if (($Config{d_dirfd} || "") eq "define") {
+    if ($has_dirfd) {
        ok(chdir DH, "fchdir back bareword");
     }
     else {
        eval { chdir(DH); };
        like($@, qr/^The dirfd function is unimplemented at/, "dirfd is unimplemented");
-       chdir "..";
+       chdir ".." or die $!;
     }
     ok(-d "op", "verify that we are back");
+
+    # And now the ambiguous case
+    {
+       no warnings qw<io deprecated>;
+       ok(opendir(H, "op"), "opendir op") or diag $!;
+       ok(open(H, "<", "base"), "open base") or diag $!;
+    }
+    if ($has_dirfd) {
+       ok(chdir(H), "fchdir to op");
+       ok(-f "chdir.t", "verify that we are in 'op'");
+       chdir ".." or die $!;
+    }
+    else {
+       eval { chdir(H); };
+       like($@, qr/^The dirfd function is unimplemented at/,
+            "dirfd is unimplemented");
+       SKIP: {
+           skip("dirfd is unimplemented");
+       }
+    }
+    ok(closedir(H), "closedir");
+    ok(chdir(H), "fchdir to base");
+    ok(-f "cond.t", "verify that we are in 'base'");
+    chdir ".." or die $!;
 }
 
 SKIP: {
-    skip("has fchdir", 1) if ($Config{d_fchdir} || "") eq "define";
+    skip("has fchdir", 1) if $has_fchdir;
     opendir(my $dh, "op");
     eval { chdir($dh); };
     like($@, qr/^The fchdir function is unimplemented at/, "fchdir is unimplemented");