From 20095f3196fb0da4a7fa64918467562a5c6c1154 Mon Sep 17 00:00:00 2001 From: Russ Allbery Date: Mon, 6 Jan 2014 21:09:55 -0800 Subject: Update Test::RRA modules from the current rra-c-util Further documentation of the changes will come later when the rest of rra-c-util files have been updated and the package makes more use of these modules, but this fixes a spelling error test failure. Change-Id: Ia885c4ab103235a1f6a2bf2b86d5a32c93751d89 Reviewed-on: https://gerrit.stanford.edu/1371 Reviewed-by: Russ Allbery Tested-by: Russ Allbery --- tests/tap/perl/Test/RRA/Automake.pm | 69 ++++++++++++++++++++++++++++++++++--- tests/tap/perl/Test/RRA/Config.pm | 23 +++++++++---- 2 files changed, 80 insertions(+), 12 deletions(-) (limited to 'tests/tap/perl/Test/RRA') diff --git a/tests/tap/perl/Test/RRA/Automake.pm b/tests/tap/perl/Test/RRA/Automake.pm index 5dde32d..b80a8fe 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 . # -# Written by Russ Allbery +# Written by Russ Allbery # 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.00'; } # 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 +Russ Allbery =head1 COPYRIGHT AND LICENSE diff --git a/tests/tap/perl/Test/RRA/Config.pm b/tests/tap/perl/Test/RRA/Config.pm index cfa3ad5..5c3df7b 100644 --- a/tests/tap/perl/Test/RRA/Config.pm +++ b/tests/tap/perl/Test/RRA/Config.pm @@ -30,13 +30,13 @@ 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 ); # 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.00'; } # If BUILD or SOURCE are set in the environment, look for data/perl.conf under @@ -64,6 +64,7 @@ our $LIBRARY_PATH; our $MINIMUM_VERSION = '5.008'; our %MINIMUM_VERSION; our @POD_COVERAGE_EXCLUDE; +our @STRICT_IGNORE; # Load the configuration. if (!do($PATH)) { @@ -75,8 +76,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 +131,7 @@ directory names starting with F. =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 +156,13 @@ 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 and C. The contents of this directory +must be either top-level directory names or directory names starting with +F. + =back No variables are exported by default, but the variables can be imported @@ -162,7 +170,7 @@ into the local namespace to avoid long variable names. =head1 AUTHOR -Russ Allbery +Russ Allbery =head1 COPYRIGHT AND LICENSE @@ -189,7 +197,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. -- cgit v1.2.3