« lib/Perl/Critic/Policy/Variables/ProhibitPerl4PackageNames.pm
↑ Summary
lib/Perl/Critic/PolicyFactory.pm »
| 1 | package Perl::Critic::Policy::TestingAndDebugging::RequireTestLabels; | ||||||||||
| 2 | |||||||||||
| 3 | 40 | ▶ | use 5.010001; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 40 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 40 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 40 | ▶ | use Readonly; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 40 | ▶ | use List::SomeUtils qw(any); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 40 | ▶ | use Perl::Critic::Utils qw{ | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | :characters :severities :data_conversion :classification :ppi | ||||||||||
| 11 | 40 | }; | |||||||||
| 12 | 40 | ▶ | use parent 'Perl::Critic::Policy'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 40 | our $VERSION = '1.156'; | |||||||||
| 15 | |||||||||||
| 16 | 40 | Readonly::Hash my %LABEL_ARG_POS => ( | |||||||||
| 17 | ok => 1, | ||||||||||
| 18 | is => 2, | ||||||||||
| 19 | isnt => 2, | ||||||||||
| 20 | like => 2, | ||||||||||
| 21 | unlike => 2, | ||||||||||
| 22 | cmp_ok => 3, | ||||||||||
| 23 | is_deeply => 2, | ||||||||||
| 24 | pass => 0, | ||||||||||
| 25 | fail => 0, | ||||||||||
| 26 | ); | ||||||||||
| 27 | |||||||||||
| 28 | #----------------------------------------------------------------------------- | ||||||||||
| 29 | |||||||||||
| 30 | 40 | Readonly::Scalar my $DESC => q{Test without a label}; | |||||||||
| 31 | 40 | Readonly::Scalar my $EXPL => q{Add a label argument to all Test::More functions}; | |||||||||
| 32 | |||||||||||
| 33 | #----------------------------------------------------------------------------- | ||||||||||
| 34 | |||||||||||
| 35 | 91 | ▶ | sub supported_parameters { | ||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 36 | return ( | ||||||||||
| 37 | { | ||||||||||
| 38 | 91 | name => 'modules', | |||||||||
| 39 | description => 'The additional modules to require labels for.', | ||||||||||
| 40 | default_string => $EMPTY, | ||||||||||
| 41 | behavior => 'string list', | ||||||||||
| 42 | list_always_present_values => [ qw( Test::More ) ], | ||||||||||
| 43 | }, | ||||||||||
| 44 | ); | ||||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 74 | ▶ | sub default_severity { return $SEVERITY_MEDIUM } | ||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 48 | 73 | ▶ | sub default_themes { return qw( core maintenance tests ) } | ||||||||
|
Subroutine
default_themes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 49 | 31 | ▶ | sub applies_to { return 'PPI::Token::Word' } | ||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 50 | |||||||||||
| 51 | #----------------------------------------------------------------------------- | ||||||||||
| 52 | |||||||||||
| 53 | 332 | ▶ | sub violates { | ||||||||
|
Subroutine
violates: called CC=5 SCAR=27.4
Pod
documented
| |||||||||||
| 54 | 332 | my ($self, $elem, $doc) = @_; | |||||||||
| 55 | |||||||||||
| 56 | 332 | my $arg_index = $LABEL_ARG_POS{$elem}; | |||||||||
| 57 | 332 | ▶ | return if not defined $arg_index; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | 0 | ▶ | return if not is_function_call($elem); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | 0 | ▶ | return if not $self->_has_test_more($doc); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | |||||||||||
| 61 | # Does the function call have enough arguments? | ||||||||||
| 62 | 0 | my @args = parse_arg_list($elem); | |||||||||
| 63 | 0 | ▶ | return if ( @args > $arg_index ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | |||||||||||
| 65 | 0 | return $self->violation( $DESC, $EXPL, $elem ); | |||||||||
| 66 | } | ||||||||||
| 67 | |||||||||||
| 68 | #----------------------------------------------------------------------------- | ||||||||||
| 69 | |||||||||||
| 70 | 0 | ▶ | sub _has_test_more { | ||||||||
|
Subroutine
_has_test_more: not called CC=2 SCAR=17.9
| |||||||||||
| 71 | 0 | my ( $self, $doc ) = @_; | |||||||||
| 72 | |||||||||||
| 73 | # TODO: This method gets called every time violates() is invoked, | ||||||||||
| 74 | # but it only needs to happen once per document. Perhaps this | ||||||||||
| 75 | # policy should just apply to PPI::Document, and then do its own | ||||||||||
| 76 | # search for method calls. Since Perl::Critic::Document is | ||||||||||
| 77 | # optimized, this should be pretty fast. | ||||||||||
| 78 | |||||||||||
| 79 | 0 | my $includes = $doc->find('PPI::Statement::Include'); | |||||||||
| 80 | 0 | ▶ | return if not $includes; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 81 | 0 | ▶ | return any { exists $self->{_modules}->{$_->module()} } | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 82 | 0 | @{ $includes }; | |||||||||
| 83 | } | ||||||||||
| 84 | |||||||||||
| 85 | 40 | 1; | |||||||||
| 86 | |||||||||||
| 87 | #----------------------------------------------------------------------------- | ||||||||||
| 88 | |||||||||||
| 89 | __END__ | ||||||||||