Test numbering mismatch.
[p5sagit/p5-mst-13.2.git] / t / op / chdir.t
1 #!./perl -w
2
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.
7     @INC = qw(t . lib ../lib);
8 }
9
10 require "test.pl";
11 plan(tests => 25);
12
13 my $IsVMS = $^O eq 'VMS';
14
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.
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     $IsVMS ? uc(rel2abs(curdir)) : rel2abs(curdir);
23 }
24
25 my $Cwd = abs_path;
26
27 # Let's get to a known position
28 SKIP: {
29     skip("Already in t/", 2) if (splitdir(abs_path))[-1] eq ($IsVMS ? 'T' : 't');
30
31     ok( chdir('t'),     'chdir("t")');
32     is( abs_path, catdir($Cwd, 't'),       '  abs_path() agrees' );
33 }
34
35 $Cwd = abs_path;
36
37 # The environment variables chdir() pays attention to.
38 my @magic_envs = qw(HOME LOGDIR SYS$LOGIN);
39
40 sub check_env {
41     my($key) = @_;
42
43     # Make sure $ENV{'SYS$LOGIN'} is only honored on VMS.
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" );
48     }
49     else {
50         ok( chdir(),              "chdir() w/ only \$ENV{$key} set" );
51         is( abs_path, $ENV{$key}, '  abs_path() agrees' );
52         chdir($Cwd);
53         is( abs_path, $Cwd,       '  and back again' );
54
55         my $warning = '';
56         local $SIG{__WARN__} = sub { $warning .= join '', @_ };
57
58
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
67
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     }
81 }
82
83 foreach my $key (@magic_envs) {
84     # We're going to be using undefs a lot here.
85     no warnings 'uninitialized';
86
87     local %ENV = () if !$IsVMS;
88     $ENV{$key} = catdir $Cwd, ($IsVMS ? 'OP' : 'op');
89     
90     check_env($key);
91 }
92
93 {
94     local %ENV = () if !$IsVMS;
95
96     ok( !chdir(),                   'chdir() w/o any ENV set' );
97     is( abs_path, $Cwd,             '  abs_path() agrees' );
98 }