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);
13 my $IsVMS = $^O eq 'VMS';
14 my ($saved_sys_login);
16 $saved_sys_login = $ENV{'SYS$LOGIN'};
19 $ENV{'SYS$LOGIN'} = $saved_sys_login;
22 # Might be a little early in the testing process to start using these,
23 # but I can't think of a way to write this test without them.
24 use File::Spec::Functions qw(:DEFAULT splitdir rel2abs);
26 # Can't use Cwd::abs_path() because it has different ideas about
27 # path separators than File::Spec.
29 $IsVMS ? uc(rel2abs(curdir)) : rel2abs(curdir);
34 # Let's get to a known position
36 skip("Already in t/", 2) if (splitdir(abs_path))[-1] eq ($IsVMS ? 'T' : 't');
38 ok( chdir('t'), 'chdir("t")');
39 is( abs_path, catdir($Cwd, 't'), ' abs_path() agrees' );
44 # The environment variables chdir() pays attention to.
45 my @magic_envs = qw(HOME LOGDIR SYS$LOGIN);
50 # Make sure $ENV{'SYS$LOGIN'} is only honored on VMS.
51 if( $key eq 'SYS$LOGIN' && !$IsVMS ) {
52 ok( !chdir(), "chdir() on $^O ignores only \$ENV{$key} set" );
53 is( abs_path, $Cwd, ' abs_path() did not change' );
54 pass( " no need to test SYS\$LOGIN on $^O" ) for 1..7;
57 ok( chdir(), "chdir() w/ only \$ENV{$key} set" );
58 is( abs_path, $ENV{$key}, ' abs_path() agrees' );
60 is( abs_path, $Cwd, ' and back again' );
63 local $SIG{__WARN__} = sub { $warning .= join '', @_ };
66 # Check the deprecated chdir(undef) feature.
68 ok( chdir(undef), "chdir(undef) w/ only \$ENV{$key} set" );
69 is( abs_path, $ENV{$key}, ' abs_path() agrees' );
70 is( $warning, <<WARNING, ' got uninit & deprecation warning' );
71 Use of uninitialized value in chdir at $0 line 60.
72 Use of chdir('') or chdir(undef) as chdir() is deprecated at $0 line 60.
80 ok( chdir(''), "chdir('') w/ only \$ENV{$key} set" );
81 is( abs_path, $ENV{$key}, ' abs_path() agrees' );
82 is( $warning, <<WARNING, ' got deprecation warning' );
83 Use of chdir('') or chdir(undef) as chdir() is deprecated at $0 line 72.
91 delete $ENV{$_} foreach @magic_envs;
92 # The following means we won't really be testing for non-existence,
93 # but in Perl we can only delete from the process table, not the job
95 $ENV{'SYS$LOGIN'} = '' if $IsVMS;
98 foreach my $key (@magic_envs) {
99 # We're going to be using undefs a lot here.
100 no warnings 'uninitialized';
103 $ENV{$key} = catdir $Cwd, ($IsVMS ? 'OP' : 'op');
111 ok( !chdir(), 'chdir() w/o any ENV set' );
112 is( abs_path, $Cwd, ' abs_path() agrees' );