4 # We're not going to chdir() into 't' because we don't know if
5 # chdir() works! Instead, we'll hedge our bets and put both
6 # possibilities into @INC.
7 @INC = qw(t . lib ../lib);
14 my $IsVMS = $^O eq 'VMS';
16 my ($saved_sys_login);
18 $saved_sys_login = $ENV{'SYS$LOGIN'} if $^O eq 'VMS'
21 $ENV{'SYS$LOGIN'} = $saved_sys_login if $^O eq 'VMS';
24 # Might be a little early in the testing process to start using these,
25 # but I can't think of a way to write this test without them.
26 use File::Spec::Functions qw(:DEFAULT splitdir rel2abs splitpath);
28 # Can't use Cwd::abs_path() because it has different ideas about
29 # path separators than File::Spec.
31 $IsVMS ? uc(rel2abs(curdir)) : rel2abs(curdir);
36 # Let's get to a known position
38 my ($vol,$dir) = splitpath(abs_path,1);
39 skip("Already in t/", 2) if (splitdir($dir))[-1] eq ($IsVMS ? 'T' : 't');
41 ok( chdir('t'), 'chdir("t")');
42 is( abs_path, catdir($Cwd, 't'), ' abs_path() agrees' );
47 # The environment variables chdir() pays attention to.
48 my @magic_envs = qw(HOME LOGDIR SYS$LOGIN);
53 # Make sure $ENV{'SYS$LOGIN'} is only honored on VMS.
54 if( $key eq 'SYS$LOGIN' && !$IsVMS ) {
55 ok( !chdir(), "chdir() on $^O ignores only \$ENV{$key} set" );
56 is( abs_path, $Cwd, ' abs_path() did not change' );
57 pass( " no need to test SYS\$LOGIN on $^O" ) for 1..7;
60 ok( chdir(), "chdir() w/ only \$ENV{$key} set" );
61 is( abs_path, $ENV{$key}, ' abs_path() agrees' );
63 is( abs_path, $Cwd, ' and back again' );
66 local $SIG{__WARN__} = sub { $warning .= join '', @_ };
69 # Check the deprecated chdir(undef) feature.
71 ok( chdir(undef), "chdir(undef) w/ only \$ENV{$key} set" );
72 is( abs_path, $ENV{$key}, ' abs_path() agrees' );
73 is( $warning, <<WARNING, ' got uninit & deprecation warning' );
74 Use of uninitialized value in chdir at $0 line 60.
75 Use of chdir('') or chdir(undef) as chdir() is deprecated at $0 line 60.
83 ok( chdir(''), "chdir('') w/ only \$ENV{$key} set" );
84 is( abs_path, $ENV{$key}, ' abs_path() agrees' );
85 is( $warning, <<WARNING, ' got deprecation warning' );
86 Use of chdir('') or chdir(undef) as chdir() is deprecated at $0 line 72.
94 foreach (@magic_envs) {
95 delete $ENV{$_} unless $IsVMS && $_ eq 'HOME' && !$Config{'d_setenv'};
97 # The following means we won't really be testing for non-existence,
98 # but in Perl we can only delete from the process table, not the job
100 $ENV{'SYS$LOGIN'} = '' if $IsVMS;
103 foreach my $key (@magic_envs) {
104 # We're going to be using undefs a lot here.
105 no warnings 'uninitialized';
108 $ENV{$key} = catdir $Cwd, ($IsVMS ? 'OP' : 'op');
115 if ($IsVMS && !$Config{'d_setenv'}) {
116 pass("Can't reset HOME, so chdir() test meaningless");
118 ok( !chdir(), 'chdir() w/o any ENV set' );
120 is( abs_path, $Cwd, ' abs_path() agrees' );