2 # We're not going to chdir() into 't' because we don't know if
3 # chdir() works! Instead, we'll hedge our bets and put both
4 # possibilities into @INC.
5 @INC = qw(t . lib ../lib);
11 # Might be a little early in the testing process to start using these,
12 # but I can't think of a way to write this test without them.
13 use File::Spec::Functions qw(:DEFAULT splitdir rel2abs);
15 # Can't use Cwd::abs_path() because it has different ideas about
16 # path seperators than File::Spec.
23 # Let's get to a known position
25 skip("Already in t/", 2) if (splitdir(abs_path))[-1] eq 't';
27 ok( chdir('t'), 'chdir("t")');
28 is( abs_path, catdir($cwd, 't'), ' abs_path() agrees' );
33 # The environment variables chdir() pays attention to.
34 my @magic_envs = qw(HOME LOGDIR SYS$LOGIN);
36 foreach my $key (@magic_envs) {
37 # We're going to be using undefs a lot here.
38 no warnings 'uninitialized';
40 delete @ENV{@magic_envs};
41 local $ENV{$key} = catdir $cwd, 'op';
43 # Make sure $ENV{'SYS$LOGIN'} is only honored on VMS.
44 if( $key eq 'SYS$LOGIN' && $^O ne 'VMS' ) {
45 ok( !chdir(), "chdir() on $^O ignores only \$ENV{$key} set" );
46 is( abs_path, $cwd, ' abs_path() did not change' );
47 ok( 1, " 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 # Bug had chdir(undef) being the same as chdir()
57 ok( !chdir(undef), "chdir(undef) w/ only \$ENV{$key} set" );
58 is( abs_path, $cwd, ' abs_path() agrees' );
61 ok( !chdir(''), "chdir('') w/ only \$ENV{$key} set" );
62 is( abs_path, $cwd, ' abs_path() agrees' );
66 # We're going to be using undefs a lot here.
67 no warnings 'uninitialized';
69 # Unset all the environment variables chdir() pay attention to.
70 local @ENV{@magic_envs} = (undef) x @magic_envs;
72 ok( !chdir(), 'chdir() w/o any ENV set' );
73 is( abs_path, $cwd, ' abs_path() agrees' );