diff options
Diffstat (limited to 'tests/tap/perl/Test')
-rw-r--r-- | tests/tap/perl/Test/RRA.pm | 82 | ||||
-rw-r--r-- | tests/tap/perl/Test/RRA/Automake.pm | 69 | ||||
-rw-r--r-- | tests/tap/perl/Test/RRA/Config.pm | 34 |
3 files changed, 150 insertions, 35 deletions
diff --git a/tests/tap/perl/Test/RRA.pm b/tests/tap/perl/Test/RRA.pm index 3035c7a..bb7de7d 100644 --- a/tests/tap/perl/Test/RRA.pm +++ b/tests/tap/perl/Test/RRA.pm @@ -9,8 +9,8 @@ # 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 <rra@stanford.edu> -# Copyright 2013 +# Written by Russ Allbery <eagle@eyrie.org> +# Copyright 2013, 2014 # The Board of Trustees of the Leland Stanford Junior University # # Permission is hereby granted, free of charge, to any person obtaining a @@ -51,29 +51,47 @@ our (@EXPORT_OK, @ISA, $VERSION); # consistency is good). BEGIN { @ISA = qw(Exporter); - @EXPORT_OK = qw(skip_unless_maintainer use_prereq); + @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 = '4.08'; + $VERSION = '5.05'; } -# Skip this test unless maintainer 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. +# 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_maintainer { +sub skip_unless_author { my ($description) = @_; - if (!$ENV{RRA_MAINTAINER_TESTS}) { - plan skip_all => "$description only run for maintainer"; + 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 @@ -91,7 +109,7 @@ sub use_prereq { # If the first import looks like a version, pass it as a bare string. my $version = q{}; - if (@imports >= 1 && $imports[0] =~ m{ \A \d+ (?: [.]\d+ )* \z }xms) { + if (@imports >= 1 && $imports[0] =~ m{ \A \d+ (?: [.][\d_]+ )* \z }xms) { $version = shift(@imports); } @@ -118,7 +136,8 @@ sub use_prereq { # If the use failed for any reason, skip the test. if (!$result || $error) { - plan skip_all => "$module required for test"; + 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. @@ -142,13 +161,17 @@ Test::RRA - Support functions for Perl tests =head1 SYNOPSIS - use Test::RRA qw(skip_unless_maintainer use_prereq); + use Test::RRA + qw(skip_unless_author skip_unless_automated use_prereq); - # Skip this test unless maintainer tests are requested. - skip_unless_maintainer('Coding style tests'); + # 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('File::Slurp'); + use_prereq('Perl6::Slurp', 'slurp'); use_prereq('Test::Script::Run', '0.04'); =head1 DESCRIPTION @@ -165,12 +188,23 @@ script should be explicitly imported. =over 4 -=item skip_unless_maintainer(DESC) +=item skip_unless_author(DESC) -Checks whether RRA_MAINTAINER_TESTS is set in the environment and skips -the whole test (by calling C<plan skip_all> from Test::More) if it is not. +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 maintainer> will be appended to it and used as the skip reason. +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 ...]) @@ -187,11 +221,11 @@ value of an array. =head1 AUTHOR -Russ Allbery <rra@stanford.edu> +Russ Allbery <eagle@eyrie.org> =head1 COPYRIGHT AND LICENSE -Copyright 2013 The Board of Trustees of the Leland Stanford Junior +Copyright 2013, 2014 The Board of Trustees of the Leland Stanford Junior University Permission is hereby granted, free of charge, to any person obtaining a @@ -219,4 +253,8 @@ 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 diff --git a/tests/tap/perl/Test/RRA/Automake.pm b/tests/tap/perl/Test/RRA/Automake.pm index 5dde32d..a064ed9 100644 --- a/tests/tap/perl/Test/RRA/Automake.pm +++ b/tests/tap/perl/Test/RRA/Automake.pm @@ -13,7 +13,7 @@ # 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 <rra@stanford.edu> +# Written by Russ Allbery <eagle@eyrie.org> # Copyright 2013 # The Board of Trustees of the Leland Stanford Junior University # @@ -82,12 +82,12 @@ our (@EXPORT_OK, @ISA, $VERSION); # consistency is good). BEGIN { @ISA = qw(Exporter); - @EXPORT_OK = qw(automake_setup perl_dirs test_file_path); + @EXPORT_OK = qw(automake_setup perl_dirs test_file_path test_tmpdir); # 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 = '4.08'; + $VERSION = '5.05'; } # Perl directories to skip globally for perl_dirs. We ignore the perl @@ -95,6 +95,11 @@ BEGIN { # distribution and has its own standalone test suite. my @GLOBAL_SKIP = qw(.git perl); +# The temporary directory created by test_tmpdir, if any. If this is set, +# attempt to remove the directory stored here on program exit (but ignore +# failure to do so). +my $TMPDIR; + # Perform initial test setup for running a Perl test in an Automake package. # This verifies that BUILD and SOURCE are set and then changes directory to # the SOURCE directory by default. Sets LD_LIBRARY_PATH if the $LIBRARY_PATH @@ -238,12 +243,53 @@ sub test_file_path { return; } +# Create a temporary directory for tests to use for transient files and return +# the path to that directory. The directory is automatically removed on +# program exit. The directory permissions use the current umask. Calls +# BAIL_OUT if the directory could not be created. +# +# Returns: Path to a writable temporary directory +sub test_tmpdir { + my $path; + + # If we already figured out what directory to use, reuse the same path. + # Otherwise, create a directory relative to BUILD if set. + if (defined($TMPDIR)) { + $path = $TMPDIR; + } else { + my $base = defined($ENV{BUILD}) ? $ENV{BUILD} : File::Spec->curdir; + $path = File::Spec->catdir($base, 'tmp'); + } + + # Create the directory if it doesn't exist. + if (!-d $path) { + if (!mkdir($path, 0777)) { + BAIL_OUT("cannot create directory $path: $!"); + } + } + + # Store the directory name for cleanup and return it. + $TMPDIR = $path; + return $path; +} + +# On program exit, remove $TMPDIR if set and if possible. Report errors with +# diag but otherwise ignore them. +END { + if (defined($TMPDIR) && -d $TMPDIR) { + local $! = undef; + if (!rmdir($TMPDIR)) { + diag("cannot remove temporary directory $TMPDIR: $!"); + } + } +} + 1; __END__ =for stopwords Allbery Automake Automake-aware Automake-based rra-c-util ARGS -subdirectories sublicense MERCHANTABILITY NONINFRINGEMENT +subdirectories sublicense MERCHANTABILITY NONINFRINGEMENT umask =head1 NAME @@ -320,11 +366,24 @@ checked for relative to the environment variable BUILD first, and then relative to SOURCE. test_file_path() returns the full path to FILE or calls BAIL_OUT if FILE could not be found. +=item test_tmpdir() + +Create a temporary directory for tests to use for transient files and +return the path to that directory. The directory is created relative to +the BUILD environment variable, which must be set. Permissions on the +directory are set using the current umask. test_tmpdir() returns the full +path to the temporary directory or calls BAIL_OUT if it could not be +created. + +The directory is automatically removed if possible on program exit. +Failure to remove the directory on exit is reported with diag() and +otherwise ignored. + =back =head1 AUTHOR -Russ Allbery <rra@stanford.edu> +Russ Allbery <eagle@eyrie.org> =head1 COPYRIGHT AND LICENSE diff --git a/tests/tap/perl/Test/RRA/Config.pm b/tests/tap/perl/Test/RRA/Config.pm index cfa3ad5..3e77650 100644 --- a/tests/tap/perl/Test/RRA/Config.pm +++ b/tests/tap/perl/Test/RRA/Config.pm @@ -30,13 +30,14 @@ BEGIN { @ISA = qw(Exporter); @EXPORT_OK = qw( $COVERAGE_LEVEL @COVERAGE_SKIP_TESTS @CRITIC_IGNORE $LIBRARY_PATH - $MINIMUM_VERSION %MINIMUM_VERSION @POD_COVERAGE_EXCLUDE + $MINIMUM_VERSION %MINIMUM_VERSION @POD_COVERAGE_EXCLUDE @STRICT_IGNORE + @STRICT_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 = '4.08'; + $VERSION = '5.05'; } # If BUILD or SOURCE are set in the environment, look for data/perl.conf under @@ -64,6 +65,8 @@ our $LIBRARY_PATH; our $MINIMUM_VERSION = '5.008'; our %MINIMUM_VERSION; our @POD_COVERAGE_EXCLUDE; +our @STRICT_IGNORE; +our @STRICT_PREREQ; # Load the configuration. if (!do($PATH)) { @@ -75,8 +78,8 @@ if (!do($PATH)) { __END__ =for stopwords -Allbery rra-c-util Automake perlcritic .libs namespace sublicense -MERCHANTABILITY NONINFRINGEMENT +Allbery rra-c-util Automake perlcritic .libs namespace subdirectory +sublicense MERCHANTABILITY NONINFRINGEMENT =head1 NAME @@ -130,7 +133,7 @@ directory names starting with F<tests/>. =item $LIBRARY_PATH -Add this directory (or a .libs subdirectory) relative to the top of the +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. @@ -155,6 +158,20 @@ 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 @@ -162,11 +179,11 @@ into the local namespace to avoid long variable names. =head1 AUTHOR -Russ Allbery <rra@stanford.edu> +Russ Allbery <eagle@eyrie.org> =head1 COPYRIGHT AND LICENSE -Copyright 2013 The Board of Trustees of the Leland Stanford Junior +Copyright 2013, 2014 The Board of Trustees of the Leland Stanford Junior University Permission is hereby granted, free of charge, to any person obtaining a @@ -189,7 +206,8 @@ DEALINGS IN THE SOFTWARE. =head1 SEE ALSO -Test::RRA(3), Test::RRA::Automake(3) +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/>. |