Skip to content
This repository has been archived by the owner on Jun 6, 2021. It is now read-only.

Commit

Permalink
check if version numbers are consistent in all the modules
Browse files Browse the repository at this point in the history
  • Loading branch information
szabgab committed Oct 17, 2014
1 parent 4b32d37 commit faae338
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/Test/Version.pm
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ sub import { ## no critic qw( Subroutines::RequireArgUnpacking Subroutines::Requ
: 1
;

$cfg->{consistent}
= defined $cfg->{consistent} ? $cfg->{consistent}
: 0
;

my $mmv = version->parse( $Module::Metadata::VERSION );
my $rec = version->parse( '1.000020' );
if ( $mmv >= $rec && ! defined $cfg->{ignore_unindexable} ) {
Expand All @@ -48,6 +53,8 @@ sub import { ## no critic qw( Subroutines::RequireArgUnpacking Subroutines::Requ
}

my $version_counter = 0;
my $version_number;
my $consistent = 1;

my $test = Test::Builder->new;

Expand All @@ -67,6 +74,10 @@ sub version_ok {
}
my $version = $info->version;

if (not defined $version) {
$consistent = 0;
}

if ( not $version and not $cfg->{has_version} ) {
$test->skip( 'No version was found in "'
. $file
Expand All @@ -85,6 +96,13 @@ sub version_ok {
return 0;
}

unless (defined $version_number) {
$version_number = $version;
}
if ($version ne $version_number) {
$consistent = 0;
}

unless ( is_lax( $version ) ) {
$test->ok( 0, $name );
$test->diag( "The version '$version' found in '$file' is invalid." );
Expand Down Expand Up @@ -125,6 +143,12 @@ sub version_all_ok {
version_ok( $file );
}

if ($cfg->{consistent} and not $consistent) {
$test->ok( 0, $name );
$test->diag('The version numbers in this distribution are not the same');
return;
}

# has at least 1 version in the dist
if ( not $cfg->{has_version} and $version_counter < 1 ) {
$test->ok( 0, $name );
Expand Down
28 changes: 28 additions & 0 deletions t/consistent.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/perl
use 5.006;
use strict;
use warnings;
use Test::Tester;
use Test::More;
use Test::Version version_all_ok => {
has_version => 0,
ignore_unindexable => 0,
consistent => 1,
};

my ( $premature, @results ) = run_tests(
sub {
version_all_ok('corpus/consistent');
}
);

is( scalar(@results), 3, 'correct number of results' );

my @oks = map { $_->{ok} } @results;

note( 'unsorted oks: ', @oks );

is_deeply( [sort @oks], [1, 1, 1], 'oks are ok' );

done_testing;

28 changes: 28 additions & 0 deletions t/inconsistent.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/perl
use 5.006;
use strict;
use warnings;
use Test::Tester;
use Test::More;
use Test::Version version_all_ok => {
has_version => 0,
ignore_unindexable => 0,
consistent => 1,
};

my ( $premature, @results ) = run_tests(
sub {
version_all_ok('corpus/inconsistent');
}
);

is( scalar(@results), 3, 'correct number of results' );

my @oks = map { $_->{ok} } @results;

note( 'unsorted oks: ', @oks );

is_deeply( [sort @oks], [0, 1, 1], 'oks are ok' );

done_testing;

28 changes: 28 additions & 0 deletions t/missing-has-version.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/perl
use 5.006;
use strict;
use warnings;
use Test::Tester;
use Test::More;
use Test::Version version_all_ok => {
has_version => 1,
ignore_unindexable => 0,
consistent => 1,
};

my ( $premature, @results ) = run_tests(
sub {
version_all_ok('corpus/missing');
}
);

is( scalar(@results), 4, 'correct number of results' );

my @oks = map { $_->{ok} } @results;

note( 'unsorted oks: ', @oks );

is_deeply( [sort @oks], [0, 0, 1, 1], 'oks are ok' );

done_testing;

28 changes: 28 additions & 0 deletions t/missing.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/perl
use 5.006;
use strict;
use warnings;
use Test::Tester;
use Test::More;
use Test::Version version_all_ok => {
has_version => 0,
ignore_unindexable => 0,
consistent => 1,
};

my ( $premature, @results ) = run_tests(
sub {
version_all_ok('corpus/missing');
}
);

is( scalar(@results), 4, 'correct number of results' );

my @oks = map { $_->{ok} } @results;

note( 'unsorted oks: ', @oks );

is_deeply( [sort @oks], [0, 1, 1, 1], 'oks are ok' );

done_testing;

0 comments on commit faae338

Please sign in to comment.