summaryrefslogtreecommitdiff
path: root/ext/File-Find
diff options
context:
space:
mode:
authorJames E Keenan <jkeenan@cpan.org>2013-12-01 19:24:06 +0100
committerJames E Keenan <jkeenan@cpan.org>2013-12-04 00:50:17 +0100
commit61097a0ac091093a5b2829b9470f9ec71a92b7bf (patch)
treecb1e5217f3da7c791407dbe756026c0bd780383d /ext/File-Find
parent69d77f94471afeabd870b0ab97e69f934aa9086e (diff)
downloadperl-61097a0ac091093a5b2829b9470f9ec71a92b7bf.tar.gz
Standardize dir_path() and file_path() in package Testing.
The versions of dir_path() and file_path() previously found in find.t and taint.t differed only in VMS-specific provisions in taint.t. Move the taint.t-versions to the package and use them in both files.
Diffstat (limited to 'ext/File-Find')
-rw-r--r--ext/File-Find/t/find.t57
-rw-r--r--ext/File-Find/t/lib/Testing.pm61
-rw-r--r--ext/File-Find/t/taint.t62
3 files changed, 65 insertions, 115 deletions
diff --git a/ext/File-Find/t/find.t b/ext/File-Find/t/find.t
index 42b379c4cd..03a2145699 100644
--- a/ext/File-Find/t/find.t
+++ b/ext/File-Find/t/find.t
@@ -36,6 +36,8 @@ use Testing qw(
create_file_ok
mkdir_ok
symlink_ok
+ dir_path
+ file_path
);
my %Expect_File = (); # what we expect for $_
@@ -211,66 +213,11 @@ sub my_postprocess {
delete $Expect_Dir{ $File::Find::dir};
}
-# Use dir_path() to specify a directory path that is expected for
-# $File::Find::dir (%Expect_Dir). Also use it in file operations like
-# chdir, rmdir etc.
-#
-# dir_path() concatenates directory names to form a *relative*
-# directory path, independent from the platform it is run on, although
-# there are limitations. Do not try to create an absolute path,
-# because that may fail on operating systems that have the concept of
-# volume names (e.g. Mac OS). As a special case, you can pass it a "."
-# as first argument, to create a directory path like "./fa/dir". If there is
-# no second argument, this function will return "./"
-
-sub dir_path {
- my $first_arg = shift @_;
-
- if ($first_arg eq '.') {
- return './' unless @_;
- my $path = File::Spec->catdir(@_);
- # add leading "./"
- $path = "./$path";
- return $path;
- }
- else { # $first_arg ne '.'
- return $first_arg unless @_; # return plain filename
- return File::Spec->catdir($first_arg, @_); # relative path
- }
-}
-
# Use topdir() to specify a directory path that you want to pass to
# find/finddepth. Historically topdir() differed on Mac OS classic.
*topdir = \&dir_path;
-# Use file_path() to specify a file path that is expected for $_
-# (%Expect_File). Also suitable for file operations like unlink etc.
-#
-# file_path() concatenates directory names (if any) and a filename to
-# form a *relative* file path (the last argument is assumed to be a
-# file). It is independent from the platform it is run on, although
-# there are limitations. As a special case, you can pass it a "." as
-# first argument, to create a file path like "./fa/file" on operating
-# systems. If there is no second argument, this function will return the
-# string "./"
-
-sub file_path {
- my $first_arg = shift @_;
-
- if ($first_arg eq '.') {
- return './' unless @_;
- my $path = File::Spec->catfile(@_);
- # add leading "./"
- $path = "./$path";
- return $path;
- }
- else { # $first_arg ne '.'
- return $first_arg unless @_; # return plain filename
- return File::Spec->catfile($first_arg, @_); # relative path
- }
-}
-
# Use file_path_name() to specify a file path that is expected for
# $File::Find::Name (%Expect_Name). Note: When the no_chdir => 1
# option is in effect, $_ is the same as $File::Find::Name. In that
diff --git a/ext/File-Find/t/lib/Testing.pm b/ext/File-Find/t/lib/Testing.pm
index 70c5dcd6d0..c638ce06b7 100644
--- a/ext/File-Find/t/lib/Testing.pm
+++ b/ext/File-Find/t/lib/Testing.pm
@@ -8,6 +8,8 @@ our @EXPORT_OK = qw(
create_file_ok
mkdir_ok
symlink_ok
+ dir_path
+ file_path
);
# Wrappers around Test::More::ok() for creation of files, directories and
@@ -36,4 +38,63 @@ sub symlink_ok($$;$) {
or die("Unable to symlink from $oldfile to $newfile");
}
+# Use dir_path() to specify a directory path that is expected for
+# $File::Find::dir (%Expect_Dir). Also use it in file operations like
+# chdir, rmdir etc.
+#
+# dir_path() concatenates directory names to form a *relative*
+# directory path, independent from the platform it is run on, although
+# there are limitations. Do not try to create an absolute path,
+# because that may fail on operating systems that have the concept of
+# volume names (e.g. Mac OS). As a special case, you can pass it a "."
+# as first argument, to create a directory path like "./fa/dir". If there is
+# no second argument, this function will return "./"
+
+sub dir_path {
+ my $first_arg = shift @_;
+
+ if ($first_arg eq '.') {
+ return './' unless @_;
+ my $path = File::Spec->catdir(@_);
+ # add leading "./"
+ $path = "./$path";
+ return $path;
+ }
+ else { # $first_arg ne '.'
+ return $first_arg unless @_; # return plain filename
+ my $fname = File::Spec->catdir($first_arg, @_); # relative path
+ $fname = VMS::Filespec::unixpath($fname) if $^O eq 'VMS';
+ return $fname;
+ }
+}
+
+# Use file_path() to specify a file path that is expected for $_
+# (%Expect_File). Also suitable for file operations like unlink etc.
+#
+# file_path() concatenates directory names (if any) and a filename to
+# form a *relative* file path (the last argument is assumed to be a
+# file). It is independent from the platform it is run on, although
+# there are limitations. As a special case, you can pass it a "." as
+# first argument, to create a file path like "./fa/file" on operating
+# systems. If there is no second argument, this function will return the
+# string "./"
+
+sub file_path {
+ my $first_arg = shift @_;
+
+ if ($first_arg eq '.') {
+ return './' unless @_;
+ my $path = File::Spec->catfile(@_);
+ # add leading "./"
+ $path = "./$path";
+ return $path;
+ }
+ else { # $first_arg ne '.'
+ return $first_arg unless @_; # return plain filename
+ my $fname = File::Spec->catfile($first_arg, @_); # relative path
+ $fname = VMS::Filespec::unixify($fname) if $^O eq 'VMS';
+ return $fname;
+ }
+}
+
1;
diff --git a/ext/File-Find/t/taint.t b/ext/File-Find/t/taint.t
index e4fb6c9fc4..1675e6c537 100644
--- a/ext/File-Find/t/taint.t
+++ b/ext/File-Find/t/taint.t
@@ -13,6 +13,8 @@ use Testing qw(
create_file_ok
mkdir_ok
symlink_ok
+ dir_path
+ file_path
);
my %Expect_File = (); # what we expect for $_
@@ -139,71 +141,11 @@ sub simple_wanted {
print "# \$_ => '$_'\n";
}
-
-# Use dir_path() to specify a directory path that's expected for
-# $File::Find::dir (%Expect_Dir). Also use it in file operations like
-# chdir, rmdir etc.
-#
-# dir_path() concatenates directory names to form a *relative*
-# directory path, independent from the platform it's run on, although
-# there are limitations. Don't try to create an absolute path,
-# because that may fail on operating systems that have the concept of
-# volume names (e.g. Mac OS). As a special case, you can pass it a "."
-# as first argument, to create a directory path like "./fa/dir". If there's
-# no second argument this function will return the string "./"
-
-sub dir_path {
- my $first_arg = shift @_;
-
- if ($first_arg eq '.') {
- return './' unless @_;
- my $path = File::Spec->catdir(@_);
- # add leading "./"
- $path = "./$path";
- return $path;
- } else { # $first_arg ne '.'
- return $first_arg unless @_; # return plain filename
- my $fname = File::Spec->catdir($first_arg, @_); # relative path
- $fname = VMS::Filespec::unixpath($fname) if $^O eq 'VMS';
- return $fname;
- }
-}
-
-
# Use topdir() to specify a directory path that you want to pass to
# find/finddepth. Historically topdir() differed on Mac OS classic.
*topdir = \&dir_path;
-
-# Use file_path() to specify a file path that's expected for $_
-# (%Expect_File). Also suitable for file operations like unlink etc.
-#
-# file_path() concatenates directory names (if any) and a filename to
-# form a *relative* file path (the last argument is assumed to be a
-# file). It's independent from the platform it's run on, although
-# there are limitations. As a special case, you can pass it a "." as
-# first argument, to create a file path like "./fa/file". If there's no
-# second argument, this function will return the string "./" otherwise.
-
-sub file_path {
- my $first_arg = shift @_;
-
- if ($first_arg eq '.') {
- return './' unless @_;
- my $path = File::Spec->catfile(@_);
- # add leading "./"
- $path = "./$path";
- return $path;
- } else { # $first_arg ne '.'
- return $first_arg unless @_; # return plain filename
- my $fname = File::Spec->catfile($first_arg, @_); # relative path
- $fname = VMS::Filespec::unixify($fname) if $^O eq 'VMS';
- return $fname;
- }
-}
-
-
# Use file_path_name() to specify a file path that's expected for
# $File::Find::Name (%Expect_Name). Note: When the no_chdir => 1
# option is in effect, $_ is the same as $File::Find::Name. In that