This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
t/op/chdir.t won't pass on VMS
[perl5.git] / t / op / chdir.t
CommitLineData
8ea155d1
MS
1BEGIN {
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.
11use Cwd qw(abs_path cwd);
12use File::Spec::Functions qw(:DEFAULT splitdir);
13
89eee1ed 14use Test::More tests => 25;
8ea155d1
MS
15
16my $cwd = abs_path;
17
18# Let's get to a known position
19SKIP: {
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.
29my @magic_envs = qw(HOME LOGDIR SYS$LOGIN);
30
31foreach 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
89eee1ed 38 # Make sure $ENV{'SYS$LOGIN'} is only honored on VMS.
8ea155d1 39 if( $key eq 'SYS$LOGIN' && $^O ne 'VMS' ) {
89eee1ed
BZ
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" );
8ea155d1
MS
43 }
44 else {
89eee1ed 45 ok( chdir(), "chdir() w/ only \$ENV{$key} set" );
8ea155d1
MS
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()
89eee1ed 52 ok( !chdir(undef), "chdir(undef) w/ only \$ENV{$key} set" );
8ea155d1
MS
53 is( abs_path, $cwd, ' abs_path() agrees' );
54
55 # Ditto chdir('').
89eee1ed 56 ok( !chdir(''), "chdir('') w/ only \$ENV{$key} set" );
8ea155d1
MS
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}