Perl-Critic / Test-Perl-Critic

Run Perl::Critic as a unit test
http://perlcritic.com
Other
9 stars 7 forks source link

critic_ok() in xt/96_perlcritic.t doesn't work with MCE running #9

Open petdance opened 7 years ago

petdance commented 7 years ago

When MCE is installed, xt/96_perlcritic.t fails because no filenames get passed to critic_ok

$ prove -b xt/96_perlcritic.t 
[23:07:49] xt/96_perlcritic.t .. no file specified at xt/96_perlcritic.t line 15.
[23:07:49] xt/96_perlcritic.t .. Dubious, test returned 255 (wstat 65280, 0xff00)
No subtests run 
[23:07:51]
marioroy commented 6 years ago

Hi @petdance. The following resolves the issue. Also, added missing line in _test_serial.

--- Test/Perl/Critic.pm 2017-07-04 12:01:15.421579849 -0500
+++ Test/Perl/Critic.pm.fix 2017-11-21 21:30:50.478096779 -0600
@@ -92,7 +92,7 @@
     my @files = Perl::Critic::Utils::all_perl_files(@dirs_or_files);
     croak 'Nothing to critique' if not @files;

-    my $have_mce = eval {require MCE::Grep};
+    my $have_mce = eval { require MCE::Grep; MCE::Grep->import; 1 };
     return $have_mce ? _test_parallel(@files) : _test_serial(@files);
 }

@@ -109,13 +109,15 @@
       # workers. So we disable the T::B sanity checks at the end of its life.
       $TEST->no_ending(1);

-      my $okays = MCE::Grep::mce_grep { critic_ok($_) } @files;
+      my $okays = MCE::Grep->run( sub { critic_ok($_) }, @files );
       my $pass = $okays == @files;

       # To make Test::Harness happy, we must emit a test plan and a sensible exit
       # status. Usually, T::B does this for us, but we disabled the ending above.
       $pass || eval 'END { $? = 1 }'; ## no critic qw(Eval Interpolation)
-      return $TEST->done_testing(scalar @files);
+      $TEST->done_testing(scalar @files);
+
+      return $pass;
 }

 #---------------------------------------------------------------------------
@@ -126,6 +128,8 @@
   my $okays = grep {critic_ok($_)} @files;
   my $pass = $okays == @files;

+  $TEST->done_testing(scalar @files);
+
   return $pass;
 }

I tested Test-Perl-Critic without and with MCE 1.827 through 1.832.

petdance commented 6 years ago

Applied. Thank.s