From 0145069edfe727927c3f9646b85e0ed468e52538 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Wed, 3 Jul 2024 15:14:27 +0200 Subject: [PATCH] Bug 37245: Add test script that runs `perl -c` on all Perl files and minor changes to Koha::Localization and Koha::MarcOverlayRules to make tests pass Test plan: - Run `prove xt/perl-check.t` - Wait... (it took ~15 minutes for me) - Should be green at the end Signed-off-by: David Nind --- Koha/Localization.pm | 1 + Koha/MarcOverlayRules.pm | 3 ++- xt/perl-check.t | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100755 xt/perl-check.t diff --git a/Koha/Localization.pm b/Koha/Localization.pm index 90201b8870..7e91d76a11 100644 --- a/Koha/Localization.pm +++ b/Koha/Localization.pm @@ -18,6 +18,7 @@ package Koha::Localization; use Modern::Perl; use Koha::Database; +use Koha::Caches; use base qw(Koha::Object); diff --git a/Koha/MarcOverlayRules.pm b/Koha/MarcOverlayRules.pm index b874f7cd07..99af52f1de 100644 --- a/Koha/MarcOverlayRules.pm +++ b/Koha/MarcOverlayRules.pm @@ -17,9 +17,10 @@ package Koha::MarcOverlayRules; use Modern::Perl; use List::Util qw(first); -use Koha::MarcOverlayRule; use Carp; +use Koha::Caches; +use Koha::MarcOverlayRule; use Koha::Exceptions::MarcOverlayRule; use Try::Tiny; use Scalar::Util qw(looks_like_number); diff --git a/xt/perl-check.t b/xt/perl-check.t new file mode 100755 index 0000000000..1ce1bb3f0f --- /dev/null +++ b/xt/perl-check.t @@ -0,0 +1,40 @@ +#!/usr/bin/perl + +use Modern::Perl; +use sigtrap qw/die normal-signals/; + +use Cwd qw(realpath); +use File::Basename; +use File::Find; +use File::Spec; +use FindBin; +use Test::More; + +my $root = realpath("$FindBin::RealBin/.."); + +my @filepaths; +sub wanted { + my $filepath = $File::Find::name; + if ($filepath =~ /\.(pm|pl)$/) { + push @filepaths, $filepath; + } +} + +find( { wanted => \&wanted, no_chdir => 1 }, $root ); + +plan tests => scalar @filepaths; + +foreach my $filepath (@filepaths) { + my $rel_path = File::Spec->abs2rel($filepath, $root); + my $cmd = sprintf('perl -c "%s" 2>&1', $filepath); + + # FIXME It's the only file that requires a specific @INC + # We should move misc/translator/*.pm to Koha namespace + if ($rel_path eq 'misc/translator/TmplTokenizer.pm') { + my $inc = dirname($filepath); + $cmd = sprintf('perl -I "%s" -c "%s" 2>&1', $inc, $filepath); + } + + my $output = `$cmd`; + like($output, qr/syntax OK/, $rel_path); +} -- 2.39.2