Commit | Line | Data |
35ae6b54 |
1 | #!./perl -w |
2 | |
8ea155d1 |
3 | BEGIN { |
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. |
69026470 |
7 | @INC = qw(t . lib ../lib); |
8ea155d1 |
8 | } |
9 | |
69026470 |
10 | require "test.pl"; |
11 | plan(tests => 25); |
8ea155d1 |
12 | |
35ae6b54 |
13 | my $IsVMS = $^O eq 'VMS'; |
14 | |
8ea155d1 |
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. |
d9c93211 |
17 | use File::Spec::Functions qw(:DEFAULT splitdir rel2abs); |
18 | |
19 | # Can't use Cwd::abs_path() because it has different ideas about |
20 | # path seperators than File::Spec. |
21 | sub abs_path { |
22 | rel2abs(curdir); |
23 | } |
8ea155d1 |
24 | |
35ae6b54 |
25 | my $Cwd = abs_path; |
8ea155d1 |
26 | |
27 | # Let's get to a known position |
28 | SKIP: { |
29 | skip("Already in t/", 2) if (splitdir(abs_path))[-1] eq 't'; |
30 | |
31 | ok( chdir('t'), 'chdir("t")'); |
35ae6b54 |
32 | is( abs_path, catdir($Cwd, 't'), ' abs_path() agrees' ); |
8ea155d1 |
33 | } |
34 | |
35ae6b54 |
35 | $Cwd = abs_path; |
8ea155d1 |
36 | |
37 | # The environment variables chdir() pays attention to. |
38 | my @magic_envs = qw(HOME LOGDIR SYS$LOGIN); |
39 | |
35ae6b54 |
40 | sub check_env { |
41 | my($key) = @_; |
8ea155d1 |
42 | |
89eee1ed |
43 | # Make sure $ENV{'SYS$LOGIN'} is only honored on VMS. |
35ae6b54 |
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" ); |
8ea155d1 |
48 | } |
49 | else { |
89eee1ed |
50 | ok( chdir(), "chdir() w/ only \$ENV{$key} set" ); |
8ea155d1 |
51 | is( abs_path, $ENV{$key}, ' abs_path() agrees' ); |
35ae6b54 |
52 | chdir($Cwd); |
53 | is( abs_path, $Cwd, ' and back again' ); |
54 | |
55 | my $warning = ''; |
56 | local $SIG{__WARN__} = sub { $warning .= join '', @_ }; |
57 | |
8ea155d1 |
58 | |
35ae6b54 |
59 | # Check the deprecated chdir(undef) feature. |
60 | #line 60 |
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. |
66 | WARNING |
8ea155d1 |
67 | |
35ae6b54 |
68 | chdir($Cwd); |
69 | |
70 | # Ditto chdir(''). |
71 | $warning = ''; |
72 | #line 72 |
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. |
77 | WARNING |
78 | |
79 | chdir($Cwd); |
80 | } |
8ea155d1 |
81 | } |
82 | |
35ae6b54 |
83 | foreach my $key (@magic_envs) { |
8ea155d1 |
84 | # We're going to be using undefs a lot here. |
85 | no warnings 'uninitialized'; |
86 | |
35ae6b54 |
87 | local %ENV = (); |
88 | $ENV{$key} = catdir $Cwd, 'op'; |
89 | |
90 | check_env($key); |
91 | } |
92 | |
93 | { |
94 | local %ENV = (); |
8ea155d1 |
95 | |
96 | ok( !chdir(), 'chdir() w/o any ENV set' ); |
35ae6b54 |
97 | is( abs_path, $Cwd, ' abs_path() agrees' ); |
8ea155d1 |
98 | } |