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';
15 # Might be a little early in the testing process to start using these,
16 # but I can't think of a way to write this test without them.
17 use File::Spec::Functions qw(:DEFAULT splitdir rel2abs);
19 # Can't use Cwd::abs_path() because it has different ideas about
20 # path seperators than File::Spec.
22 $IsVMS ? uc(rel2abs(curdir)) : rel2abs(curdir);
27 # Let's get to a known position
29 skip("Already in t/", 2) if (splitdir(abs_path))[-1] eq ($IsVMS ? 'T' : 't');
31 ok( chdir('t'), 'chdir("t")');
32 is( abs_path, catdir($Cwd, 't'), ' abs_path() agrees' );
37 # The environment variables chdir() pays attention to.
38 my @magic_envs = qw(HOME LOGDIR SYS$LOGIN);
43 # Make sure $ENV{'SYS$LOGIN'} is only honored on VMS.
44 if( $key eq 'SYS$LOGIN' && !$IsVMS ) {
45 ok( !chdir(), "chdir() on $^O ignores only \$ENV{$key} set" );
46 is( abs_path, $Cwd, ' abs_path() did not change' );
47 pass( " no need to chdir back on $^O" );
50 ok( chdir(), "chdir() w/ only \$ENV{$key} set" );
51 is( abs_path, $ENV{$key}, ' abs_path() agrees' );
53 is( abs_path, $Cwd, ' and back again' );
56 local $SIG{__WARN__} = sub { $warning .= join '', @_ };
59 # Check the deprecated chdir(undef) feature.
61 ok( chdir(undef), "chdir(undef) w/ only \$ENV{$key} set" );
62 is( abs_path, $ENV{$key}, ' abs_path() agrees' );
63 is( $warning, <<WARNING, ' got uninit & deprecation warning' );
64 Use of uninitialized value in chdir at $0 line 60.
65 Use of chdir('') or chdir(undef) as chdir() is deprecated at $0 line 60.
73 ok( chdir(''), "chdir('') w/ only \$ENV{$key} set" );
74 is( abs_path, $ENV{$key}, ' abs_path() agrees' );
75 is( $warning, <<WARNING, ' got deprecation warning' );
76 Use of chdir('') or chdir(undef) as chdir() is deprecated at $0 line 72.
83 foreach my $key (@magic_envs) {
84 # We're going to be using undefs a lot here.
85 no warnings 'uninitialized';
87 local %ENV = () if !$IsVMS;
88 $ENV{$key} = catdir $Cwd, ($IsVMS ? 'OP' : 'op');
94 local %ENV = () if !$IsVMS;
96 ok( !chdir(), 'chdir() w/o any ENV set' );
97 is( abs_path, $Cwd, ' abs_path() agrees' );