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 = ('lib', '../lib');
9 # Might be a little early in the testing process to start using these,
10 # but I can't think of a way to write this test without them.
11 use Cwd qw(abs_path cwd);
12 use File::Spec::Functions qw(:DEFAULT splitdir);
14 use Test::More tests => 24;
18 # Let's get to a known position
20 skip("Already in t/", 2) if (splitdir(abs_path))[-1] eq 't';
22 ok( chdir('t'), 'chdir("t")');
23 is( abs_path, catdir($cwd, 't'), ' abs_path() agrees' );
28 # The environment variables chdir() pays attention to.
29 my @magic_envs = qw(HOME LOGDIR SYS$LOGIN);
31 foreach my $key (@magic_envs) {
32 # We're going to be using undefs a lot here.
33 no warnings 'uninitialized';
35 delete @ENV{@magic_envs};
36 local $ENV{$key} = catdir $cwd, 'op';
38 if( $key eq 'SYS$LOGIN' && $^O ne 'VMS' ) {
39 # Make sure $ENV{'SYS$LOGIN'} is only honored on VMS.
40 ok( !chdir(), "chdir() w/\$ENV{$key} set" );
41 is( abs_path, $cwd, ' abs_path() agrees' );
44 ok( chdir(), "chdir() w/\$ENV{$key} set" );
45 is( abs_path, $ENV{$key}, ' abs_path() agrees' );
47 is( abs_path, $cwd, ' and back again' );
50 # Bug had chdir(undef) being the same as chdir()
51 ok( !chdir(undef), "chdir(undef) w/\$ENV{$key} set" );
52 is( abs_path, $cwd, ' abs_path() agrees' );
55 ok( !chdir(''), "chdir('') w/\$ENV{$key} set" );
56 is( abs_path, $cwd, ' abs_path() agrees' );
60 # We're going to be using undefs a lot here.
61 no warnings 'uninitialized';
63 # Unset all the environment variables chdir() pay attention to.
64 local @ENV{@magic_envs} = (undef) x @magic_envs;
66 ok( !chdir(), 'chdir() w/o any ENV set' );
67 is( abs_path, $cwd, ' abs_path() agrees' );