Test numbering mismatch.
[p5sagit/p5-mst-13.2.git] / t / op / chdir.t
CommitLineData
35ae6b54 1#!./perl -w
2
8ea155d1 3BEGIN {
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 10require "test.pl";
205e3209 11plan(tests => 25);
8ea155d1 12
35ae6b54 13my $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 17use 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.
21sub abs_path {
9d4c144b 22 $IsVMS ? uc(rel2abs(curdir)) : rel2abs(curdir);
d9c93211 23}
8ea155d1 24
35ae6b54 25my $Cwd = abs_path;
8ea155d1 26
27# Let's get to a known position
28SKIP: {
9d4c144b 29 skip("Already in t/", 2) if (splitdir(abs_path))[-1] eq ($IsVMS ? 'T' : 't');
8ea155d1 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.
38my @magic_envs = qw(HOME LOGDIR SYS$LOGIN);
39
35ae6b54 40sub 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' );
64Use of uninitialized value in chdir at $0 line 60.
65Use of chdir('') or chdir(undef) as chdir() is deprecated at $0 line 60.
66WARNING
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' );
76Use of chdir('') or chdir(undef) as chdir() is deprecated at $0 line 72.
77WARNING
78
79 chdir($Cwd);
80 }
8ea155d1 81}
82
35ae6b54 83foreach my $key (@magic_envs) {
8ea155d1 84 # We're going to be using undefs a lot here.
85 no warnings 'uninitialized';
86
9d4c144b 87 local %ENV = () if !$IsVMS;
88 $ENV{$key} = catdir $Cwd, ($IsVMS ? 'OP' : 'op');
35ae6b54 89
90 check_env($key);
91}
92
93{
9d4c144b 94 local %ENV = () if !$IsVMS;
8ea155d1 95
96 ok( !chdir(), 'chdir() w/o any ENV set' );
35ae6b54 97 is( abs_path, $Cwd, ' abs_path() agrees' );
8ea155d1 98}