From 922c7668a5da5ba20f40a577718f4734c9d60d84 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 16 May 2023 12:52:22 +0200 Subject: [PATCH] Bug 33743: Make xt/find-missing-filters.t and xt/single_quotes.t check directories in git index only --- xt/find-missing-filters.t | 35 ++++++++----------------------- xt/single_quotes.t | 43 +++++++++++++++------------------------ 2 files changed, 25 insertions(+), 53 deletions(-) diff --git a/xt/find-missing-filters.t b/xt/find-missing-filters.t index 6b7e80f4aa3..2cd461a56a4 100755 --- a/xt/find-missing-filters.t +++ b/xt/find-missing-filters.t @@ -17,40 +17,23 @@ use Modern::Perl; use Test::More tests => 1; -use File::Find; -use File::Slurp; +use File::Slurp qw( read_file ); use Data::Dumper; use t::lib::QA::TemplateFilters; -my @themes; - -# OPAC themes -my $opac_dir = 'koha-tmpl/opac-tmpl'; -opendir ( my $dh, $opac_dir ) or die "can't opendir $opac_dir: $!"; -for my $theme ( grep { not /^\.|lib|js|xslt/ } readdir($dh) ) { - push @themes, "$opac_dir/$theme/en"; -} -close $dh; - -# STAFF themes -my $staff_dir = 'koha-tmpl/intranet-tmpl'; -opendir ( $dh, $staff_dir ) or die "can't opendir $staff_dir: $!"; -for my $theme ( grep { not /^\.|lib|js/ } readdir($dh) ) { - push @themes, "$staff_dir/$theme/en"; -} -close $dh; - my @files; -sub wanted { - my $name = $File::Find::name; - push @files, $name - if $name =~ m[\.(tt|inc)$] and -f $name; -} -find({ wanted => \&wanted, no_chdir => 1 }, @themes ); +# 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 @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/single_quotes.t b/xt/single_quotes.t index 402b51cc64b..2c88d78c335 100755 --- a/xt/single_quotes.t +++ b/xt/single_quotes.t @@ -19,39 +19,28 @@ use Modern::Perl; use Test::More tests => 1; -use File::Find; +use File::Slurp qw( read_file ); -my @themes; +my @files; -# OPAC themes -my $opac_dir = 'koha-tmpl/opac-tmpl'; -opendir ( my $dh, $opac_dir ) or die "can't opendir $opac_dir: $!"; -for my $theme ( grep { not /^\.|lib|js|xslt/ } readdir($dh) ) { - push @themes, "$opac_dir/$theme/en"; -} -close $dh; +# 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 themes -my $staff_dir = 'koha-tmpl/intranet-tmpl'; -opendir ( $dh, $staff_dir ) or die "can't opendir $staff_dir: $!"; -for my $theme ( grep { not /^\.|lib|js/ } readdir($dh) ) { - push @themes, "$staff_dir/$theme/en"; -} -close $dh; +# 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 @files; -find( - sub { - open my $fh, '<', $_ or die "Could not open $_: $!"; - my @lines = sort grep /\_\(\'/, <$fh>; - push @files, { name => "$_", lines => \@lines } if @lines; - }, - @themes -); +my @errors; +for my $file ( @files ) { + chomp $file; + my @lines = sort grep /\_\(\'/, read_file($file); + push @errors, { name => $file, lines => \@lines } if @lines; +} -ok( !@files, "Files do not contain single quotes _(' " ) +ok( !@errors, "Files do not contain single quotes _(' " ) or diag( "Files list: \n", join( "\n", - map { $_->{name} . ': ' . join( ', ', @{ $_->{lines} } ) } @files ) + map { $_->{name} . ': ' . join( ', ', @{ $_->{lines} } ) } @errors ) ); -- 2.25.1