Perl::Critic::Policy::Bangs::ProhibitNoPlan - Know what you're going to test.


Perl-Critic-Bangs documentation Contained in the Perl-Critic-Bangs distribution.

Index


Code Index:

NAME

Top

Perl::Critic::Policy::Bangs::ProhibitNoPlan - Know what you're going to test.

AFFILIATION

Top

This Policy is part of the Perl::Critic::Bangs distribution.

DESCRIPTION

Top

Test::More should be given a plan indicting the number of tests to be run. This policy searches for instances of Test::More called with "no_plan".

CONFIGURATION

Top

This Policy is not configurable except for the standard options.

AUTHOR

Top

Andrew Moore <amoore@mooresystems.com>

ACKNOWLEDGMENTS

Top

Adapted from policies by Jeffrey Ryan Thalhammer <thaljef@cpan.org>, Based on App::Fluff by Andy Lester, "<andy at petdance.com>"

COPYRIGHT

Top


Perl-Critic-Bangs documentation Contained in the Perl-Critic-Bangs distribution.

package Perl::Critic::Policy::Bangs::ProhibitNoPlan;

use strict;
use warnings;
use Perl::Critic::Utils;
use base 'Perl::Critic::Policy';

our $VERSION = '1.08';

sub supported_parameters { return ()                             }
sub default_severity     { return $SEVERITY_LOW                  }
sub default_themes       { return qw( bangs tests )              }
sub applies_to           { return 'PPI::Token::QuoteLike::Words' }

#---------------------------------------------------------------------------

sub violates {
    my ( $self, $elem, $doc ) = @_;


    if ( $elem =~ qr/\bno_plan\b/ ) {
        # Make sure that the previous sibling was Test::More, or return
        my $sib = $elem->sprevious_sibling() || return;
        $sib->isa('PPI::Token::Word') && $sib eq 'Test::More' || return;

        my $desc = q(Test::More with "no_plan" found);
        my $expl = q(Test::More should be given a plan indicating the number of tests run);
        return $self->violation( $desc, $expl, $elem );
    }

    return;
}

1;

__END__

#---------------------------------------------------------------------------