| Test-Version documentation | Contained in the Test-Version distribution. |
Test::Version - Check to see that version's in modules are sane
version 0.11
use Test::More; use Test::Version 0.04; # test blib or lib by default version_all_ok(); done_testing;
This module's goal is to be a one stop shop for checking to see that your
versions across your dist are sane. Please ensure that you use version 0.04
or later only, as earlier versions are old code and may not work correctly.
Current feature list:
Tests to insure that all modules checked have a VERSION defined, Can replace Test::HasVersion
Tests to insure that all versions are valid, according to the rules of
version method is_lax. To quote:
The lax criteria corresponds to what is currently allowed by the version parser. All of the following formats are acceptable for dotted-decimal formats strings:
v1.2 1.2345.6 v1.23_4 1.2345 1.2345_01
version_ok( $filename, [ $name ] );Test a single .pm file by passing a path to the function. Checks if the
module has a version, and that it is valid with is_lax.
version_all_ok( [ $directory, [ $name ]] );Test all modules in a directory with version_ok. By default it will check
blib or lib if you haven't passed it a directory.
Will not test Perl 5.12 package version declarations because
Module::Extract::VERSION can't extract them yet.
The goal is to have the functionality of all of these.
Special thanks to particle <particle@cpan.org> for the original
Test::Version and letting me maintain it further.
This software is Copyright (c) 2011 by Caleb Cushing.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
| Test-Version documentation | Contained in the Test-Version distribution. |
package Test::Version; use 5.006; use strict; use warnings; BEGIN { our $VERSION = '0.11'; # VERSION } use parent 'Exporter'; use Test::Builder; use version 0.86 qw( is_lax ); use File::Find::Rule::Perl; use Module::Extract::VERSION; use Test::More; our @EXPORT = qw( version_all_ok ); ## no critic (Modules::ProhibitAutomaticExportation) our @EXPORT_OK = qw( version_ok ); my $test = Test::Builder->new; sub _get_version { my $pm = shift; return my $version = Module::Extract::VERSION->parse_version_safely( $pm ); } sub version_ok { my ( $file, $name ) = @_; $file ||= ''; $name ||= "check version in '$file'"; unless ( $file ) { $test->ok( 0, $name ); $test->diag( "No file passed to version_ok()." ); return 0; } unless ( -e $file ) { $test->ok( 0, $name ); $test->diag( "'$file' doesn't exist." ); return 0; } my $version = _get_version( $file ); unless ( $version ) { $test->ok( 0 , $name ); $test->diag( "No version was found in '$file'." ); return 0; } unless ( is_lax( $version ) ) { $test->ok( 0, $name ); $test->diag( "The version '$version' found in '$file' is invalid." ); return 0; } $test->ok( 1, $name ); return 1; } sub version_all_ok { my ( $dir, $name ) = @_; $dir = defined $dir ? $dir : -d 'blib' ? 'blib' : 'lib' ; # Report failure location correctly - GH #1 local $Test::Builder::Level = $Test::Builder::Level + 1; ## no critic (Variables::ProhibitPackageVars) $name ||= "all modules in $dir have valid versions"; unless ( -d $dir ) { $test->ok( 0, $name ); $test->diag( "$dir does not exist, or is not a directory" ); return; } my @files = File::Find::Rule->perl_module->in( $dir ); foreach my $file ( @files ) { version_ok( $file ); } return; } 1; # ABSTRACT: Check to see that version's in modules are sane __END__