AFS-PAG
view release on metacpan or search on metacpan
t/lib/Test/RRA.pm view on Meta::CPAN
# Helper functions for test programs written in Perl.
#
# This module provides a collection of helper functions used by test programs
# written in Perl. This is a general collection of functions that can be used
# by both C packages with Automake and by stand-alone Perl modules. See
# Test::RRA::Automake for additional functions specifically for C Automake
# distributions.
#
# The canonical version of this file is maintained in the rra-c-util package,
# which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
#
# Written by Russ Allbery <eagle@eyrie.org>
# Copyright 2013, 2014
t/lib/Test/RRA.pm view on Meta::CPAN
BEGIN {
@ISA = qw(Exporter);
@EXPORT_OK = qw(skip_unless_author skip_unless_automated use_prereq);
# This version should match the corresponding rra-c-util release, but with
# two digits for the minor version, including a leading zero if necessary,
# so that it will sort properly.
$VERSION = '5.05';
}
# Skip this test unless author tests are requested. Takes a short description
# of what tests this script would perform, which is used in the skip message.
# Calls plan skip_all, which will terminate the program.
#
# $description - Short description of the tests
#
# Returns: undef
sub skip_unless_author {
my ($description) = @_;
if (!$ENV{AUTHOR_TESTING}) {
plan skip_all => "$description only run for author";
}
return;
}
# Skip this test unless doing automated testing or release testing. This is
# used for tests that should be run by CPAN smoke testing or during releases,
# but not for manual installs by end users. Takes a short description of what
# tests this script would perform, which is used in the skip message. Calls
# plan skip_all, which will terminate the program.
#
# $description - Short description of the tests
#
# Returns: undef
sub skip_unless_automated {
my ($description) = @_;
for my $env (qw(AUTOMATED_TESTING RELEASE_TESTING AUTHOR_TESTING)) {
return if $ENV{$env};
}
plan skip_all => "$description normally skipped";
return;
}
# Attempt to load a module and skip the test if the module could not be
# loaded. If the module could be loaded, call its import function manually.
# If the module could not be loaded, calls plan skip_all, which will terminate
# the program.
#
# The special logic here is based on Test::More and is required to get the
# imports to happen in the caller's namespace.
#
# $module - Name of the module to load
# @imports - Any arguments to import, possibly including a version
#
t/lib/Test/RRA.pm view on Meta::CPAN
local $SIG{__DIE__} = undef;
$result = eval qq{
package $package;
use $module $version \@imports;
1;
};
$error = $@;
$sigdie = $SIG{__DIE__} || undef;
}
# If the use failed for any reason, skip the test.
if (!$result || $error) {
my $name = length($version) > 0 ? "$module $version" : $module;
plan skip_all => "$name required for test";
}
# If the module set $SIG{__DIE__}, we cleared that via local. Restore it.
## no critic (Variables::RequireLocalizedPunctuationVars)
if (defined($sigdie)) {
$SIG{__DIE__} = $sigdie;
}
return;
}
1;
__END__
=for stopwords
Allbery Allbery's DESC bareword sublicense MERCHANTABILITY NONINFRINGEMENT
rra-c-util
=head1 NAME
Test::RRA - Support functions for Perl tests
=head1 SYNOPSIS
use Test::RRA
qw(skip_unless_author skip_unless_automated use_prereq);
# Skip this test unless author tests are requested.
skip_unless_author('Coding style tests');
# Skip this test unless doing automated or release testing.
skip_unless_automated('POD syntax tests');
# Load modules, skipping the test if they're not available.
use_prereq('Perl6::Slurp', 'slurp');
use_prereq('Test::Script::Run', '0.04');
=head1 DESCRIPTION
This module collects utility functions that are useful for Perl test
scripts. It assumes Russ Allbery's Perl module layout and test
conventions and will only be useful for other people if they use the
same conventions.
=head1 FUNCTIONS
None of these functions are imported by default. The ones used by a
script should be explicitly imported.
=over 4
=item skip_unless_author(DESC)
Checks whether AUTHOR_TESTING is set in the environment and skips the
whole test (by calling C<plan skip_all> from Test::More) if it is not.
DESC is a description of the tests being skipped. A space and C<only run
for author> will be appended to it and used as the skip reason.
=item skip_unless_automated(DESC)
Checks whether AUTHOR_TESTING, AUTOMATED_TESTING, or RELEASE_TESTING are
set in the environment and skips the whole test (by calling C<plan
skip_all> from Test::More) if they are not. This should be used by tests
that should not run during end-user installs of the module, but which
should run as part of CPAN smoke testing and release testing.
DESC is a description of the tests being skipped. A space and C<normally
skipped> will be appended to it and used as the skip reason.
=item use_prereq(MODULE[, VERSION][, IMPORT ...])
Attempts to load MODULE with the given VERSION and import arguments. If
this fails for any reason, the test will be skipped (by calling C<plan
skip_all> from Test::More) with a skip reason saying that MODULE is
required for the test.
VERSION will be passed to C<use> as a version bareword if it looks like a
version number. The remaining IMPORT arguments will be passed as the
value of an array.
=back
=head1 AUTHOR
Russ Allbery <eagle@eyrie.org>
t/lib/Test/RRA.pm view on Meta::CPAN
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
=head1 SEE ALSO
Test::More(3), Test::RRA::Automake(3), Test::RRA::Config(3)
This module is maintained in the rra-c-util package. The current version
is available from L<http://www.eyrie.org/~eagle/software/rra-c-util/>.
The functions to control when tests are run use environment variables
defined by the L<Lancaster
Consensus|https://github.com/Perl-Toolchain-Gang/toolchain-site/blob/master/lancaster-consensus.md>.
=cut
t/lib/Test/RRA/Config.pm view on Meta::CPAN
# Configuration for Perl test cases.
#
# In order to reuse the same Perl test cases in multiple packages, I use a
# configuration file to store some package-specific data. This module loads
# that configuration and provides the namespace for the configuration
# settings.
#
# The canonical version of this file is maintained in the rra-c-util package,
# which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
package Test::RRA::Config;
use 5.006;
t/lib/Test/RRA/Config.pm view on Meta::CPAN
1;
__END__
=for stopwords
Allbery rra-c-util Automake perlcritic .libs namespace subdirectory
sublicense MERCHANTABILITY NONINFRINGEMENT
=head1 NAME
Test::RRA::Config - Perl test configuration
=head1 SYNOPSIS
use Test::RRA::Config qw($MINIMUM_VERSION);
print "Required Perl version is $MINIMUM_VERSION\n";
=head1 DESCRIPTION
Test::RRA::Config encapsulates per-package configuration for generic Perl
test programs that are shared between multiple packages using the
rra-c-util infrastructure. It handles locating and loading the test
configuration file for both C Automake packages and stand-alone Perl
modules.
Test::RRA::Config looks for a file named F<data/perl.conf> relative to the
root of the test directory. That root is taken from the environment
variables BUILD or SOURCE (in that order) if set, which will be the case
for C Automake packages using C TAP Harness. If neither is set, it
expects the root of the test directory to be a directory named F<t>
relative to the current directory, which will be the case for stand-alone
Perl modules.
The following variables are supported:
=over 4
=item $COVERAGE_LEVEL
The coverage level achieved by the test suite for Perl test coverage
testing using Test::Strict, as a percentage. The test will fail if test
coverage less than this percentage is achieved. If not given, defaults
to 100.
=item @COVERAGE_SKIP_TESTS
Directories under F<t> whose tests should be skipped when doing coverage
testing. This can be tests that won't contribute to coverage or tests
that don't run properly under Devel::Cover for some reason (such as ones
that use taint checking). F<docs> and F<style> will always be skipped
regardless of this setting.
=item @CRITIC_IGNORE
Additional directories to ignore when doing recursive perlcritic testing.
The contents of this directory must be either top-level directory names or
directory names starting with F<tests/>.
=item $LIBRARY_PATH
Add this directory (or a F<.libs> subdirectory) relative to the top of the
source tree to LD_LIBRARY_PATH when checking the syntax of Perl modules.
This may be required to pick up libraries that are used by in-tree Perl
modules so that Perl scripts can pass a syntax check.
=item $MINIMUM_VERSION
Default minimum version requirement for included Perl scripts. If not
given, defaults to 5.008.
=item %MINIMUM_VERSION
Minimum version exceptions for specific directories. The keys should be
minimum versions of Perl to enforce. The value for each key should be a
reference to an array of either top-level directory names or directory
names starting with F<tests/>. All files in those directories will have
that minimum Perl version constraint imposed instead of $MINIMUM_VERSION.
=item @POD_COVERAGE_EXCLUDE
Regexes that match method names that should be excluded from POD coverage
testing. Normally, all methods have to be documented in the POD for a
Perl module, but methods matching any of these regexes will be considered
private and won't require documentation.
=item @STRICT_IGNORE
Additional directories to ignore when doing recursive Test::Strict testing
for C<use strict> and C<use warnings>. The contents of this directory
must be either top-level directory names or directory names starting with
F<tests/>.
=item @STRICT_PREREQ
A list of Perl modules that have to be available in order to do meaningful
Test::Strict testing. If any of the modules cannot be loaded via C<use>,
Test::Strict checking will be skipped. There is currently no way to
require specific versions of the modules.
=back
No variables are exported by default, but the variables can be imported
into the local namespace to avoid long variable names.
=head1 AUTHOR
t/lib/Test/RRA/Config.pm view on Meta::CPAN
DEALINGS IN THE SOFTWARE.
=head1 SEE ALSO
perlcritic(1), Test::MinimumVersion(3), Test::RRA(3),
Test::RRA::Automake(3), Test::Strict(3)
This module is maintained in the rra-c-util package. The current version
is available from L<http://www.eyrie.org/~eagle/software/rra-c-util/>.
The C TAP Harness test driver and libraries for TAP-based C testing are
available from L<http://www.eyrie.org/~eagle/software/c-tap-harness/>.
=cut
( run in 1.952 second using v1.01-cache-2.11-cpan-5a3173703d6 )