From 3872991615bd8d75bce3bf2483cd97a67ae7d69c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tina=20M=C3=BCller?= Date: Mon, 12 Aug 2024 15:32:32 +0200 Subject: [PATCH 1/5] Fix HashKeyQuotes for composed hash keys --- .perlcriticrc | 2 +- .../Policy/{ => OpenQA}/HashKeyQuotes.pm | 4 +++- t/10-perlcritic.t | 11 +++++++++++ t/OpenQA/HashKeyQuotes.run | 19 +++++++++++++++++++ 4 files changed, 34 insertions(+), 2 deletions(-) rename lib/perlcritic/Perl/Critic/Policy/{ => OpenQA}/HashKeyQuotes.pm (85%) create mode 100644 t/10-perlcritic.t create mode 100644 t/OpenQA/HashKeyQuotes.run diff --git a/.perlcriticrc b/.perlcriticrc index 0addc1f..c255157 100644 --- a/.perlcriticrc +++ b/.perlcriticrc @@ -41,7 +41,7 @@ severity = 1 # == Custom Policies # -- Useless quotes on hashes -[HashKeyQuotes] +[OpenQA::HashKeyQuotes] severity = 5 # -- Superfluous use strict/warning. diff --git a/lib/perlcritic/Perl/Critic/Policy/HashKeyQuotes.pm b/lib/perlcritic/Perl/Critic/Policy/OpenQA/HashKeyQuotes.pm similarity index 85% rename from lib/perlcritic/Perl/Critic/Policy/HashKeyQuotes.pm rename to lib/perlcritic/Perl/Critic/Policy/OpenQA/HashKeyQuotes.pm index 1f27af4..edc693c 100644 --- a/lib/perlcritic/Perl/Critic/Policy/HashKeyQuotes.pm +++ b/lib/perlcritic/Perl/Critic/Policy/OpenQA/HashKeyQuotes.pm @@ -1,7 +1,7 @@ # Copyright SUSE LLC # SPDX-License-Identifier: GPL-2.0-or-later -package Perl::Critic::Policy::HashKeyQuotes; +package Perl::Critic::Policy::OpenQA::HashKeyQuotes; use strict; use warnings; @@ -22,6 +22,8 @@ sub applies_to { return qw(PPI::Token::Quote::Single PPI::Token::Quote::Double) sub violates ($self, $elem, $document) { # skip anything that's not a hash key return () unless is_hash_key($elem); + # skip if it has a sibling, e.g. $h{'foo' . 'bar'} + return () if $elem->snext_sibling or $elem->sprevious_sibling; # only some PPI::Token::Quote::* classes implement literal my $k = $elem->can('literal') ? $elem->literal : $elem->string; diff --git a/t/10-perlcritic.t b/t/10-perlcritic.t new file mode 100644 index 0000000..ffb2070 --- /dev/null +++ b/t/10-perlcritic.t @@ -0,0 +1,11 @@ +#!/usr/bin/perl +# Copyright SUSE LLC +# SPDX-License-Identifier: GPL-2.0-or-later + +use strict; +use warnings; +use FindBin '$Bin'; +use lib "$Bin/../lib/perlcritic"; +use Test::Perl::Critic::Policy qw/ all_policies_ok /; + +all_policies_ok(); diff --git a/t/OpenQA/HashKeyQuotes.run b/t/OpenQA/HashKeyQuotes.run new file mode 100644 index 0000000..3a0a0dc --- /dev/null +++ b/t/OpenQA/HashKeyQuotes.run @@ -0,0 +1,19 @@ +my %h; +## name Passing +## failures 0 +## cut + +$h{bare} = 1; +$h{"line\nbreak"} = 2; +$h{'special!'} = 3; +$h{'concatenate_' . 'strings'} = 4; +$h{bare2 } = 5; + +## name Failing +## failures 4 +## cut + +$h{'single'} = 1; +$h{ 'single' } = 2; +$h{"double"} = 3; +$h{"double2" } = 4; From 0d1b4da3028c0c120d018974a1ce250f95bb57ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tina=20M=C3=BCller?= Date: Mon, 12 Aug 2024 16:25:29 +0200 Subject: [PATCH 2/5] Fix SpaceAfterSubroutineName plugin for long sub headers --- .../{ => OpenQA}/RedundantStrictWarning.pm | 2 +- .../{ => OpenQA}/SpaceAfterSubroutineName.pm | 7 +++-- t/OpenQA/SpaceAfterSubroutineName.run | 31 +++++++++++++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) rename lib/perlcritic/Perl/Critic/Policy/{ => OpenQA}/RedundantStrictWarning.pm (96%) rename lib/perlcritic/Perl/Critic/Policy/{ => OpenQA}/SpaceAfterSubroutineName.pm (91%) create mode 100644 t/OpenQA/SpaceAfterSubroutineName.run diff --git a/lib/perlcritic/Perl/Critic/Policy/RedundantStrictWarning.pm b/lib/perlcritic/Perl/Critic/Policy/OpenQA/RedundantStrictWarning.pm similarity index 96% rename from lib/perlcritic/Perl/Critic/Policy/RedundantStrictWarning.pm rename to lib/perlcritic/Perl/Critic/Policy/OpenQA/RedundantStrictWarning.pm index 1f6a3b1..87da8b9 100644 --- a/lib/perlcritic/Perl/Critic/Policy/RedundantStrictWarning.pm +++ b/lib/perlcritic/Perl/Critic/Policy/OpenQA/RedundantStrictWarning.pm @@ -1,7 +1,7 @@ # Copyright SUSE LLC # SPDX-License-Identifier: GPL-2.0-or-later -package Perl::Critic::Policy::RedundantStrictWarning; +package Perl::Critic::Policy::OpenQA::RedundantStrictWarning; use strict; use warnings; diff --git a/lib/perlcritic/Perl/Critic/Policy/SpaceAfterSubroutineName.pm b/lib/perlcritic/Perl/Critic/Policy/OpenQA/SpaceAfterSubroutineName.pm similarity index 91% rename from lib/perlcritic/Perl/Critic/Policy/SpaceAfterSubroutineName.pm rename to lib/perlcritic/Perl/Critic/Policy/OpenQA/SpaceAfterSubroutineName.pm index c796785..b3a9dc6 100644 --- a/lib/perlcritic/Perl/Critic/Policy/SpaceAfterSubroutineName.pm +++ b/lib/perlcritic/Perl/Critic/Policy/OpenQA/SpaceAfterSubroutineName.pm @@ -1,7 +1,7 @@ # Copyright SUSE LLC # SPDX-License-Identifier: GPL-2.0-or-later -package Perl::Critic::Policy::SpaceAfterSubroutineName; +package Perl::Critic::Policy::OpenQA::SpaceAfterSubroutineName; use strict; use warnings; @@ -68,6 +68,8 @@ sub check_complete_sub ($self, $elem, @tokens) { # 5. Whitespace - must be 1 # 6. Structure - the actual code block + my $nsib = $elem->snext_sibling; + my $psib = $elem->sprevious_sibling; return () if _is_surrounded_by_one_space($tokens[2]) && _is_surrounded_by_one_space($tokens[4]); return $self->report_violation($elem); } @@ -77,7 +79,8 @@ sub _is_block ($token) { } sub _is_only_one_space ($token) { - return $token->isa('PPI::Token::Whitespace') && $token->content eq ' '; + # We also allow line breaks, e.g. perltidy forces to break up long subroutine headers + return $token->isa('PPI::Token::Whitespace') && $token->content =~ m/^[ \n]$/; } sub _is_surrounded_by_one_space ($token) { diff --git a/t/OpenQA/SpaceAfterSubroutineName.run b/t/OpenQA/SpaceAfterSubroutineName.run new file mode 100644 index 0000000..ba21304 --- /dev/null +++ b/t/OpenQA/SpaceAfterSubroutineName.run @@ -0,0 +1,31 @@ +## name Passing +## failures 0 +## cut + +sub long ($self, $jobid, $job_labels, $aggregated, $failed_modules, $actually_failed_modules, + $todo = undef) +{ +} + +sub long2 +($x, $y) { +} + +sub a ($x) { +} + +## name Failing +## failures 4 +## cut + +sub foo($x) { +} + +sub foo ($x){ +} + +sub foo ($x) { +} + +sub foo ($x) { +} From a08ab6f8da64bf78db69f13b38bb8c5c1b7f9afa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tina=20M=C3=BCller?= Date: Mon, 12 Aug 2024 16:31:32 +0200 Subject: [PATCH 3/5] Write tests for ArgumentInUseStrictWarnings plugin --- .perlcriticrc | 2 +- .../{ => OpenQA}/ArgumentInUseStrictWarnings.pm | 2 +- t/OpenQA/ArgumentInUseStrictWarnings.run | 12 ++++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) rename lib/perlcritic/Perl/Critic/Policy/{ => OpenQA}/ArgumentInUseStrictWarnings.pm (94%) create mode 100644 t/OpenQA/ArgumentInUseStrictWarnings.run diff --git a/.perlcriticrc b/.perlcriticrc index c255157..638b25b 100644 --- a/.perlcriticrc +++ b/.perlcriticrc @@ -45,5 +45,5 @@ severity = 1 severity = 5 # -- Superfluous use strict/warning. -[RedundantStrictWarning] +[OpenQA::RedundantStrictWarning] equivalent_modules = Test::Most diff --git a/lib/perlcritic/Perl/Critic/Policy/ArgumentInUseStrictWarnings.pm b/lib/perlcritic/Perl/Critic/Policy/OpenQA/ArgumentInUseStrictWarnings.pm similarity index 94% rename from lib/perlcritic/Perl/Critic/Policy/ArgumentInUseStrictWarnings.pm rename to lib/perlcritic/Perl/Critic/Policy/OpenQA/ArgumentInUseStrictWarnings.pm index 4c24edb..fa8cb2c 100644 --- a/lib/perlcritic/Perl/Critic/Policy/ArgumentInUseStrictWarnings.pm +++ b/lib/perlcritic/Perl/Critic/Policy/OpenQA/ArgumentInUseStrictWarnings.pm @@ -1,7 +1,7 @@ # Copyright SUSE LLC # SPDX-License-Identifier: GPL-2.0-or-later -package Perl::Critic::Policy::ArgumentInUseStrictWarnings; +package Perl::Critic::Policy::OpenQA::ArgumentInUseStrictWarnings; use strict; use warnings; diff --git a/t/OpenQA/ArgumentInUseStrictWarnings.run b/t/OpenQA/ArgumentInUseStrictWarnings.run new file mode 100644 index 0000000..1afa28b --- /dev/null +++ b/t/OpenQA/ArgumentInUseStrictWarnings.run @@ -0,0 +1,12 @@ +## name Passing +## failures 0 +## cut + +use strict; +use warnings; + +## name Failing +## failures 1 +## cut + +use warnings 'redefined'; From d8936a791134f8f2acad872ceec819eea8b041f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tina=20M=C3=BCller?= Date: Mon, 12 Aug 2024 16:36:19 +0200 Subject: [PATCH 4/5] Write test for RedundantStrictWarning plugin --- t/OpenQA/RedundantStrictWarning.run | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 t/OpenQA/RedundantStrictWarning.run diff --git a/t/OpenQA/RedundantStrictWarning.run b/t/OpenQA/RedundantStrictWarning.run new file mode 100644 index 0000000..4b28e00 --- /dev/null +++ b/t/OpenQA/RedundantStrictWarning.run @@ -0,0 +1,16 @@ +## name Passing +## failures 0 +## cut + +use Mojo::Base 'DBIx::Class::Core'; + +## name Passing +## failures 0 +## TODO It can be neessary to use two modules that both enable strict +## cut + +use Mojo::Base 'DBIx::Class::Core'; + +use Moose; +extends 'OpenQA::Schema::Result::Jobs'; + From 3968962faf0edc17427b5bf4c0fe1be725799d91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tina=20M=C3=BCller?= Date: Mon, 12 Aug 2024 16:37:40 +0200 Subject: [PATCH 5/5] ci: Run t/ tests Issue: https://progress.opensuse.org/issues/155188 --- .github/workflows/test.yaml | 13 +++++++++++++ Makefile | 6 +++++- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/test.yaml diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..b0ee6e9 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,13 @@ +--- +name: 'Unit Tests' + +on: [push, pull_request] + +jobs: + test: + runs-on: ubuntu-latest + container: + image: perldocker/perl-tester + steps: + - uses: actions/checkout@v4 + - run: make test-t diff --git a/Makefile b/Makefile index 37e0d26..800db43 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ update-deps: tools/update-deps --cpanfile cpanfile .PHONY: test -test: test-tidy test-critic test-yaml test-author +test: test-tidy test-critic test-yaml test-author test-t .PHONY: test-tidy test-tidy: @@ -25,3 +25,7 @@ test-yaml: .PHONY: test-author test-author: prove -l -r xt/ + +.PHONY: test-t +test-t: + prove -l -r t/