Commit | Line | Data |
8ea155d1 |
1 | BEGIN { |
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'); |
6 | } |
7 | |
8 | |
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); |
13 | |
14 | use Test::More tests => 24; |
15 | |
16 | my $cwd = abs_path; |
17 | |
18 | # Let's get to a known position |
19 | SKIP: { |
20 | skip("Already in t/", 2) if (splitdir(abs_path))[-1] eq 't'; |
21 | |
22 | ok( chdir('t'), 'chdir("t")'); |
23 | is( abs_path, catdir($cwd, 't'), ' abs_path() agrees' ); |
24 | } |
25 | |
26 | $cwd = abs_path; |
27 | |
28 | # The environment variables chdir() pays attention to. |
29 | my @magic_envs = qw(HOME LOGDIR SYS$LOGIN); |
30 | |
31 | foreach my $key (@magic_envs) { |
32 | # We're going to be using undefs a lot here. |
33 | no warnings 'uninitialized'; |
34 | |
35 | delete @ENV{@magic_envs}; |
36 | local $ENV{$key} = catdir $cwd, 'op'; |
37 | |
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' ); |
42 | } |
43 | else { |
44 | ok( chdir(), "chdir() w/\$ENV{$key} set" ); |
45 | is( abs_path, $ENV{$key}, ' abs_path() agrees' ); |
46 | chdir($cwd); |
47 | is( abs_path, $cwd, ' and back again' ); |
48 | } |
49 | |
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' ); |
53 | |
54 | # Ditto chdir(''). |
55 | ok( !chdir(''), "chdir('') w/\$ENV{$key} set" ); |
56 | is( abs_path, $cwd, ' abs_path() agrees' ); |
57 | } |
58 | |
59 | { |
60 | # We're going to be using undefs a lot here. |
61 | no warnings 'uninitialized'; |
62 | |
63 | # Unset all the environment variables chdir() pay attention to. |
64 | local @ENV{@magic_envs} = (undef) x @magic_envs; |
65 | |
66 | ok( !chdir(), 'chdir() w/o any ENV set' ); |
67 | is( abs_path, $cwd, ' abs_path() agrees' ); |
68 | } |