From 74414618ea46a65e7eb49390871716e40acf9b64 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 12 May 2025 14:34:01 +0200 Subject: [PATCH] Bug 39876: Apply module to other tests We are ready to reuse Koha::Devel::Files in other places where `git ls-files` is used. Signed-off-by: David Nind Signed-off-by: Tomas Cohen Arazi --- Koha/Devel/Files.pm | 53 ++++++++++++++++++++++++++++++++--- xt/author/codespell.t | 13 ++++----- xt/author/pod_checker.t | 7 ++--- xt/author/podcorrectness.t | 8 +++--- xt/find-missing-csrf.t | 11 ++------ xt/find-missing-filters.t | 12 ++------ xt/find-missing-op-in-forms.t | 12 ++------ xt/perltidy.t | 8 +++--- xt/pl_valid.t | 17 ++--------- xt/single_quotes.t | 11 ++------ xt/tt_tidy.t | 6 ++-- 11 files changed, 85 insertions(+), 73 deletions(-) diff --git a/Koha/Devel/Files.pm b/Koha/Devel/Files.pm index fb339ef839f..d23d54a1759 100644 --- a/Koha/Devel/Files.pm +++ b/Koha/Devel/Files.pm @@ -30,13 +30,58 @@ The module defines a set of exceptions for different file types and contexts. Th =cut my $exceptions = { - pl => { tidy => [qw(Koha/Schema/Result Koha/Schema.pm)] }, + pl => { + tidy => [ + qw( + Koha/Schema/Result + Koha/Schema.pm + ) + ], + valid => [ + qw( + Koha/Account/Credit.pm + Koha/Account/Debit.pm + Koha/Old/Hold.pm + misc/translator/TmplTokenizer.pm + ) + ], + codespell => [ + qw( + installer/data/mysql/updatedatabase.pl + installer/data/mysql/update22to30.pl + installer/data/mysql/db_revs/241200035.pl + misc/cronjobs/build_browser_and_cloud.pl + ) + ], + }, js => { tidy => [ - qw(koha-tmpl/intranet-tmpl/lib koha-tmpl/intranet-tmpl/js/Gettext.js koha-tmpl/opac-tmpl/lib Koha/ILL/Backend/) - ] + qw( + koha-tmpl/intranet-tmpl/lib + koha-tmpl/intranet-tmpl/js/Gettext.js + koha-tmpl/opac-tmpl/lib + Koha/ILL/Backend/ + ) + ], + codespell => [ + qw( + koha-tmpl/intranet-tmpl/lib + koha-tmpl/intranet-tmpl/js/Gettext.js + koha-tmpl/opac-tmpl/lib + koha-tmpl/opac-tmpl/bootstrap/js/Gettext.js + ) + ], + }, + tt => { + tidy => [ + qw( + Koha/ILL/Backend/ + *doc-head-open.inc + misc/cronjobs/rss + ) + ], + codespell => [], }, - tt => { tidy => [qw(Koha/ILL/Backend/ *doc-head-open.inc misc/cronjobs/rss)] }, }; =head1 METHODS diff --git a/xt/author/codespell.t b/xt/author/codespell.t index 781d1acd974..e31799ca517 100755 --- a/xt/author/codespell.t +++ b/xt/author/codespell.t @@ -3,24 +3,23 @@ use Modern::Perl; use Test::PerlTidy; use Test::More; +use Koha::Devel::Files; + my $codespell_version = qx{codespell --version}; chomp $codespell_version; $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 @files; -push @files, - qx{git ls-files '*.pl' '*.PL' '*.pm' '*.t' ':(exclude)installer/data/mysql/updatedatabase.pl' ':(exclude)installer/data/mysql/update22to30.pl' ':(exclude)installer/data/mysql/db_revs/241200035.pl' ':(exclude)misc/cronjobs/build_browser_and_cloud.pl'}; -push @files, qx{git ls-files svc opac/svc}; # Files without extension -push @files, qx{git ls-files '*.tt' '*.inc'}; -push @files, - qx{git ls-files '*.js' '*.ts' '*.vue' ':(exclude)koha-tmpl/intranet-tmpl/lib' ':(exclude)koha-tmpl/intranet-tmpl/js/Gettext.js' ':(exclude)koha-tmpl/opac-tmpl/lib' ':(exclude)koha-tmpl/opac-tmpl/bootstrap/js/Gettext.js'}; +push @files, $dev_files->ls_perl_files; +push @files, $dev_files->ls_tt_files; +push @files, $dev_files->ls_js_files; plan tests => scalar @files; for my $file (@files) { - chomp $file; my $output = qx{codespell -d --ignore-words .codespell-ignore $file}; chomp $output; is( $output, q{} ); diff --git a/xt/author/pod_checker.t b/xt/author/pod_checker.t index b0396640832..53e32ddf1b9 100755 --- a/xt/author/pod_checker.t +++ b/xt/author/pod_checker.t @@ -4,11 +4,10 @@ use Modern::Perl; use Test::More; use Test::NoWarnings; use Pod::Checker; +use Koha::Devel::Files; -my @files; -push @files, qx{git ls-files '*.pl' '*.PL' '*.pm' '*.t'}; -push @files, qx{git ls-files svc opac/svc}; # Files without extension -chomp for @files; +my $dev_files = Koha::Devel::Files->new; +my @files = $dev_files->ls_perl_files; plan tests => scalar @files + 1; diff --git a/xt/author/podcorrectness.t b/xt/author/podcorrectness.t index c30a0df74da..9f737845543 100755 --- a/xt/author/podcorrectness.t +++ b/xt/author/podcorrectness.t @@ -15,9 +15,9 @@ use Modern::Perl; use Test::More; use Test::Pod; -my @files; -push @files, qx{git ls-files '*.pl' '*.PL' '*.pm' '*.t'}; -push @files, qx{git ls-files svc opac/svc}; # Files without extension -chomp for @files; +use Koha::Devel::Files; + +my $dev_files = Koha::Devel::Files->new; +my @files = $dev_files->ls_perl_files; all_pod_files_ok(@files); diff --git a/xt/find-missing-csrf.t b/xt/find-missing-csrf.t index c10d7ee6b12..59610f9d284 100755 --- a/xt/find-missing-csrf.t +++ b/xt/find-missing-csrf.t @@ -22,20 +22,15 @@ use Test::More tests => 2; use File::Slurp; use Data::Dumper; -my @files; +use Koha::Devel::Files; -# OPAC -push @files, `git ls-files 'koha-tmpl/opac-tmpl/bootstrap/en/*.tt'`; -push @files, `git ls-files 'koha-tmpl/opac-tmpl/bootstrap/en/*.inc'`; +my $dev_files = Koha::Devel::Files->new; +my @files = $dev_files->ls_tt_files; -# Staff -push @files, `git ls-files 'koha-tmpl/intranet-tmpl/prog/en/*.tt'`; -push @files, `git ls-files 'koha-tmpl/intranet-tmpl/prog/en/*.inc'`; ok( @files > 0, 'We should test something' ); my @errors; for my $file (@files) { - chomp $file; my @e = check_csrf_in_forms($file); push @errors, sprintf "%s:%s", $file, join( ",", @e ) if @e; } diff --git a/xt/find-missing-filters.t b/xt/find-missing-filters.t index 0aefa3707c5..425c73921e1 100755 --- a/xt/find-missing-filters.t +++ b/xt/find-missing-filters.t @@ -20,21 +20,15 @@ use Test::More tests => 2; use File::Slurp qw( read_file ); use Data::Dumper; use t::lib::QA::TemplateFilters; +use Koha::Devel::Files; -my @files; +my $dev_files = Koha::Devel::Files->new; +my @files = $dev_files->ls_tt_files; -# OPAC -push @files, `git ls-files 'koha-tmpl/opac-tmpl/bootstrap/en/*.tt'`; -push @files, `git ls-files 'koha-tmpl/opac-tmpl/bootstrap/en/*.inc'`; - -# Staff -push @files, `git ls-files 'koha-tmpl/intranet-tmpl/prog/en/*.tt'`; -push @files, `git ls-files 'koha-tmpl/intranet-tmpl/prog/en/*.inc'`; ok( @files > 0, 'We should test something' ); my @errors; for my $file (@files) { - chomp $file; my $content = read_file($file); my @e = t::lib::QA::TemplateFilters::missing_filters($content); push @errors, { file => $file, errors => \@e } if @e; diff --git a/xt/find-missing-op-in-forms.t b/xt/find-missing-op-in-forms.t index 840d8b994ba..31a3f2b50f3 100755 --- a/xt/find-missing-op-in-forms.t +++ b/xt/find-missing-op-in-forms.t @@ -22,20 +22,14 @@ use Test::More tests => 2; use File::Slurp; use Data::Dumper; -my @files; +use Koha::Devel::Files; -# OPAC -push @files, `git ls-files 'koha-tmpl/opac-tmpl/bootstrap/en/*.tt'`; -push @files, `git ls-files 'koha-tmpl/opac-tmpl/bootstrap/en/*.inc'`; - -# Staff -push @files, `git ls-files 'koha-tmpl/intranet-tmpl/prog/en/*.tt'`; -push @files, `git ls-files 'koha-tmpl/intranet-tmpl/prog/en/*.inc'`; +my $dev_files = Koha::Devel::Files->new; +my @files = $dev_files->ls_perl_files; ok( @files > 0, 'We should test something' ); my @errors; for my $file (@files) { - chomp $file; my @e = catch_missing_op($file); push @errors, sprintf "%s:%s", $file, join( ",", @e ) if @e; } diff --git a/xt/perltidy.t b/xt/perltidy.t index f5b85031abc..edf8a5abd3e 100755 --- a/xt/perltidy.t +++ b/xt/perltidy.t @@ -3,13 +3,13 @@ use Modern::Perl; use Test::PerlTidy; use Test::More; -my @files; -push @files, qx{git ls-files '*.pl' '*.PL' '*.pm' '*.t' ':(exclude)Koha/Schema/Result' ':(exclude)Koha/Schema.pm'}; -push @files, qx{git ls-files svc opac/svc}; # Files without extension +use Koha::Devel::Files; + +my $dev_files = Koha::Devel::Files->new( { context => 'tidy' } ); +my @files = $dev_files->ls_perl_files; plan tests => scalar @files; for my $file (@files) { - chomp $file; ok( Test::PerlTidy::is_file_tidy($file) ); } diff --git a/xt/pl_valid.t b/xt/pl_valid.t index 028710deb20..ec7b8f5994c 100755 --- a/xt/pl_valid.t +++ b/xt/pl_valid.t @@ -24,17 +24,10 @@ use Pod::Checker; use Parallel::ForkManager; use Sys::CPU; -my @files; -push @files, qx{git ls-files '*.pl' '*.PL' '*.pm' '*.t'}; -push @files, qx{git ls-files svc opac/svc}; # Files without extension -chomp for @files; +use Koha::Devel::Files; -my @exceptions = qw( - Koha/Account/Credit.pm - Koha/Account/Debit.pm - Koha/Old/Hold.pm - misc/translator/TmplTokenizer.pm -); +my $dev_files = Koha::Devel::Files->new( { context => 'valid' } ); +my @files = $dev_files->ls_perl_files; my $ncpu; if ( $ENV{KOHA_PROVE_CPUS} ) { @@ -48,10 +41,6 @@ my $pm = Parallel::ForkManager->new($ncpu); plan tests => scalar(@files) + 1; for my $file (@files) { - if ( grep { $file eq $_ } @exceptions ) { - pass("$file is skipped - exception"); - next; - } $pm->start and next; my $output = `perl -cw '$file' 2>&1`; chomp $output; diff --git a/xt/single_quotes.t b/xt/single_quotes.t index 0e84e4fc0e6..a0e7413f9bb 100755 --- a/xt/single_quotes.t +++ b/xt/single_quotes.t @@ -21,20 +21,15 @@ use Modern::Perl; use Test::More tests => 2; use File::Slurp qw( read_file ); -my @files; +use Koha::Devel::Files; -# OPAC -push @files, `git ls-files 'koha-tmpl/opac-tmpl/bootstrap/en/*.tt'`; -push @files, `git ls-files 'koha-tmpl/opac-tmpl/bootstrap/en/*.inc'`; +my $dev_files = Koha::Devel::Files->new; +my @files = $dev_files->ls_tt_files; -# Staff -push @files, `git ls-files 'koha-tmpl/intranet-tmpl/prog/en/*.tt'`; -push @files, `git ls-files 'koha-tmpl/intranet-tmpl/prog/en/*.inc'`; ok( @files > 0, 'We should test something' ); my @errors; for my $file (@files) { - chomp $file; my @lines = sort grep /\_\(\'/, read_file($file); push @errors, { name => $file, lines => \@lines } if @lines; } diff --git a/xt/tt_tidy.t b/xt/tt_tidy.t index c97ce7da545..650bd100c81 100755 --- a/xt/tt_tidy.t +++ b/xt/tt_tidy.t @@ -23,7 +23,10 @@ use Test::Strict; use Parallel::ForkManager; use Sys::CPU; -my @tt_files = qx{git ls-files '*.tt' '*.inc'}; +use Koha::Devel::Files; + +my $dev_files = Koha::Devel::Files->new( { context => 'tidy' } ); +my @tt_files = $dev_files->ls_perl_files; $Test::Strict::TEST_STRICT = 0; @@ -39,7 +42,6 @@ my $pm = Parallel::ForkManager->new($ncpu); foreach my $filepath (@tt_files) { $pm->start and next; - chomp $filepath; my $tidy = qx{perl misc/devel/tidy.pl --silent --no-write $filepath}; my $content = read_file $filepath; ok( $content eq $tidy, "$filepath should be kept tidy" ); -- 2.50.0