@@ -7,7 +7,6 @@ use warnings;
7
7
8
8
use Carp qw( croak) ;
9
9
use English qw( -no_match_vars) ;
10
- use MCE::Grep;
11
10
12
11
use Test::Builder qw( ) ;
13
12
use Perl::Critic qw( ) ;
@@ -93,23 +92,41 @@ sub all_critic_ok {
93
92
my @files = Perl::Critic::Utils::all_perl_files(@dirs_or_files );
94
93
croak ' Nothing to critique' if not @files ;
95
94
96
- # Since tests are running in forked MCE workers, test results could arrive
97
- # in any order. The test numbers will be meaningless, so turn them off.
98
- $TEST -> use_numbers(0);
95
+ my $have_mce = eval {require MCE::Grep};
96
+ return $have_mce ? _test_parallel(@files ) : _test_serial(@files );
97
+ }
98
+
99
+ # ---------------------------------------------------------------------------
100
+
101
+ sub _test_parallel {
102
+ my @files = @_ ;
103
+
104
+ # Since tests are running in forked MCE workers, test results could arrive
105
+ # in any order. The test numbers will be meaningless, so turn them off.
106
+ $TEST -> use_numbers(0);
99
107
100
- # The parent won't know about any of the tests that were run by the forked
101
- # workers. So we disable the T::B sanity checks at the end of its life.
102
- $TEST -> no_ending(1);
108
+ # The parent won't know about any of the tests that were run by the forked
109
+ # workers. So we disable the T::B sanity checks at the end of its life.
110
+ $TEST -> no_ending(1);
111
+
112
+ my $okays = MCE::Grep::mce_grep { critic_ok($_ ) } @files ;
113
+ my $pass = $okays == @files ;
114
+
115
+ # To make Test::Harness happy, we must emit a test plan and a sensible exit
116
+ # status. Usually, T::B does this for us, but we disabled the ending above.
117
+ $pass || eval ' END { $? = 1 }' ; # # no critic qw(Eval Interpolation)
118
+ $TEST -> done_testing(scalar @files );
119
+ }
120
+
121
+ # ---------------------------------------------------------------------------
103
122
104
- my $okays = mce_grep { critic_ok( $_ ) } @files ;
105
- my $pass = $okays == @files ;
123
+ sub _test_serial {
124
+ my @files = @_ ;
106
125
107
- # To make Test::Harness happy, we must emit a test plan and a sensible exit
108
- # status. Usually, T::B does this for us, but we disabled the ending above.
109
- $pass || eval ' END { $? = 1 }' ; # # no critic qw(Eval Interpolation)
110
- $TEST -> done_testing(scalar @files );
126
+ my $okays = grep {critic_ok($_ )} @files ;
127
+ my $pass = $okays == @files ;
111
128
112
- return $pass ;
129
+ return $pass ;
113
130
}
114
131
115
132
# ---------------------------------------------------------------------------
0 commit comments