This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
find.t: Use temporary testing directory for all blocks of tests.
authorJames E Keenan <jkeenan@cpan.org>
Wed, 16 Jan 2019 15:56:44 +0000 (10:56 -0500)
committerJames E Keenan <jkeenan@cpan.org>
Wed, 23 Jan 2019 20:13:30 +0000 (15:13 -0500)
During the execution of ext/File-Find/t/taint.t certain files and directories
are created.  As inferred from smoke-test reports, when testing in parallel
these entities ran the risk of being detected by certain tests in
ext/File-Find/t/find.t, thereby causing intermittent failures in the smoke
tests.

Problem is being addressed by (a) moving the block of tests created in August 2014
(RT #122547) to prevent processing of misspelled options to a place in the
file where we have moved from the current working directory one level down to
a temporary testing directory; and (b) providing a list of basenames of files
we expect to find therewithin.

ext/File-Find/t/find.t

index b532752..b0e30eb 100644 (file)
@@ -90,46 +90,6 @@ finddepth({wanted => sub { ++$::count_taint if $_ eq 'taint.t'; } },
     File::Spec->curdir);
 is($::count_taint, 1, "'finddepth' found exactly 1 file named 'taint.t'");
 
-##### RT #122547 #####
-# Do find() and finddepth() correctly warn on invalid options?
-{
-    my $bad_option = 'foobar';
-    my $second_bad_option = 'really_foobar';
-
-    $::count_taint = 0;
-    local $SIG{__WARN__} = sub { $warn_msg = $_[0]; };
-    {
-        find(
-            {
-                wanted => sub { ++$::count_taint if $_ eq 'taint.t'; },
-                $bad_option => undef,
-            },
-            File::Spec->curdir
-        );
-    };
-    like($warn_msg, qr/Invalid option/s, "Got warning for invalid option");
-    like($warn_msg, qr/$bad_option/s, "Got warning for $bad_option");
-    is($::count_taint, 1, "count_taint incremented");
-    undef $warn_msg;
-
-    $::count_taint = 0;
-    {
-        finddepth(
-            {
-                wanted => sub { ++$::count_taint if $_ eq 'taint.t'; },
-                $bad_option => undef,
-                $second_bad_option => undef,
-            },
-            File::Spec->curdir
-        );
-    };
-    like($warn_msg, qr/Invalid option/s, "Got warning for invalid option");
-    like($warn_msg, qr/$bad_option/s, "Got warning for $bad_option");
-    like($warn_msg, qr/$second_bad_option/s, "Got warning for $second_bad_option");
-    is($::count_taint, 1, "count_taint incremented");
-    undef $warn_msg;
-}
-
 my $FastFileTests_OK = 0;
 
 sub cleanup {
@@ -283,22 +243,72 @@ sub my_postprocess {
 mkdir_ok( dir_path('for_find'), 0770 );
 ok( chdir( dir_path('for_find')), "Able to chdir to 'for_find'")
     or die("Unable to chdir to 'for_find'");
+
+my @testing_basenames = ( qw| fb_ord fba_ord fa_ord faa_ord fab_ord faba_ord | );
+
 mkdir_ok( dir_path('fa'), 0770 );
 mkdir_ok( dir_path('fb'), 0770  );
-create_file_ok( file_path('fb', 'fb_ord') );
+create_file_ok( file_path('fb', $testing_basenames[0]) );
 mkdir_ok( dir_path('fb', 'fba'), 0770  );
-create_file_ok( file_path('fb', 'fba', 'fba_ord') );
+create_file_ok( file_path('fb', 'fba', $testing_basenames[1]) );
 if ($symlink_exists) {
     symlink_ok('../fb','fa/fsl');
 }
-create_file_ok( file_path('fa', 'fa_ord') );
+create_file_ok( file_path('fa', $testing_basenames[2]) );
 
 mkdir_ok( dir_path('fa', 'faa'), 0770  );
-create_file_ok( file_path('fa', 'faa', 'faa_ord') );
+create_file_ok( file_path('fa', 'faa', $testing_basenames[3]) );
 mkdir_ok( dir_path('fa', 'fab'), 0770  );
-create_file_ok( file_path('fa', 'fab', 'fab_ord') );
+create_file_ok( file_path('fa', 'fab', $testing_basenames[4]) );
 mkdir_ok( dir_path('fa', 'fab', 'faba'), 0770  );
-create_file_ok( file_path('fa', 'fab', 'faba', 'faba_ord') );
+create_file_ok( file_path('fa', 'fab', 'faba', $testing_basenames[5]) );
+
+##### RT #122547 #####
+# Do find() and finddepth() correctly warn on invalid options?
+##### RT #133771 #####
+# When running tests in parallel, avoid clash with tests in
+# ext/File-Find/t/taint by moving into the temporary testing directory
+# before testing for warnings on invalid options.
+
+my %tb = map { $_ => 1 } @testing_basenames;
+
+{
+    my $bad_option = 'foobar';
+    my $second_bad_option = 'really_foobar';
+
+    $::count_tb = 0;
+    local $SIG{__WARN__} = sub { $warn_msg = $_[0]; };
+    {
+        find(
+            {
+                wanted => sub { ++$::count_tb if $tb{$_}; },
+                $bad_option => undef,
+            },
+            File::Spec->curdir
+        );
+    };
+    like($warn_msg, qr/Invalid option/s, "Got warning for invalid option");
+    like($warn_msg, qr/$bad_option/s, "Got warning for $bad_option");
+    is($::count_tb, scalar(@testing_basenames), "count_tb incremented");
+    undef $warn_msg;
+
+    $::count_tb = 0;
+    {
+        finddepth(
+            {
+                wanted => sub { ++$::count_tb if $tb{$_}; },
+                $bad_option => undef,
+                $second_bad_option => undef,
+            },
+            File::Spec->curdir
+        );
+    };
+    like($warn_msg, qr/Invalid option/s, "Got warning for invalid option");
+    like($warn_msg, qr/$bad_option/s, "Got warning for $bad_option");
+    like($warn_msg, qr/$second_bad_option/s, "Got warning for $second_bad_option");
+    is($::count_tb, scalar(@testing_basenames), "count_tb incremented");
+    undef $warn_msg;
+}
 
 ##### Basic tests for find() #####
 # Set up list of files we expect to find.