Blame t/style/critic.t

Packit e6c7a3
#!/usr/bin/perl
Packit e6c7a3
#
Packit e6c7a3
# Check for perlcritic errors in all code.
Packit e6c7a3
#
Packit e6c7a3
# If author tests are enabled, check all Perl code in blib/lib, examples, usr,
Packit e6c7a3
# t, and Build.PL for problems uncovered by perlcritic, ignoring template
Packit e6c7a3
# files, junk, and any files explicitly configured to be ignored.
Packit e6c7a3
#
Packit e6c7a3
# Written by Russ Allbery <eagle@eyrie.org>
Packit e6c7a3
# Copyright 2013, 2014
Packit e6c7a3
#     The Board of Trustees of the Leland Stanford Junior University
Packit e6c7a3
#
Packit e6c7a3
# Permission is hereby granted, free of charge, to any person obtaining a
Packit e6c7a3
# copy of this software and associated documentation files (the "Software"),
Packit e6c7a3
# to deal in the Software without restriction, including without limitation
Packit e6c7a3
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
Packit e6c7a3
# and/or sell copies of the Software, and to permit persons to whom the
Packit e6c7a3
# Software is furnished to do so, subject to the following conditions:
Packit e6c7a3
#
Packit e6c7a3
# The above copyright notice and this permission notice shall be included in
Packit e6c7a3
# all copies or substantial portions of the Software.
Packit e6c7a3
#
Packit e6c7a3
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Packit e6c7a3
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Packit e6c7a3
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
Packit e6c7a3
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Packit e6c7a3
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
Packit e6c7a3
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
Packit e6c7a3
# DEALINGS IN THE SOFTWARE.
Packit e6c7a3
Packit e6c7a3
use 5.006;
Packit e6c7a3
use strict;
Packit e6c7a3
use warnings;
Packit e6c7a3
Packit e6c7a3
use lib 't/lib';
Packit e6c7a3
Packit e6c7a3
use Test::More;
Packit e6c7a3
use Test::RRA qw(skip_unless_author use_prereq);
Packit e6c7a3
use Test::RRA::Config qw(@CRITIC_IGNORE);
Packit e6c7a3
Packit e6c7a3
# Skip tests unless we're running author tests since this test is too
Packit e6c7a3
# sensitive to the exact version of Perl::Critic to be generally useful.
Packit e6c7a3
skip_unless_author('Coding style tests');
Packit e6c7a3
Packit e6c7a3
# Load prerequisite modules.
Packit e6c7a3
use_prereq('Perl::Critic::Utils');
Packit e6c7a3
use_prereq('Test::Perl::Critic');
Packit e6c7a3
Packit e6c7a3
# Force the embedded Perl::Tidy check to use the correct configuration.
Packit e6c7a3
local $ENV{PERLTIDY} = 't/data/perltidyrc';
Packit e6c7a3
Packit e6c7a3
# Import the configuration file and run Perl::Critic.
Packit e6c7a3
Test::Perl::Critic->import(-profile => 't/data/perlcriticrc');
Packit e6c7a3
Packit e6c7a3
# By default, Test::Perl::Critic only checks blib.  We also want to check t,
Packit e6c7a3
# Build.PL, and examples.
Packit e6c7a3
my @files = Perl::Critic::Utils::all_perl_files('blib');
Packit e6c7a3
if (!@files) {
Packit e6c7a3
    @files = Perl::Critic::Utils::all_perl_files('lib');
Packit e6c7a3
}
Packit e6c7a3
if (-f 'Build.PL') {
Packit e6c7a3
    push(@files, 'Build.PL');
Packit e6c7a3
}
Packit e6c7a3
for my $dir (qw(examples usr t)) {
Packit e6c7a3
    if (-d $dir) {
Packit e6c7a3
        push(@files, Perl::Critic::Utils::all_perl_files($dir));
Packit e6c7a3
    }
Packit e6c7a3
}
Packit e6c7a3
Packit e6c7a3
# Strip out Autoconf templates or left-over perltidy files.
Packit e6c7a3
@files = grep { !m{ [.](?:in|tdy) }xms } @files;
Packit e6c7a3
Packit e6c7a3
# Strip out ignored files.
Packit e6c7a3
my %ignore = map { $_ => 1 } @CRITIC_IGNORE;
Packit e6c7a3
@files = grep { !$ignore{$_} } @files;
Packit e6c7a3
Packit e6c7a3
# Declare a plan now that we know what we're testing.
Packit e6c7a3
plan tests => scalar @files;
Packit e6c7a3
Packit e6c7a3
# Run the actual tests.
Packit e6c7a3
for my $file (@files) {
Packit e6c7a3
    critic_ok($file);
Packit e6c7a3
}
Packit e6c7a3
Packit e6c7a3
# On Debian with perltidy 20130922-1, a perltidy.LOG file gets left behind in
Packit e6c7a3
# the current directory.  Remove it if it exists.
Packit e6c7a3
unlink('perltidy.LOG');