|
Lines 1-19
Link Here
|
| 1 |
#!/usr/bin/perl |
1 |
#!/usr/bin/perl |
| 2 |
use Modern::Perl; |
2 |
use Modern::Perl; |
|
|
3 |
use threads; # used for parallel |
| 3 |
use Test::PerlTidy; |
4 |
use Test::PerlTidy; |
| 4 |
use Test::More; |
5 |
use Test::More; |
| 5 |
use Test::NoWarnings; |
6 |
use Test::NoWarnings; |
|
|
7 |
use Parallel::ForkManager; |
| 8 |
use Sys::CPU; |
| 9 |
use Cwd qw(getcwd); |
| 6 |
|
10 |
|
| 7 |
use Koha::Devel::CI::IncrementalRuns; |
11 |
use Koha::Devel::CI::IncrementalRuns; |
| 8 |
|
12 |
|
| 9 |
my $ci = Koha::Devel::CI::IncrementalRuns->new( { context => 'tidy' } ); |
13 |
my $ci = Koha::Devel::CI::IncrementalRuns->new( { context => 'tidy' } ); |
| 10 |
my @files = $ci->get_files_to_test('pl'); |
14 |
my @files = $ci->get_files_to_test('pl'); |
| 11 |
|
15 |
|
| 12 |
plan tests => scalar(@files) + 1; |
16 |
my $ncpu; |
|
|
17 |
if ( $ENV{KOHA_PROVE_CPUS} ) { |
| 18 |
$ncpu = $ENV{KOHA_PROVE_CPUS}; |
| 19 |
} else { |
| 20 |
$ncpu = Sys::CPU::cpu_count(); |
| 21 |
} |
| 22 |
|
| 23 |
# Capture the current working directory before forking |
| 24 |
my $cwd = getcwd(); |
| 13 |
|
25 |
|
|
|
26 |
my $pm = Parallel::ForkManager->new($ncpu); |
| 14 |
my %results; |
27 |
my %results; |
|
|
28 |
$pm->run_on_finish( |
| 29 |
sub { |
| 30 |
my ( $pid, $exit_code, $ident, $exit_signal, $core_dump, $data ) = @_; |
| 31 |
$results{$ident} = $exit_code; |
| 32 |
} |
| 33 |
); |
| 34 |
|
| 35 |
plan tests => scalar(@files) + 1; |
| 36 |
|
| 15 |
for my $file (@files) { |
37 |
for my $file (@files) { |
| 16 |
ok( Test::PerlTidy::is_file_tidy($file) ) or $results{$file} = 1; |
38 |
$pm->start($file) and next; |
|
|
39 |
|
| 40 |
# Ensure we're in the correct directory in the forked process |
| 41 |
chdir($cwd); |
| 42 |
|
| 43 |
my $is_tidy = Test::PerlTidy::is_file_tidy($file); |
| 44 |
my $exit_code = $is_tidy ? 0 : 1; |
| 45 |
|
| 46 |
ok( $is_tidy, "$file is tidy" ); |
| 47 |
|
| 48 |
$pm->finish($exit_code); |
| 17 |
} |
49 |
} |
| 18 |
|
50 |
|
|
|
51 |
$pm->wait_all_children; |
| 52 |
|
| 19 |
$ci->report_results( \%results ); |
53 |
$ci->report_results( \%results ); |
| 20 |
- |
|
|