summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames E Keenan <jkeenan@cpan.org>2013-12-01 16:43:47 +0100
committerJames E Keenan <jkeenan@cpan.org>2013-12-01 16:51:25 +0100
commit0fe503d17167f34d2c2f9a939c273dade116cb79 (patch)
tree803f40dc015a3628655843525a2ece33220e1c30
parent4779e03e2981c0d32b33717bf693fadd4a65b552 (diff)
downloadperl-0fe503d17167f34d2c2f9a939c273dade116cb79.tar.gz
Standardize subroutine definitions between tests.
In taint.t, replace touch() with create_file_ok() and MkDir() with mkdir_ok(). Make definition of wanted_File_Dir() identical in both test files. This is a step on the road to eliminating repeated code.
-rw-r--r--ext/File-Find/t/find.t2
-rw-r--r--ext/File-Find/t/taint.t54
2 files changed, 31 insertions, 25 deletions
diff --git a/ext/File-Find/t/find.t b/ext/File-Find/t/find.t
index f44ef9c810..c3ee6910d5 100644
--- a/ext/File-Find/t/find.t
+++ b/ext/File-Find/t/find.t
@@ -155,7 +155,7 @@ sub symlink_ok($$;$) {
}
sub wanted_File_Dir {
- printf "# \$File::Find::dir => '$File::Find::dir'\t\$_ => '$_'\n";
+ print "# \$File::Find::dir => '$File::Find::dir'\t\$_ => '$_'\n";
s#\.$## if ($^O eq 'VMS' && $_ ne '.'); #
s/(.dir)?$//i if ($^O eq 'VMS' && -d _);
ok( $Expect_File{$_}, "found $_ for \$_, as expected" );
diff --git a/ext/File-Find/t/taint.t b/ext/File-Find/t/taint.t
index 9d78ae0632..100b5613bd 100644
--- a/ext/File-Find/t/taint.t
+++ b/ext/File-Find/t/taint.t
@@ -108,24 +108,30 @@ END {
cleanup();
}
-sub touch {
- ok( open(my $T,'>',$_[0]), "Opened $_[0] successfully" );
+sub create_file_ok($;$) {
+ my $file = $_[0];
+ my $msg = $_[2] || "able to create file: $file";
+ ok( open(my $T,'>',$file), $msg )
+ or die("Unable to create file: $file");
}
-sub MkDir($$) {
- ok( mkdir($_[0],$_[1]), "Created directory $_[0] successfully" );
+sub mkdir_ok($$;$) {
+ my ($dir, $mask) = @_[0..1];
+ my $msg = $_[2] || "able to mkdir: $dir";
+ ok( mkdir($dir, $mask), $msg )
+ or die("Unable to mkdir: $dir");
}
sub wanted_File_Dir {
- print "# \$File::Find::dir => '$File::Find::dir'\n";
- print "# \$_ => '$_'\n";
- s#\.$## if ($^O eq 'VMS' && $_ ne '.');
+ print "# \$File::Find::dir => '$File::Find::dir'\t\$_ => '$_'\n";
+ s#\.$## if ($^O eq 'VMS' && $_ ne '.'); #
s/(.dir)?$//i if ($^O eq 'VMS' && -d _);
- ok( $Expect_File{$_}, "Expected and found $File::Find::name" );
+ ok( $Expect_File{$_}, "found $_ for \$_, as expected" );
if ( $FastFileTests_OK ) {
- delete $Expect_File{ $_}
+ delete $Expect_File{$_}
unless ( $Expect_Dir{$_} && ! -d _ );
- } else {
+ }
+ else {
delete $Expect_File{$_}
unless ( $Expect_Dir{$_} && ! -d $_ );
}
@@ -217,29 +223,29 @@ sub file_path {
*file_path_name = \&file_path;
-MkDir( dir_path('for_find'), 0770 );
+mkdir_ok( dir_path('for_find'), 0770 );
ok( chdir( dir_path('for_find')), 'successful chdir() to for_find' );
$cwd = cwd(); # save cwd
( $cwd_untainted ) = $cwd =~ m|^(.+)$|; # untaint it
-MkDir( dir_path('fa'), 0770 );
-MkDir( dir_path('fb'), 0770 );
-touch( file_path('fb', 'fb_ord') );
-MkDir( dir_path('fb', 'fba'), 0770 );
-touch( file_path('fb', 'fba', 'fba_ord') );
+mkdir_ok( dir_path('fa'), 0770 );
+mkdir_ok( dir_path('fb'), 0770 );
+create_file_ok( file_path('fb', 'fb_ord') );
+mkdir_ok( dir_path('fb', 'fba'), 0770 );
+create_file_ok( file_path('fb', 'fba', 'fba_ord') );
SKIP: {
skip "Creating symlink", 1, unless $symlink_exists;
ok( symlink('../fb','fa/fsl'), 'Created symbolic link' );
}
-touch( file_path('fa', 'fa_ord') );
-
-MkDir( dir_path('fa', 'faa'), 0770 );
-touch( file_path('fa', 'faa', 'faa_ord') );
-MkDir( dir_path('fa', 'fab'), 0770 );
-touch( file_path('fa', 'fab', 'fab_ord') );
-MkDir( dir_path('fa', 'fab', 'faba'), 0770 );
-touch( file_path('fa', 'fab', 'faba', 'faba_ord') );
+create_file_ok( file_path('fa', 'fa_ord') );
+
+mkdir_ok( dir_path('fa', 'faa'), 0770 );
+create_file_ok( file_path('fa', 'faa', 'faa_ord') );
+mkdir_ok( dir_path('fa', 'fab'), 0770 );
+create_file_ok( file_path('fa', 'fab', 'fab_ord') );
+mkdir_ok( dir_path('fa', 'fab', 'faba'), 0770 );
+create_file_ok( file_path('fa', 'fab', 'faba', 'faba_ord') );
print "# check untainting (no follow)\n";