Blame t/style/coverage.t

Packit e6c7a3
#!/usr/bin/perl
Packit e6c7a3
#
Packit e6c7a3
# Test Perl code for test coverage.
Packit e6c7a3
#
Packit e6c7a3
# The canonical version of this file is maintained in the rra-c-util package,
Packit e6c7a3
# which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
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 File::Spec;
Packit e6c7a3
use Test::More;
Packit e6c7a3
use Test::RRA qw(skip_unless_author use_prereq);
Packit e6c7a3
use Test::RRA::Config qw($COVERAGE_LEVEL @COVERAGE_SKIP_TESTS);
Packit e6c7a3
Packit e6c7a3
# Skip code coverage unless author tests are enabled since it takes a long
Packit e6c7a3
# time, is sensitive to versions of various libraries, and does not detect
Packit e6c7a3
# functionality problems.
Packit e6c7a3
skip_unless_author('Coverage tests');
Packit e6c7a3
Packit e6c7a3
# Load prerequisite modules.
Packit e6c7a3
use_prereq('Devel::Cover');
Packit e6c7a3
use_prereq('Test::Strict');
Packit e6c7a3
Packit e6c7a3
# Build a list of test directories to use for coverage.
Packit e6c7a3
my %ignore = map { $_ => 1 } qw(data docs style), @COVERAGE_SKIP_TESTS;
Packit e6c7a3
opendir(my $testdir, 't') or BAIL_OUT("cannot open t: $!");
Packit e6c7a3
my @t_dirs = readdir($testdir) or BAIL_OUT("cannot read t: $!");
Packit e6c7a3
closedir($testdir) or BAIL_OUT("cannot close t: $!");
Packit e6c7a3
Packit e6c7a3
# Filter out ignored and system directories.
Packit e6c7a3
@t_dirs = grep { !$ignore{$_} } File::Spec->no_upwards(@t_dirs);
Packit e6c7a3
Packit e6c7a3
# Prepend the t directory name to the directories.
Packit e6c7a3
@t_dirs = map { File::Spec->catfile('t', $_) } @t_dirs;
Packit e6c7a3
Packit e6c7a3
# Disable POD coverage; that's handled separately and is confused by
Packit e6c7a3
# autoloading.
Packit e6c7a3
$Test::Strict::DEVEL_COVER_OPTIONS
Packit e6c7a3
  = '-coverage,statement,branch,condition,subroutine';
Packit e6c7a3
Packit e6c7a3
# Do the coverage analysis.
Packit e6c7a3
all_cover_ok($COVERAGE_LEVEL, @t_dirs);
Packit e6c7a3
Packit e6c7a3
# Hack to suppress "used only once" warnings.
Packit e6c7a3
END { $Test::Strict::DEVEL_COVER_OPTIONS = q{} }