From eca3591d74d4b2c11488c2d5851351c969b0e25c Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 18 Mar 2025 12:13:03 +0100 Subject: [PATCH] Bug 39365: Add tests We exclude (for now) some files that needs additional work: 1. Koha/Account/Credit.pm, Koha/Account/Debit.pm and Koha/Old/Hold.pm "Inconsistent hierarchy during C3 merge of class" 2. misc/translator/TmplTokenizer.pm Can't locate VerboseWarnings.pm in @INC We also ignore some known warnings. Signed-off-by: Emily Lamancusa Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer --- xt/pl_valid.t | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100755 xt/pl_valid.t diff --git a/xt/pl_valid.t b/xt/pl_valid.t new file mode 100755 index 0000000000..028710deb2 --- /dev/null +++ b/xt/pl_valid.t @@ -0,0 +1,83 @@ +#!/usr/bin/env perl + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; +use threads; # used for parallel +use Test::More; +use Test::NoWarnings; +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; + +my @exceptions = qw( + Koha/Account/Credit.pm + Koha/Account/Debit.pm + Koha/Old/Hold.pm + misc/translator/TmplTokenizer.pm +); + +my $ncpu; +if ( $ENV{KOHA_PROVE_CPUS} ) { + $ncpu = $ENV{KOHA_PROVE_CPUS}; +} else { + $ncpu = Sys::CPU::cpu_count(); +} + +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; + if ($?) { + fail("$file has syntax errors"); + diag($output); + } elsif ( $output =~ /^$file syntax OK$/ ) { + pass("$file passed syntax check"); + } else { + my @fails; + for my $line ( split "\n", $output ) { + next if $line =~ m{^$file syntax OK$}; + next if $line =~ m{^Subroutine .* redefined at}; + next if $line =~ m{^Constant subroutine .* redefined at}; + + next if $line =~ m{Name "Lingua::Ispell::path" used only once: possible typo at C4/Tags.pm}; + push @fails, $line; + } + if (@fails) { + fail("$file has syntax warnings."); + diag( join "\n", @fails ); + } else { + pass("$file passed syntax check"); + } + } + $pm->finish; +} + +$pm->wait_all_children;