Bugzilla – Attachment 182382 Details for
Bug 39876
Centralize listing of files from our codebase
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 39876: Apply module to other tests
Bug-39876-Apply-module-to-other-tests.patch (text/plain), 11.51 KB, created by
David Nind
on 2025-05-13 13:40:00 UTC
(
hide
)
Description:
Bug 39876: Apply module to other tests
Filename:
MIME Type:
Creator:
David Nind
Created:
2025-05-13 13:40:00 UTC
Size:
11.51 KB
patch
obsolete
>From a53cd08924cf7bde16b2d7457970ac5bf06f172f Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >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 <david@davidnind.com> >--- > 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 fb339ef839..d23d54a175 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 781d1acd97..e31799ca51 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 b039664083..53e32ddf1b 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 c30a0df74d..9f73784554 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 c10d7ee6b1..59610f9d28 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 0aefa3707c..425c73921e 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 840d8b994b..31a3f2b50f 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 f5b85031ab..edf8a5abd3 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 028710deb2..ec7b8f5994 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 0e84e4fc0e..a0e7413f9b 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 c97ce7da54..650bd100c8 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.39.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 39876
:
182305
|
182306
|
182307
|
182344
|
182345
|
182346
|
182354
|
182380
|
182381
|
182382
|
182417
|
182461
|
183618
|
183619
|
183620
|
183621
|
183622
|
183623
|
183625