From 4feab8a987a345e38c44077d1042bf05ec03f0eb Mon Sep 17 00:00:00 2001 From: Russ Allbery Date: Sun, 17 Jan 2016 12:25:15 -0800 Subject: Standardize Perl module versions The versions of all of the wallet Perl modules now match the overall package version except for Wallet::Schema, which is used to version the database schema. Import the test from rra-c-util 5.10 and exclude Wallet::Schema from the tests. Go through all Perl modules and standardize the syntax for setting the version and indicating the required version of Perl. Fix a few other syntax issues while I'm in there. --- tests/perl/module-version-t | 169 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 169 insertions(+) create mode 100755 tests/perl/module-version-t (limited to 'tests/perl/module-version-t') diff --git a/tests/perl/module-version-t b/tests/perl/module-version-t new file mode 100755 index 0000000..a9ebf3b --- /dev/null +++ b/tests/perl/module-version-t @@ -0,0 +1,169 @@ +#!/usr/bin/perl +# +# Check or update the version of embedded Perl modules. +# +# Examines all module files (*.pm) under the perl/lib directory, if it exists, +# and verifies that their $VERSION is set to the same value as the current +# version number as determined by the NEWS file at the top level of the source +# tree (or the current directory if not being run as a test). +# +# When given the --update option, instead fixes all of the Perl modules found +# to have the correct version. + +use 5.006; +use strict; +use warnings; + +# SOURCE may not be set if we're running this script manually to update +# version numbers. If it isn't, assume we're being run from the top of the +# tree. +BEGIN { + if ($ENV{SOURCE}) { + unshift(@INC, "$ENV{SOURCE}/tap/perl"); + } else { + unshift(@INC, 'tests/tap/perl'); + } +} + +use Getopt::Long qw(GetOptions); +use Test::RRA qw(skip_unless_automated); +use Test::RRA::Automake qw(automake_setup); +use Test::RRA::ModuleVersion qw(test_module_versions update_module_versions); + +# Return the current version and, optionally, the package name from the NEWS +# file. Munges the version to be appropriate for Perl if necessary. +# +# Returns: Scalar: The version number of the latest version in NEWS +# List: The version number and the package name +# Throws: Text exception if NEWS is not found or doesn't contain a version +sub news_version { + my ($package, $version); + open(my $news, q{<}, 'NEWS') or die "$0: cannot open NEWS: $!\n"; + SCAN: + while (defined(my $line = <$news>)) { + ## no critic (RegularExpressions::ProhibitEscapedMetacharacters) + if ($line =~ m{ \A ([\w\s-]+) \s ([\d.]+) \s \( }xms) { + ($package, $version) = ($1, $2); + last SCAN; + } + ## use critic + } + close($news) or die "$0: error reading from NEWS: $!\n"; + if (!defined($version)) { + die "$0: cannot find version number in NEWS\n"; + } + + # Munge the version for Perl purposes by ensuring that each component + # has two digits and by dropping the second period. + $version =~ s{ [.] (\d) (?= [.] | \z ) }{.0$1}xmsg; + $version =~ s{ ([.] \d+) [.] (\d+) }{$1$2}xms; + + # Return the appropriate value based on context. + return wantarray ? ($version, $package) : $version; +} + +# Get the package name and version. +my ($version, $package) = news_version(); + +# rra-c-util itself checks the versions of the testing support modules instead +# of an embedded tree of Perl modules. +my $root = ($package eq 'rra-c-util') ? 'tests/tap/perl' : 'perl/lib'; + +# Main routine. We run as either a test suite or as a script to update all of +# the module versions, selecting based on whether we got the -u / --update +# command-line option. +my $update; +Getopt::Long::config('bundling', 'no_ignore_case'); +GetOptions('update|u' => \$update) or exit 1; +if ($update) { + update_module_versions($root, $version); +} else { + skip_unless_automated('Module version tests'); + automake_setup(); + test_module_versions($root, $version); +} +exit 0; +__END__ + +=for stopwords +Allbery sublicense MERCHANTABILITY NONINFRINGEMENT rra-c-util + +=head1 NAME + +module-version-t - Check or update versions of embedded Perl modules + +=head1 SYNOPSIS + +B [B<--update>] + +=head1 REQUIREMENTS + +Perl 5.6.2 or later. + +=head1 DESCRIPTION + +This script has a dual purpose as either a test script or a utility script. +The intent is to assist with maintaining consistent versions between a larger +primarily C project and any embedded Perl modules, supporting both the package +keyword syntax introduced in Perl 5.12 or the older explicit setting of a +$VERSION variable. + +As a test, it reads the current version of a package from the F file and +then looks for any Perl modules in F. (As a special exception, if +the package name as determined from the F file is C, it +looks for Perl modules in F instead.) If it finds any, it +checks that the version number of the Perl module matches the version number +of the package from the F file. These test results are reported with +Test::More, suitable for any TAP harness. + +As a utility script, when run with the B<--update> option, it similarly finds +all Perl modules in F (or F per above) and then +rewrites their version setting to match the version of the package as +determined from the F file. + +=head1 OPTIONS + +=over 4 + +=item B<-u>, B<--update> + +Rather than test the Perl modules for the correct version, update all Perl +modules found in the tree under F to the current version from the +NEWS file. + +=back + +=head1 AUTHOR + +Russ Allbery + +=head1 COPYRIGHT AND LICENSE + +Copyright 2014, 2016 Russ Allbery + +Copyright 2013 The Board of Trustees of the Leland Stanford Junior University + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +=head1 SEE ALSO + +This module is maintained in the rra-c-util package. The current version is +available from L. + +=cut -- cgit v1.2.3 From 57bcc0cb1e8893f6a39c4fcb902d02b920efde1a Mon Sep 17 00:00:00 2001 From: Russ Allbery Date: Sun, 17 Jan 2016 12:38:45 -0800 Subject: Adjust perl/module-version-t to run from tests When run under runtests, it runs with a parent directory of tests, and therefore needs to look for NEWS in ../NEWS. Allow for both paths. --- tests/perl/module-version-t | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'tests/perl/module-version-t') diff --git a/tests/perl/module-version-t b/tests/perl/module-version-t index a9ebf3b..47c22fe 100755 --- a/tests/perl/module-version-t +++ b/tests/perl/module-version-t @@ -37,8 +37,15 @@ use Test::RRA::ModuleVersion qw(test_module_versions update_module_versions); # List: The version number and the package name # Throws: Text exception if NEWS is not found or doesn't contain a version sub news_version { - my ($package, $version); - open(my $news, q{<}, 'NEWS') or die "$0: cannot open NEWS: $!\n"; + my ($package, $version, $news); + for my $path ('NEWS', '../NEWS') { + if (-f $path) { + open($news, q{<}, $path) or die "$0: cannot open $path: $!\n"; + } + } + if (!$news) { + die "$0: cannot find NEWS file\n"; + } SCAN: while (defined(my $line = <$news>)) { ## no critic (RegularExpressions::ProhibitEscapedMetacharacters) -- cgit v1.2.3 From a9ab5b066f6c98fe8265730415c7a6773798e810 Mon Sep 17 00:00:00 2001 From: Russ Allbery Date: Sun, 17 Jan 2016 18:51:36 -0800 Subject: Import new tests/perl/module-version-t from rra-c-util This fixes locating the NEWS file when building out of tree. --- tests/perl/module-version-t | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'tests/perl/module-version-t') diff --git a/tests/perl/module-version-t b/tests/perl/module-version-t index 47c22fe..f1ebf0f 100755 --- a/tests/perl/module-version-t +++ b/tests/perl/module-version-t @@ -69,6 +69,17 @@ sub news_version { return wantarray ? ($version, $package) : $version; } +# Parse command-line arguments. +my $update; +Getopt::Long::config('bundling', 'no_ignore_case'); +GetOptions('update|u' => \$update) or exit 1; + +# If we're not updating, set up for Automake testing. Otherwise, we assume +# we're running from the top of the source tree. +if (!$update) { + automake_setup(); +} + # Get the package name and version. my ($version, $package) = news_version(); @@ -79,14 +90,10 @@ my $root = ($package eq 'rra-c-util') ? 'tests/tap/perl' : 'perl/lib'; # Main routine. We run as either a test suite or as a script to update all of # the module versions, selecting based on whether we got the -u / --update # command-line option. -my $update; -Getopt::Long::config('bundling', 'no_ignore_case'); -GetOptions('update|u' => \$update) or exit 1; if ($update) { update_module_versions($root, $version); } else { skip_unless_automated('Module version tests'); - automake_setup(); test_module_versions($root, $version); } exit 0; -- cgit v1.2.3