Skip to content

Commit

Permalink
_vms_abs_path on non-directories
Browse files Browse the repository at this point in the history
From: "Craig A. Berry" <craigberry@mac.com>
Message-ID: <40E704AA.4090801@mac.com>
Date: Sat, 03 Jul 2004 14:10:34 -0500

p4raw-id: //depot/perl@23029
  • Loading branch information
craigberry authored and nwc10 committed Jul 4, 2004
1 parent d281a6a commit 9d7d972
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
34 changes: 24 additions & 10 deletions ext/Cwd/t/cwd.t
Expand Up @@ -145,30 +145,44 @@ SKIP: {
unlink "linktest";
}

chdir '../ext/Cwd/t' if $ENV{PERL_CORE};
if ($ENV{PERL_CORE}) {
chdir '../ext/Cwd/t';
unshift @INC, '../../../lib';
}

# Make sure we can run abs_path() on files, not just directories
my $path = 'cwd.t';
dir_ends_with(Cwd::abs_path($path), 'cwd.t', 'abs_path() can be invoked on a file');
dir_ends_with(Cwd::fast_abs_path($path), 'cwd.t', 'fast_abs_path() can be invoked on a file');
path_ends_with(Cwd::abs_path($path), 'cwd.t', 'abs_path() can be invoked on a file');
path_ends_with(Cwd::fast_abs_path($path), 'cwd.t', 'fast_abs_path() can be invoked on a file');

$path = File::Spec->catfile(File::Spec->updir, 't', $path);
dir_ends_with(Cwd::abs_path($path), 'cwd.t', 'abs_path() can be invoked on a file');
dir_ends_with(Cwd::fast_abs_path($path), 'cwd.t', 'fast_abs_path() can be invoked on a file');
path_ends_with(Cwd::abs_path($path), 'cwd.t', 'abs_path() can be invoked on a file');
path_ends_with(Cwd::fast_abs_path($path), 'cwd.t', 'fast_abs_path() can be invoked on a file');


#############################################
# These two routines give us sort of a poor-man's cross-platform
# directory comparison routine.
# These routines give us sort of a poor-man's cross-platform
# directory or path comparison capability.

sub bracketed_form {
sub bracketed_form_dir {
return join '', map "[$_]",
grep length, File::Spec->splitdir(File::Spec->canonpath( shift() ));
}

sub dir_ends_with {
my ($dir, $expect) = (shift, shift);
my $bracketed_expect = quotemeta bracketed_form($expect);
like( bracketed_form($dir), qr|$bracketed_expect$|i, (@_ ? shift : ()) );
my $bracketed_expect = quotemeta bracketed_form_dir($expect);
like( bracketed_form_dir($dir), qr|$bracketed_expect$|i, (@_ ? shift : ()) );
}

sub bracketed_form_path {
return join '', map "[$_]",
grep length, File::Spec->splitpath(File::Spec->canonpath( shift() ));
}

sub path_ends_with {
my ($dir, $expect) = (shift, shift);
my $bracketed_expect = quotemeta bracketed_form_path($expect);
like( bracketed_form_path($dir), qr|$bracketed_expect$|i, (@_ ? shift : ()) );
}

8 changes: 4 additions & 4 deletions lib/Cwd.pm
Expand Up @@ -597,11 +597,11 @@ sub _vms_cwd {

sub _vms_abs_path {
return $ENV{'DEFAULT'} unless @_;

# may need to turn foo.dir into [.foo]
my $path = VMS::Filespec::pathify($_[0]);
if (! defined $path)
{
_croak("Invalid path name $_[0]")
}
$path = $_[0] unless defined $path;

return VMS::Filespec::rmsexpand($path);
}

Expand Down

0 comments on commit 9d7d972

Please sign in to comment.