Blame t/lib/Test/RRA/Config.pm

Packit Service d987f3
# Configuration for Perl test cases.
Packit Service d987f3
#
Packit Service d987f3
# In order to reuse the same Perl test cases in multiple packages, I use a
Packit Service d987f3
# configuration file to store some package-specific data.  This module loads
Packit Service d987f3
# that configuration and provides the namespace for the configuration
Packit Service d987f3
# settings.
Packit Service d987f3
Packit Service d987f3
package Test::RRA::Config;
Packit Service d987f3
Packit Service d987f3
use 5.006;
Packit Service d987f3
use strict;
Packit Service d987f3
use warnings;
Packit Service d987f3
Packit Service d987f3
# For Perl 5.006 compatibility.
Packit Service d987f3
## no critic (ClassHierarchies::ProhibitExplicitISA)
Packit Service d987f3
Packit Service d987f3
use Exporter;
Packit Service d987f3
use Test::More;
Packit Service d987f3
Packit Service d987f3
# Declare variables that should be set in BEGIN for robustness.
Packit Service d987f3
our (@EXPORT_OK, @ISA, $VERSION);
Packit Service d987f3
Packit Service d987f3
# Set $VERSION and everything export-related in a BEGIN block for robustness
Packit Service d987f3
# against circular module loading (not that we load any modules, but
Packit Service d987f3
# consistency is good).
Packit Service d987f3
BEGIN {
Packit Service d987f3
    @ISA       = qw(Exporter);
Packit Service d987f3
    @EXPORT_OK = qw(
Packit Service d987f3
      $COVERAGE_LEVEL @COVERAGE_SKIP_TESTS @CRITIC_IGNORE $LIBRARY_PATH
Packit Service d987f3
      $MINIMUM_VERSION %MINIMUM_VERSION @MODULE_VERSION_IGNORE
Packit Service d987f3
      @POD_COVERAGE_EXCLUDE @STRICT_IGNORE @STRICT_PREREQ
Packit Service d987f3
    );
Packit Service d987f3
Packit Service d987f3
    # This version should match the corresponding rra-c-util release, but with
Packit Service d987f3
    # two digits for the minor version, including a leading zero if necessary,
Packit Service d987f3
    # so that it will sort properly.
Packit Service d987f3
    $VERSION = '6.02';
Packit Service d987f3
}
Packit Service d987f3
Packit Service d987f3
# If C_TAP_BUILD or C_TAP_SOURCE are set in the environment, look for
Packit Service d987f3
# data/perl.conf under those paths for a C Automake package.  Otherwise, look
Packit Service d987f3
# in t/data/perl.conf for a standalone Perl module or tests/data/perl.conf for
Packit Service d987f3
# Perl tests embedded in a larger distribution.  Don't use Test::RRA::Automake
Packit Service d987f3
# since it may not exist.
Packit Service d987f3
our $PATH;
Packit Service d987f3
for my $base ($ENV{C_TAP_BUILD}, $ENV{C_TAP_SOURCE}, './t', './tests') {
Packit Service d987f3
    next if !defined($base);
Packit Service d987f3
    my $path = "$base/data/perl.conf";
Packit Service d987f3
    if (-r $path) {
Packit Service d987f3
        $PATH = $path;
Packit Service d987f3
        last;
Packit Service d987f3
    }
Packit Service d987f3
}
Packit Service d987f3
if (!defined($PATH)) {
Packit Service d987f3
    BAIL_OUT('cannot find data/perl.conf');
Packit Service d987f3
}
Packit Service d987f3
Packit Service d987f3
# Pre-declare all of our variables and set any defaults.
Packit Service d987f3
our $COVERAGE_LEVEL = 100;
Packit Service d987f3
our @COVERAGE_SKIP_TESTS;
Packit Service d987f3
our @CRITIC_IGNORE;
Packit Service d987f3
our $LIBRARY_PATH;
Packit Service d987f3
our $MINIMUM_VERSION = '5.008';
Packit Service d987f3
our %MINIMUM_VERSION;
Packit Service d987f3
our @MODULE_VERSION_IGNORE;
Packit Service d987f3
our @POD_COVERAGE_EXCLUDE;
Packit Service d987f3
our @STRICT_IGNORE;
Packit Service d987f3
our @STRICT_PREREQ;
Packit Service d987f3
Packit Service d987f3
# Load the configuration.
Packit Service d987f3
if (!do($PATH)) {
Packit Service d987f3
    my $error = $@ || $! || 'loading file did not return true';
Packit Service d987f3
    BAIL_OUT("cannot load $PATH: $error");
Packit Service d987f3
}
Packit Service d987f3
Packit Service d987f3
1;
Packit Service d987f3
__END__
Packit Service d987f3
Packit Service d987f3
=for stopwords
Packit Service d987f3
Allbery rra-c-util Automake perlcritic .libs namespace subdirectory sublicense
Packit Service d987f3
MERCHANTABILITY NONINFRINGEMENT regexes
Packit Service d987f3
Packit Service d987f3
=head1 NAME
Packit Service d987f3
Packit Service d987f3
Test::RRA::Config - Perl test configuration
Packit Service d987f3
Packit Service d987f3
=head1 SYNOPSIS
Packit Service d987f3
Packit Service d987f3
    use Test::RRA::Config qw($MINIMUM_VERSION);
Packit Service d987f3
    print "Required Perl version is $MINIMUM_VERSION\n";
Packit Service d987f3
Packit Service d987f3
=head1 DESCRIPTION
Packit Service d987f3
Packit Service d987f3
Test::RRA::Config encapsulates per-package configuration for generic Perl test
Packit Service d987f3
programs that are shared between multiple packages using the rra-c-util
Packit Service d987f3
infrastructure.  It handles locating and loading the test configuration file
Packit Service d987f3
for both C Automake packages and stand-alone Perl modules.
Packit Service d987f3
Packit Service d987f3
Test::RRA::Config looks for a file named F<data/perl.conf> relative to the
Packit Service d987f3
root of the test directory.  That root is taken from the environment variables
Packit Service d987f3
C_TAP_BUILD or C_TAP_SOURCE (in that order) if set, which will be the case for
Packit Service d987f3
C Automake packages using C TAP Harness.  If neither is set, it expects the
Packit Service d987f3
root of the test directory to be a directory named F<t> relative to the
Packit Service d987f3
current directory, which will be the case for stand-alone Perl modules.
Packit Service d987f3
Packit Service d987f3
The following variables are supported:
Packit Service d987f3
Packit Service d987f3
=over 4
Packit Service d987f3
Packit Service d987f3
=item $COVERAGE_LEVEL
Packit Service d987f3
Packit Service d987f3
The coverage level achieved by the test suite for Perl test coverage testing
Packit Service d987f3
using Test::Strict, as a percentage.  The test will fail if test coverage less
Packit Service d987f3
than this percentage is achieved.  If not given, defaults to 100.
Packit Service d987f3
Packit Service d987f3
=item @COVERAGE_SKIP_TESTS
Packit Service d987f3
Packit Service d987f3
Directories under F<t> whose tests should be skipped when doing coverage
Packit Service d987f3
testing.  This can be tests that won't contribute to coverage or tests that
Packit Service d987f3
don't run properly under Devel::Cover for some reason (such as ones that use
Packit Service d987f3
taint checking).  F<docs> and F<style> will always be skipped regardless of
Packit Service d987f3
this setting.
Packit Service d987f3
Packit Service d987f3
=item @CRITIC_IGNORE
Packit Service d987f3
Packit Service d987f3
Additional directories to ignore when doing recursive perlcritic testing.  The
Packit Service d987f3
contents of this directory must be either top-level directory names or
Packit Service d987f3
directory names starting with F<tests/>.
Packit Service d987f3
Packit Service d987f3
=item $LIBRARY_PATH
Packit Service d987f3
Packit Service d987f3
Add this directory (or a F<.libs> subdirectory) relative to the top of the
Packit Service d987f3
source tree to LD_LIBRARY_PATH when checking the syntax of Perl modules.  This
Packit Service d987f3
may be required to pick up libraries that are used by in-tree Perl modules so
Packit Service d987f3
that Perl scripts can pass a syntax check.
Packit Service d987f3
Packit Service d987f3
=item $MINIMUM_VERSION
Packit Service d987f3
Packit Service d987f3
Default minimum version requirement for included Perl scripts.  If not given,
Packit Service d987f3
defaults to 5.008.
Packit Service d987f3
Packit Service d987f3
=item %MINIMUM_VERSION
Packit Service d987f3
Packit Service d987f3
Minimum version exceptions for specific directories.  The keys should be
Packit Service d987f3
minimum versions of Perl to enforce.  The value for each key should be a
Packit Service d987f3
reference to an array of either top-level directory names or directory names
Packit Service d987f3
starting with F<tests/>.  All files in those directories will have that
Packit Service d987f3
minimum Perl version constraint imposed instead of $MINIMUM_VERSION.
Packit Service d987f3
Packit Service d987f3
=item @MODULE_VERSION_IGNORE
Packit Service d987f3
Packit Service d987f3
File names to ignore when checking that all modules in a distribution have the
Packit Service d987f3
same version.  Sometimes, some specific modules need separate, special version
Packit Service d987f3
handling, such as modules defining database schemata for DBIx::Class, and
Packit Service d987f3
can't follow the version of the larger package.
Packit Service d987f3
Packit Service d987f3
=item @POD_COVERAGE_EXCLUDE
Packit Service d987f3
Packit Service d987f3
Regexes that match method names that should be excluded from POD coverage
Packit Service d987f3
testing.  Normally, all methods have to be documented in the POD for a Perl
Packit Service d987f3
module, but methods matching any of these regexes will be considered private
Packit Service d987f3
and won't require documentation.
Packit Service d987f3
Packit Service d987f3
=item @STRICT_IGNORE
Packit Service d987f3
Packit Service d987f3
Additional directories to ignore when doing recursive Test::Strict testing for
Packit Service d987f3
C<use strict> and C<use warnings>.  The contents of this directory must be
Packit Service d987f3
either top-level directory names or directory names starting with F<tests/>.
Packit Service d987f3
Packit Service d987f3
=item @STRICT_PREREQ
Packit Service d987f3
Packit Service d987f3
A list of Perl modules that have to be available in order to do meaningful
Packit Service d987f3
Test::Strict testing.  If any of the modules cannot be loaded via C<use>,
Packit Service d987f3
Test::Strict checking will be skipped.  There is currently no way to require
Packit Service d987f3
specific versions of the modules.
Packit Service d987f3
Packit Service d987f3
=back
Packit Service d987f3
Packit Service d987f3
No variables are exported by default, but the variables can be imported into
Packit Service d987f3
the local namespace to avoid long variable names.
Packit Service d987f3
Packit Service d987f3
=head1 AUTHOR
Packit Service d987f3
Packit Service d987f3
Russ Allbery <eagle@eyrie.org>
Packit Service d987f3
Packit Service d987f3
=head1 COPYRIGHT AND LICENSE
Packit Service d987f3
Packit Service d987f3
Copyright 2015, 2016 Russ Allbery <eagle@eyrie.org>
Packit Service d987f3
Packit Service d987f3
Copyright 2013, 2014 The Board of Trustees of the Leland Stanford Junior
Packit Service d987f3
University
Packit Service d987f3
Packit Service d987f3
Permission is hereby granted, free of charge, to any person obtaining a copy
Packit Service d987f3
of this software and associated documentation files (the "Software"), to deal
Packit Service d987f3
in the Software without restriction, including without limitation the rights
Packit Service d987f3
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
Packit Service d987f3
copies of the Software, and to permit persons to whom the Software is
Packit Service d987f3
furnished to do so, subject to the following conditions:
Packit Service d987f3
Packit Service d987f3
The above copyright notice and this permission notice shall be included in all
Packit Service d987f3
copies or substantial portions of the Software.
Packit Service d987f3
Packit Service d987f3
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Packit Service d987f3
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Packit Service d987f3
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
Packit Service d987f3
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Packit Service d987f3
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Packit Service d987f3
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
Packit Service d987f3
SOFTWARE.
Packit Service d987f3
Packit Service d987f3
=head1 SEE ALSO
Packit Service d987f3
Packit Service d987f3
perlcritic(1), Test::MinimumVersion(3), Test::RRA(3), Test::RRA::Automake(3),
Packit Service d987f3
Test::Strict(3)
Packit Service d987f3
Packit Service d987f3
This module is maintained in the rra-c-util package.  The current version is
Packit Service d987f3
available from L<https://www.eyrie.org/~eagle/software/rra-c-util/>.
Packit Service d987f3
Packit Service d987f3
The C TAP Harness test driver and libraries for TAP-based C testing are
Packit Service d987f3
available from L<https://www.eyrie.org/~eagle/software/c-tap-harness/>.
Packit Service d987f3
Packit Service d987f3
=cut