t/op/chdir.t won't pass on VMS
[p5sagit/p5-mst-13.2.git] / t / op / chdir.t
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 => 25;
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     # 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" );
43     }
44     else {
45         ok( chdir(),              "chdir() w/ only \$ENV{$key} set" );
46         is( abs_path, $ENV{$key}, '  abs_path() agrees' );
47         chdir($cwd);
48         is( abs_path, $cwd,       '  and back again' );
49     }
50
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' );
54
55     # Ditto chdir('').
56     ok( !chdir(''),                 "chdir('') w/ only \$ENV{$key} set" );
57     is( abs_path, $cwd,             '  abs_path() agrees' );
58 }
59
60 {
61     # We're going to be using undefs a lot here.
62     no warnings 'uninitialized';
63
64     # Unset all the environment variables chdir() pay attention to.
65     local @ENV{@magic_envs} = (undef) x @magic_envs;
66
67     ok( !chdir(),                   'chdir() w/o any ENV set' );
68     is( abs_path, $cwd,             '  abs_path() agrees' );
69 }