From 172fe080b52086a0823e3aec4c56eec2a2e5e085 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 12 May 2025 16:10:10 +0200 Subject: [PATCH] Bug 39877: Apply to other slow tests --- Koha/Devel/CI/IncrementalRuns.pm | 4 ++-- Koha/Devel/Files.pm | 38 ++++++++++++++++++++++++++++++++ xt/author/codespell.t | 16 +++++++++----- xt/perltidy.t | 14 +++++++----- 4 files changed, 59 insertions(+), 13 deletions(-) diff --git a/Koha/Devel/CI/IncrementalRuns.pm b/Koha/Devel/CI/IncrementalRuns.pm index b14077ea88f..ec183b8632b 100644 --- a/Koha/Devel/CI/IncrementalRuns.pm +++ b/Koha/Devel/CI/IncrementalRuns.pm @@ -129,7 +129,7 @@ sub get_files_to_test { @koha_commit_history; if ($last_build_commit) { @files = @{ from_json( read_file("$self->{git_repo_dir}/$self->{test_name}/$last_build_commit") ) }; - push @files, $dev_files->ls_perl_files("$last_build_commit HEAD"); + push @files, $dev_files->ls_files( $filetype, "$last_build_commit HEAD" ); } else { # In case we run on a branch that does not have ancestor commits in the history @@ -140,7 +140,7 @@ sub get_files_to_test { $no_history = 1; } } - @files = $dev_files->ls_perl_files if !$self->{incremental_run} || $no_history; + @files = $dev_files->ls_files($filetype) if !$self->{incremental_run} || $no_history; return @files; } diff --git a/Koha/Devel/Files.pm b/Koha/Devel/Files.pm index 6aad0d7192e..e80a21e3c86 100644 --- a/Koha/Devel/Files.pm +++ b/Koha/Devel/Files.pm @@ -118,6 +118,44 @@ sub build_git_exclude { : q{}; } +=head2 ls_files + + my @files = $file_manager->ls_files($filetype, $git_range); + +Lists files that have been modified within a specified Git range. If no range is provided, it lists all Perl files, excluding those specified in the exceptions. + +=cut + +sub ls_files { + my ( $self, $filetype, $git_range ) = @_; + my @files; + if ($git_range) { + $git_range =~ s|\.\.| |; + my @modified_files = qx{git diff --name-only $git_range}; + chomp @modified_files; + if ( $filetype eq 'pl' ) { + push @files, grep { -e && /\.(pl|PL|pm|t)$/ } @modified_files; + push @files, grep { -e && /^(svc|opac\/svc)/ } @modified_files; + } elsif ( $filetype eq 'js' ) { + push @files, grep { -e && /\.(js|ts|vue)$/ } @modified_files; + } elsif ( $filetype eq 'tt' ) { + push @files, grep { -e && /\.(tt|inc)$/ } @modified_files; + } + + my @exception_files = $exceptions->{$filetype}->{ $self->{context} }; + @files = array_minus( @files, @exception_files ); + } else { + if ( $filetype eq 'pl' ) { + @files = $self->ls_perl_files; + } elsif ( $filetype eq 'js' ) { + @files = $self->ls_js_files; + } elsif ( $filetype eq 'tt' ) { + @files = $self->ls_tt_files; + } + } + return @files; +} + =head2 ls_perl_files my @perl_files = $file_manager->ls_perl_files($git_range); diff --git a/xt/author/codespell.t b/xt/author/codespell.t index e31799ca517..25f65c13be4 100755 --- a/xt/author/codespell.t +++ b/xt/author/codespell.t @@ -3,7 +3,7 @@ use Modern::Perl; use Test::PerlTidy; use Test::More; -use Koha::Devel::Files; +use Koha::Devel::CI::IncrementalRuns; my $codespell_version = qx{codespell --version}; chomp $codespell_version; @@ -11,16 +11,20 @@ $codespell_version =~ s/-.*$//; if ( ( $codespell_version =~ s/\.//gr ) < 220 ) { # if codespell < 2.2.0 plan skip_all => "codespell version $codespell_version too low, need at least 2.2.0"; } -my $dev_files = Koha::Devel::Files->new( { context => 'codespell' } ); + +my $ci = Koha::Devel::CI::IncrementalRuns->new( { context => 'codespell' } ); my @files; -push @files, $dev_files->ls_perl_files; -push @files, $dev_files->ls_tt_files; -push @files, $dev_files->ls_js_files; +push @files, $ci->get_files_to_test('pl'); +push @files, $ci->get_files_to_test('tt'); +push @files, $ci->get_files_to_test('js'); plan tests => scalar @files; +my %results; for my $file (@files) { my $output = qx{codespell -d --ignore-words .codespell-ignore $file}; chomp $output; - is( $output, q{} ); + is( $output, q{} ) or $results{$file} = 1; } + +$ci->report_results( \%results ); diff --git a/xt/perltidy.t b/xt/perltidy.t index edf8a5abd3e..6c1148a9b16 100755 --- a/xt/perltidy.t +++ b/xt/perltidy.t @@ -2,14 +2,18 @@ use Modern::Perl; use Test::PerlTidy; use Test::More; +use Test::NoWarnings; -use Koha::Devel::Files; +use Koha::Devel::CI::IncrementalRuns; -my $dev_files = Koha::Devel::Files->new( { context => 'tidy' } ); -my @files = $dev_files->ls_perl_files; +my $ci = Koha::Devel::CI::IncrementalRuns->new( { context => 'tidy' } ); +my @files = $ci->get_files_to_test('pl'); -plan tests => scalar @files; +plan tests => scalar @files + 1; +my %results; for my $file (@files) { - ok( Test::PerlTidy::is_file_tidy($file) ); + ok( Test::PerlTidy::is_file_tidy($file) ) or $results{$file} = 1; } + +$ci->report_results( \%results ); -- 2.34.1