perl
view release on metacpan or search on metacpan
dist/PathTools/t/cwd.t view on Meta::CPAN
my $vms_unix_rpt = 0;
my $vms_efs = 0;
my $vms_mode = 0;
if ($IsVMS) {
require VMS::Filespec;
use Carp;
use Carp::Heavy;
$vms_mode = 1;
if (eval 'require VMS::Feature') {
$vms_unix_rpt = VMS::Feature::current("filename_unix_report");
$vms_efs = VMS::Feature::current("efs_charset");
} else {
my $unix_rpt = $ENV{'DECC$FILENAME_UNIX_REPORT'} || '';
my $efs_charset = $ENV{'DECC$EFS_CHARSET'} || '';
$vms_unix_rpt = $unix_rpt =~ /^[ET1]/i;
$vms_efs = $efs_charset =~ /^[ET1]/i;
}
$vms_mode = 0 if ($vms_unix_rpt);
}
my $tests = 31;
# _perl_abs_path() currently only works when the directory separator
# is '/', so don't test it when it won't work.
my $EXTRA_ABSPATH_TESTS = ($Config{prefix} =~ m/\//) && $^O ne 'cygwin';
$tests += 4 if $EXTRA_ABSPATH_TESTS;
plan tests => $tests;
SKIP: {
skip "no need to check for blib/ in the core", 1 if $ENV{PERL_CORE};
like $INC{'Cwd.pm'}, qr{blib}i, "Cwd should be loaded from blib/ during testing";
}
# check imports
can_ok('main', qw(cwd getcwd fastcwd fastgetcwd));
ok( !defined(&chdir), 'chdir() not exported by default' );
ok( !defined(&abs_path), ' nor abs_path()' );
ok( !defined(&fast_abs_path), ' nor fast_abs_path()');
{
my @fields = qw(PATH IFS CDPATH ENV BASH_ENV);
my $before = grep exists $ENV{$_}, @fields;
cwd();
my $after = grep exists $ENV{$_}, @fields;
is($before, $after, "cwd() shouldn't create spurious entries in %ENV");
}
# XXX force Cwd to bootstrap its XSUBs since we have set @INC = "../lib"
# XXX and subsequent chdir()s can make them impossible to find
eval { fastcwd };
# Must find an external pwd (or equivalent) command.
my $pwd = $^O eq 'MSWin32' ? "cmd" : "pwd";
my $pwd_cmd =
($^O eq "NetWare") ?
"cd" :
(grep { -x && -f } map { "$_/$pwd$Config{exe_ext}" }
split m/$Config{path_sep}/, $ENV{PATH})[0];
$pwd_cmd = 'SHOW DEFAULT' if $IsVMS;
if ($^O eq 'MSWin32') {
$pwd_cmd =~ s,/,\\,g;
$pwd_cmd = "$pwd_cmd /c cd";
}
$pwd_cmd =~ s=\\=/=g if ($^O eq 'dos');
SKIP: {
skip "No native pwd command found to test against", 4 unless $pwd_cmd;
print "# native pwd = '$pwd_cmd'\n";
local @ENV{qw(PATH IFS CDPATH ENV BASH_ENV)};
my ($pwd_cmd_untainted) = $pwd_cmd =~ /^(.+)$/; # Untaint.
chomp(my $start = `$pwd_cmd_untainted`);
# Win32's cd returns native C:\ style
$start =~ s,\\,/,g if ($^O eq 'MSWin32' || $^O eq "NetWare");
if ($IsVMS) {
# DCL SHOW DEFAULT has leading spaces
$start =~ s/^\s+//;
# When in UNIX report mode, need to convert to compare it.
if ($vms_unix_rpt) {
$start = VMS::Filespec::unixpath($start);
# Remove trailing slash.
$start =~ s#/$##;
}
}
SKIP: {
skip("'$pwd_cmd' failed, nothing to test against", 4) if $?;
skip("/afs seen, paths unlikely to match", 4) if $start =~ m|/afs/|;
# Darwin's getcwd(3) (which Cwd.xs:bsd_realpath() uses which
# Cwd.pm:getcwd uses) has some magic related to the PWD
# environment variable: if PWD is set to a directory that
# looks about right (guess: has the same (dev,ino) as the '.'?),
# the PWD is returned. However, if that path contains
# symlinks, the path will not be equal to the one returned by
# /bin/pwd (which probably uses the usual walking upwards in
# the path -trick). This situation is easy to reproduce since
# /tmp is a symlink to /private/tmp. Therefore we invalidate
# the PWD to force getcwd(3) to (re)compute the cwd in full.
# Admittedly fixing this in the Cwd module would be better
# long-term solution but deleting $ENV{PWD} should not be
# done light-heartedly. --jhi
delete $ENV{PWD} if $^O eq 'darwin';
my $cwd = cwd;
my $getcwd = getcwd;
my $fastcwd = fastcwd;
my $fastgetcwd = fastgetcwd;
is($cwd, $start, 'cwd()');
is($getcwd, $start, 'getcwd()');
is($fastcwd, $start, 'fastcwd()');
is($fastgetcwd, $start, 'fastgetcwd()');
}
}
( run in 1.279 second using v1.01-cache-2.11-cpan-71847e10f99 )