From deed50f208b2fcb0f4861342698ad482b4f2fe60 Mon Sep 17 00:00:00 2001 From: James E Keenan Date: Sun, 1 Dec 2013 18:35:54 +0100 Subject: [PATCH] Extract subroutines used to test File-Find into separate package. t/porting/manifest.t and pod_rules.t: Add comments describing how to handle a MANIFEST which is not sorted properly (per recommendation by Nicholas Clark). --- MANIFEST | 1 + ext/File-Find/t/find.t | 30 ++++++------------------------ ext/File-Find/t/lib/Testing.pm | 39 +++++++++++++++++++++++++++++++++++++++ ext/File-Find/t/taint.t | 20 ++++++-------------- t/porting/manifest.t | 24 +++++++++++++++++++++++- t/porting/pod_rules.t | 19 +++++++++++++++++++ 6 files changed, 94 insertions(+), 39 deletions(-) create mode 100644 ext/File-Find/t/lib/Testing.pm diff --git a/MANIFEST b/MANIFEST index 17bda1e..dcd15dc 100644 --- a/MANIFEST +++ b/MANIFEST @@ -3573,6 +3573,7 @@ ext/File-DosGlob/lib/File/DosGlob.pm Win32 DOS-globbing module ext/File-DosGlob/t/DosGlob.t See if File::DosGlob works ext/File-Find/lib/File/Find.pm Routines to do a find ext/File-Find/t/find.t See if File::Find works +ext/File-Find/t/lib/Testing.pm Functions used in testing File-find ext/File-Find/t/taint.t See if File::Find works with taint ext/File-Glob/bsd_glob.c File::Glob extension run time code ext/File-Glob/bsd_glob.h File::Glob extension header file diff --git a/ext/File-Find/t/find.t b/ext/File-Find/t/find.t index c3ee691..42b379c 100644 --- a/ext/File-Find/t/find.t +++ b/ext/File-Find/t/find.t @@ -31,6 +31,12 @@ $test_count += 2 if $^O eq 'MSWin32' and $symlink_exists; use Test::More; plan tests => $test_count; +use lib qw( ./t/lib ); +use Testing qw( + create_file_ok + mkdir_ok + symlink_ok +); my %Expect_File = (); # what we expect for $_ my %Expect_Name = (); # what we expect for $File::Find::name/fullname @@ -130,30 +136,6 @@ END { cleanup(); } -# Wrappers around Test::More::ok() for creation of files, directories and -# symlinks used in testing - -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($$;$) { - my ($dir, $mask) = @_[0..1]; - my $msg = $_[2] || "able to mkdir: $dir"; - ok( mkdir($dir, $mask), $msg ) - or die("Unable to mkdir: $dir"); -} - -sub symlink_ok($$;$) { - my ($oldfile, $newfile) = @_[0..1]; - my $msg = $_[2] || "able to symlink from $oldfile to $newfile"; - ok( symlink( $oldfile, $newfile ), $msg) - or die("Unable to symlink from $oldfile to $newfile"); -} - sub wanted_File_Dir { print "# \$File::Find::dir => '$File::Find::dir'\t\$_ => '$_'\n"; s#\.$## if ($^O eq 'VMS' && $_ ne '.'); # diff --git a/ext/File-Find/t/lib/Testing.pm b/ext/File-Find/t/lib/Testing.pm new file mode 100644 index 0000000..70c5dcd --- /dev/null +++ b/ext/File-Find/t/lib/Testing.pm @@ -0,0 +1,39 @@ +package Testing; +use 5.006_001; +use strict; +use warnings; +require Exporter; +our @ISA = qw(Exporter); +our @EXPORT_OK = qw( + create_file_ok + mkdir_ok + symlink_ok +); + +# Wrappers around Test::More::ok() for creation of files, directories and +# symlinks used in testing of File-Find + +*ok = \&Test::More::ok; + +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($$;$) { + my ($dir, $mask) = @_[0..1]; + my $msg = $_[2] || "able to mkdir: $dir"; + ok( mkdir($dir, $mask), $msg ) + or die("Unable to mkdir: $dir"); +} + +sub symlink_ok($$;$) { + my ($oldfile, $newfile) = @_[0..1]; + my $msg = $_[2] || "able to symlink from $oldfile to $newfile"; + ok( symlink( $oldfile, $newfile ), $msg) + or die("Unable to symlink from $oldfile to $newfile"); +} + +1; diff --git a/ext/File-Find/t/taint.t b/ext/File-Find/t/taint.t index 100b561..e4fb6c9 100644 --- a/ext/File-Find/t/taint.t +++ b/ext/File-Find/t/taint.t @@ -8,6 +8,12 @@ BEGIN { : (skip_all => "A perl without taint support") ); } +use lib qw( ./t/lib ); +use Testing qw( + create_file_ok + mkdir_ok + symlink_ok +); my %Expect_File = (); # what we expect for $_ my %Expect_Name = (); # what we expect for $File::Find::name/fullname @@ -108,20 +114,6 @@ END { cleanup(); } -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($$;$) { - 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'\t\$_ => '$_'\n"; s#\.$## if ($^O eq 'VMS' && $_ ne '.'); # diff --git a/t/porting/manifest.t b/t/porting/manifest.t index ea4fe83..b8c63c5 100644 --- a/t/porting/manifest.t +++ b/t/porting/manifest.t @@ -1,6 +1,28 @@ #!./perl -w -# Test the well-formed-ness of the MANIFEST file. +# What does this test? +# This tests the well-formed-ness of the MANIFEST file. +# +# Why do we test this? +# TK +# +# It's broken - how do I fix it? +# If MANIFEST is not sorted properly, you will get this error output: +# got ''MANIFEST' is NOT sorted properly +# # ' +# # expected /(?^:is sorted properly)/ +# +# To correct this, run either: +# +# ./perl -Ilib Porting/manisort -o MANIFEST MANIFEST +# +# which will output "'MANIFEST' is NOT sorted properly" but which will +# correct the problem; or: +# +# make manifest +# +# which will output "WARNING: re-sorting MANIFEST" but which will also +# correct the problem. BEGIN { @INC = '..' if -f '../TestInit.pm'; diff --git a/t/porting/pod_rules.t b/t/porting/pod_rules.t index cdf2ae6..5c69483 100644 --- a/t/porting/pod_rules.t +++ b/t/porting/pod_rules.t @@ -1,5 +1,24 @@ #!./perl +# What does this test? +# This test executes Porting/pod_rules.pl and reports the result of that +# program. +# +# Why do we test this? +# Among other reasons, to check the well-formed-ness of these files: +# win32/makefile.mk +# MANIFEST +# win32/Makefile +# win32/pod.mak +# Makefile.SH +# vms/descrip_mms.template +# +# It's broken - how do I fix it? +# If MANIFEST fails the 'up to date' test, it will probably also fail +# t/porting/manifest.t as well. Follow instructions in that file for +# correcting the MANIFEST. When that file passes, the MANIFEST check in this +# file will probably pass as well. + BEGIN { chdir '..' unless -d 't'; unshift @INC, 'lib'; -- 2.7.4