develooper Front page | perl.perl5.porters | Postings from September 2001

[PATCH perl@12258] chdir.t finally (I hope)

Thread Next
From:
Craig A. Berry
Date:
September 29, 2001 07:38
Subject:
[PATCH perl@12258] chdir.t finally (I hope)
Message ID:
a05101000b7db8afde231@[172.16.52.1]
Based on suggestions from Michael Schwern, the patch below finally 
gets the test to pass on VMS.  If I still have the test count wrong 
for other platforms, please change the "no need to test SYS\$LOGIN " 
line rather than the plan at the top.

--- t/op/chdir.t;-0     Fri Sep 28 08:40:18 2001
+++ t/op/chdir.t        Sat Sep 29 09:28:53 2001
@@ -8,16 +8,23 @@
 }
 
 require "test.pl";
-plan(tests => 25);
+plan(tests => 31);
 
 my $IsVMS = $^O eq 'VMS';
+my ($saved_sys_login);
+BEGIN {
+    $saved_sys_login = $ENV{'SYS$LOGIN'};
+}
+END {
+    $ENV{'SYS$LOGIN'} = $saved_sys_login;
+}
 
 # 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);
 
 # Can't use Cwd::abs_path() because it has different ideas about
-# path seperators than File::Spec.
+# path separators than File::Spec.
 sub abs_path {
     $IsVMS ? uc(rel2abs(curdir)) : rel2abs(curdir);
 }
@@ -44,7 +51,7 @@
     if( $key eq 'SYS$LOGIN' && !$IsVMS ) {
         ok( !chdir(),         "chdir() on $^O ignores only \$ENV{$key} set" );
         is( abs_path, $Cwd,   '  abs_path() did not change' );
-        pass( "  no need to chdir back on $^O" );
+        pass( "  no need to test SYS\$LOGIN on $^O" ) for 1..7;
     }
     else {
         ok( chdir(),              "chdir() w/ only \$ENV{$key} set" );
@@ -80,18 +87,26 @@
     }
 }
 
+sub clean_env {
+    delete $ENV{$_} foreach @magic_envs;
+    # The following means we won't really be testing for non-existence,
+    # but in Perl we can only delete from the process table, not the job 
+    # table.
+    $ENV{'SYS$LOGIN'} = '' if $IsVMS;
+}
+
 foreach my $key (@magic_envs) {
     # We're going to be using undefs a lot here.
     no warnings 'uninitialized';
 
-    local %ENV = () if !$IsVMS;
+    clean_env;
     $ENV{$key} = catdir $Cwd, ($IsVMS ? 'OP' : 'op');
     
     check_env($key);
 }
 
 {
-    local %ENV = () if !$IsVMS;
+    clean_env;
 
     ok( !chdir(),                   'chdir() w/o any ENV set' );
     is( abs_path, $Cwd,             '  abs_path() agrees' );


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About