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