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"; |
d6cdadd4 |
11 | plan(tests => 31); |
8ea155d1 |
12 | |
35ae6b54 |
13 | my $IsVMS = $^O eq 'VMS'; |
2d6b1654 |
14 | |
d6cdadd4 |
15 | my ($saved_sys_login); |
16 | BEGIN { |
2d6b1654 |
17 | $saved_sys_login = $ENV{'SYS$LOGIN'} if $^O eq 'VMS' |
d6cdadd4 |
18 | } |
19 | END { |
2d6b1654 |
20 | $ENV{'SYS$LOGIN'} = $saved_sys_login if $^O eq 'VMS'; |
d6cdadd4 |
21 | } |
35ae6b54 |
22 | |
8ea155d1 |
23 | # Might be a little early in the testing process to start using these, |
24 | # but I can't think of a way to write this test without them. |
d9c93211 |
25 | use File::Spec::Functions qw(:DEFAULT splitdir rel2abs); |
26 | |
27 | # Can't use Cwd::abs_path() because it has different ideas about |
d6cdadd4 |
28 | # path separators than File::Spec. |
d9c93211 |
29 | sub abs_path { |
9d4c144b |
30 | $IsVMS ? uc(rel2abs(curdir)) : rel2abs(curdir); |
d9c93211 |
31 | } |
8ea155d1 |
32 | |
35ae6b54 |
33 | my $Cwd = abs_path; |
8ea155d1 |
34 | |
35 | # Let's get to a known position |
36 | SKIP: { |
9d4c144b |
37 | skip("Already in t/", 2) if (splitdir(abs_path))[-1] eq ($IsVMS ? 'T' : 't'); |
8ea155d1 |
38 | |
39 | ok( chdir('t'), 'chdir("t")'); |
35ae6b54 |
40 | is( abs_path, catdir($Cwd, 't'), ' abs_path() agrees' ); |
8ea155d1 |
41 | } |
42 | |
35ae6b54 |
43 | $Cwd = abs_path; |
8ea155d1 |
44 | |
45 | # The environment variables chdir() pays attention to. |
46 | my @magic_envs = qw(HOME LOGDIR SYS$LOGIN); |
47 | |
35ae6b54 |
48 | sub check_env { |
49 | my($key) = @_; |
8ea155d1 |
50 | |
89eee1ed |
51 | # Make sure $ENV{'SYS$LOGIN'} is only honored on VMS. |
35ae6b54 |
52 | if( $key eq 'SYS$LOGIN' && !$IsVMS ) { |
53 | ok( !chdir(), "chdir() on $^O ignores only \$ENV{$key} set" ); |
54 | is( abs_path, $Cwd, ' abs_path() did not change' ); |
d6cdadd4 |
55 | pass( " no need to test SYS\$LOGIN on $^O" ) for 1..7; |
8ea155d1 |
56 | } |
57 | else { |
89eee1ed |
58 | ok( chdir(), "chdir() w/ only \$ENV{$key} set" ); |
8ea155d1 |
59 | is( abs_path, $ENV{$key}, ' abs_path() agrees' ); |
35ae6b54 |
60 | chdir($Cwd); |
61 | is( abs_path, $Cwd, ' and back again' ); |
62 | |
63 | my $warning = ''; |
64 | local $SIG{__WARN__} = sub { $warning .= join '', @_ }; |
65 | |
8ea155d1 |
66 | |
35ae6b54 |
67 | # Check the deprecated chdir(undef) feature. |
68 | #line 60 |
69 | ok( chdir(undef), "chdir(undef) w/ only \$ENV{$key} set" ); |
70 | is( abs_path, $ENV{$key}, ' abs_path() agrees' ); |
71 | is( $warning, <<WARNING, ' got uninit & deprecation warning' ); |
72 | Use of uninitialized value in chdir at $0 line 60. |
73 | Use of chdir('') or chdir(undef) as chdir() is deprecated at $0 line 60. |
74 | WARNING |
8ea155d1 |
75 | |
35ae6b54 |
76 | chdir($Cwd); |
77 | |
78 | # Ditto chdir(''). |
79 | $warning = ''; |
80 | #line 72 |
81 | ok( chdir(''), "chdir('') w/ only \$ENV{$key} set" ); |
82 | is( abs_path, $ENV{$key}, ' abs_path() agrees' ); |
83 | is( $warning, <<WARNING, ' got deprecation warning' ); |
84 | Use of chdir('') or chdir(undef) as chdir() is deprecated at $0 line 72. |
85 | WARNING |
86 | |
87 | chdir($Cwd); |
88 | } |
8ea155d1 |
89 | } |
90 | |
d6cdadd4 |
91 | sub clean_env { |
92 | delete $ENV{$_} foreach @magic_envs; |
93 | # The following means we won't really be testing for non-existence, |
94 | # but in Perl we can only delete from the process table, not the job |
95 | # table. |
96 | $ENV{'SYS$LOGIN'} = '' if $IsVMS; |
97 | } |
98 | |
35ae6b54 |
99 | foreach my $key (@magic_envs) { |
8ea155d1 |
100 | # We're going to be using undefs a lot here. |
101 | no warnings 'uninitialized'; |
102 | |
d6cdadd4 |
103 | clean_env; |
9d4c144b |
104 | $ENV{$key} = catdir $Cwd, ($IsVMS ? 'OP' : 'op'); |
35ae6b54 |
105 | |
106 | check_env($key); |
107 | } |
108 | |
109 | { |
d6cdadd4 |
110 | clean_env; |
8ea155d1 |
111 | |
112 | ok( !chdir(), 'chdir() w/o any ENV set' ); |
35ae6b54 |
113 | is( abs_path, $Cwd, ' abs_path() agrees' ); |
8ea155d1 |
114 | } |