#!./perl -w BEGIN { # We're not going to chdir() into 't' because we don't know if # chdir() works! Instead, we'll hedge our bets and put both # possibilities into @INC. @INC = qw(t . lib ../lib); } use Config; require "test.pl"; plan(tests => 31); my $IsVMS = $^O eq 'VMS'; my $IsMacOS = $^O eq 'MacOS'; # Might be a little early in the testing process to start using these, # but I can't think of a way to write this test without them. use File::Spec::Functions qw(:DEFAULT splitdir rel2abs splitpath); # Can't use Cwd::abs_path() because it has different ideas about # path separators than File::Spec. sub abs_path { $IsVMS ? uc(rel2abs(curdir)) : rel2abs(curdir); } my $Cwd = abs_path; # Let's get to a known position SKIP: { my ($vol,$dir) = splitpath(abs_path,1); my $test_dir = $IsVMS ? 'T' : 't'; skip("Already in t/", 2) if (splitdir($dir))[-1] eq $test_dir; ok( chdir($test_dir), 'chdir($test_dir)'); is( abs_path, catdir($Cwd, $test_dir), ' abs_path() agrees' ); } $Cwd = abs_path; # The environment variables chdir() pays attention to. my @magic_envs = qw(HOME LOGDIR SYS$LOGIN); sub check_env { my($key) = @_; # Make sure $ENV{'SYS$LOGIN'} is only honored on VMS. if( $key eq 'SYS$LOGIN' && !$IsVMS && !$IsMacOS ) { ok( !chdir(), "chdir() on $^O ignores only \$ENV{$key} set" ); is( abs_path, $Cwd, ' abs_path() did not change' ); pass( " no need to test SYS\$LOGIN on $^O" ) for 1..7; } else { ok( chdir(), "chdir() w/ only \$ENV{$key} set" ); is( abs_path, $ENV{$key}, ' abs_path() agrees' ); chdir($Cwd); is( abs_path, $Cwd, ' and back again' ); my $warning = ''; local $SIG{__WARN__} = sub { $warning .= join '', @_ }; # Check the deprecated chdir(undef) feature. #line 64 ok( chdir(undef), "chdir(undef) w/ only \$ENV{$key} set" ); is( abs_path, $ENV{$key}, ' abs_path() agrees' ); is( $warning, <