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 => 25;
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 # Make sure $ENV{'SYS$LOGIN'} is only honored on VMS.
39 if( $key eq 'SYS$LOGIN' && $^O ne 'VMS' ) {
40 ok( !chdir(), "chdir() on $^O ignores only \$ENV{$key} set" );
41 is( abs_path, $cwd, ' abs_path() did not change' );
42 ok( 1, " no need to chdir back on $^O" );
45 ok( chdir(), "chdir() w/ only \$ENV{$key} set" );
46 is( abs_path, $ENV{$key}, ' abs_path() agrees' );
48 is( abs_path, $cwd, ' and back again' );
51 # Bug had chdir(undef) being the same as chdir()
52 ok( !chdir(undef), "chdir(undef) w/ only \$ENV{$key} set" );
53 is( abs_path, $cwd, ' abs_path() agrees' );
56 ok( !chdir(''), "chdir('') w/ only \$ENV{$key} set" );
57 is( abs_path, $cwd, ' abs_path() agrees' );
61 # We're going to be using undefs a lot here.
62 no warnings 'uninitialized';
64 # Unset all the environment variables chdir() pay attention to.
65 local @ENV{@magic_envs} = (undef) x @magic_envs;
67 ok( !chdir(), 'chdir() w/o any ENV set' );
68 is( abs_path, $cwd, ' abs_path() agrees' );