From 4c1e5a6a58ab8639354128e4c3aee0d6c9deea6f Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Mon, 17 Jul 2023 07:13:38 +0000 Subject: [PATCH] Bug 33745: (follow-up) Add exception to 00-testcritic.t Content-Type: text/plain; charset=utf-8 Test plan: Run t/00-testcritic.t t/00-testcritic_2.t Signed-off-by: Marcel de Rooy --- t/00-testcritic.t | 7 +++++-- t/00-testcritic_2.t | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100755 t/00-testcritic_2.t diff --git a/t/00-testcritic.t b/t/00-testcritic.t index cd3a7af71b..57935293ba 100755 --- a/t/00-testcritic.t +++ b/t/00-testcritic.t @@ -9,9 +9,12 @@ use English qw(-no_match_vars); eval { require Test::Perl::Critic; }; if ( $EVAL_ERROR ) { - my $msg = 'Test::Perl::Critic required to criticise code,'; + my $msg = 'Test::Perl::Critic required to criticise code'; plan( skip_all => $msg ); } Test::Perl::Critic->import( -profile => '.perlcriticrc'); -all_critic_ok('.'); +# Test all perl files excluding Koha/Object.pm, see t/00-testcritic_2.t +my $koha_object_module = ( -e 'Koha/Object.pm' ? '' : 'lib/' ) . 'Koha/Object.pm'; +my @files = grep { $_ ne $koha_object_module } Perl::Critic::Utils::all_perl_files('.'); +all_critic_ok( @files ); diff --git a/t/00-testcritic_2.t b/t/00-testcritic_2.t new file mode 100755 index 0000000000..7885049661 --- /dev/null +++ b/t/00-testcritic_2.t @@ -0,0 +1,16 @@ +#!/usr/bin/env perl + +# Running perlcritic on specific Koha files (as exception) + +use Modern::Perl; +use Test::More tests => 2; +use English qw(-no_match_vars); + +SKIP: { + eval { require Perl::Critic; }; + skip 'Perl::Critic required to criticise code', 2 if $EVAL_ERROR; + my $file = ( -e 'Koha/Object.pm' ? '' : 'lib/' ) . 'Koha/Object.pm'; + my @violations = Perl::Critic->new( -profile => '.perlcriticrc' )->critique($file); + is( @violations, 1, "One violation found in $file" ); + like( $violations[0], qr/Stricture disabled at line/, 'No strict refs found as expected' ); +} -- 2.30.2