Skip to content

Commit

Permalink
xt/: add perl-critic and perl-tidy tests
Browse files Browse the repository at this point in the history
Add author tests for code quality to ensure easier and constant
maintainability.

Signed-off-by: Jens Rehsack <[email protected]>
  • Loading branch information
rehsack committed Apr 23, 2018
1 parent 9b8ca22 commit bf31e07
Show file tree
Hide file tree
Showing 8 changed files with 245 additions and 148 deletions.
17 changes: 17 additions & 0 deletions .perltidyrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-b
-bl
-noll
-pt=2
-bt=2
-sbt=2
-vt=0
-vtc=0
-dws
-aws
-nsfs
-asc
-bbt=0
-cab=0
-l=130
-ole=unix
--noblanks-before-comments
63 changes: 27 additions & 36 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@ use 5.008001;

use ExtUtils::MakeMaker;

my %RUN_DEPS = (
'Carp' => 0,
'File::Basename' => 0,
'File::Path' => '2.00',
'File::Spec' => 0,
'FindBin' => 0,
);
my %RUN_DEPS = ();
my %CONFIGURE_DEPS = (
'ExtUtils::MakeMaker' => 0,
);
Expand All @@ -24,7 +18,7 @@ my %TEST_DEPS = (
WriteMakefile1(
MIN_PERL_VERSION => '5.008001',
META_ADD => {
'meta-spec' => { version => 2 },
'meta-spec' => {version => 2},
resources => {
homepage => 'https://metacpan.org/release/Hash-MoreUtils',
repository => {
Expand All @@ -36,7 +30,7 @@ WriteMakefile1(
web => 'http://rt.cpan.org/Public/Dist/Display.html?Name=Hash-MoreUtils',
mailto => '[email protected]',
},
license => 'http://dev.perl.org/licenses/',
license => 'http://dev.perl.org/licenses/',
},
prereqs => {
develop => {
Expand All @@ -49,18 +43,16 @@ WriteMakefile1(
'Test::Pod::Coverage' => 0,
'Test::Pod::Spelling::CommonMistakes' => 0,
'Test::Spelling' => 0,
'Test::Perl::Critic' => 0,
'Test::PerlTidy' => 0,
},
},
configure => {
requires => {%CONFIGURE_DEPS},
},
build => { requires => {%BUILD_DEPS} },
test => { requires => {%TEST_DEPS} },
build => {requires => {%BUILD_DEPS}},
test => {requires => {%TEST_DEPS}},
runtime => {
recommends => {
'File::HomeDir' => '0.50',
'List::MoreUtils' => '0.22',
},
requires => {
%RUN_DEPS,
perl => '5.8.1',
Expand All @@ -72,50 +64,50 @@ WriteMakefile1(
VERSION_FROM => 'lib/Hash/MoreUtils.pm',
ABSTRACT_FROM => 'lib/Hash/MoreUtils.pm',
LICENSE => 'perl',
AUTHOR => [ 'Hans Dieter Pearcey <[email protected]>', 'Jens Rehsack <[email protected]>' ],
AUTHOR => ['Hans Dieter Pearcey <[email protected]>', 'Jens Rehsack <[email protected]>'],
CONFIGURE_REQUIRES => \%CONFIGURE_DEPS,
PREREQ_PM => \%RUN_DEPS,
BUILD_REQUIRES => \%BUILD_DEPS,
TEST_REQUIRES => \%TEST_DEPS,
test => { TESTS => 't/*.t xt/*.t' },
test => {TESTS => 't/*.t xt/*.t'},
);

sub WriteMakefile1
{ # originally written by Alexandr Ciornii, version 0.21. Added by eumm-upgrade.
my %params = @_;
my $eumm_version = $ExtUtils::MakeMaker::VERSION;
$eumm_version = eval $eumm_version;
die "EXTRA_META is deprecated" if ( exists( $params{EXTRA_META} ) );
die "License not specified" if ( !exists( $params{LICENSE} ) );
die "EXTRA_META is deprecated" if (exists($params{EXTRA_META}));
die "License not specified" if (!exists($params{LICENSE}));
$params{TEST_REQUIRES}
and $eumm_version < 6.6303
and $params{BUILD_REQUIRES} = { %{ $params{BUILD_REQUIRES} || {} }, %{ delete $params{TEST_REQUIRES} } };
and $params{BUILD_REQUIRES} = {%{$params{BUILD_REQUIRES} || {}}, %{delete $params{TEST_REQUIRES}}};
#EUMM 6.5502 has problems with BUILD_REQUIRES
$params{BUILD_REQUIRES}
and $eumm_version < 6.5503
and $params{PREREQ_PM} = { %{ $params{PREREQ_PM} || {} }, %{ delete $params{BUILD_REQUIRES} } };
and $params{PREREQ_PM} = {%{$params{PREREQ_PM} || {}}, %{delete $params{BUILD_REQUIRES}}};
ref $params{AUTHOR}
and "ARRAY" eq ref $params{AUTHOR}
and $eumm_version < 6.5702
and $params{AUTHOR} = join( ", ", @{ $params{AUTHOR} } );
delete $params{CONFIGURE_REQUIRES} if ( $eumm_version < 6.52 );
delete $params{MIN_PERL_VERSION} if ( $eumm_version < 6.48 );
delete $params{META_MERGE} if ( $eumm_version < 6.46 );
delete $params{META_ADD}{prereqs} if ( $eumm_version < 6.58 );
delete $params{META_ADD}{'meta-spec'} if ( $eumm_version < 6.58 );
delete $params{META_ADD} if ( $eumm_version < 6.46 );
delete $params{LICENSE} if ( $eumm_version < 6.31 );
delete $params{AUTHOR} if ( $] < 5.005 );
delete $params{ABSTRACT_FROM} if ( $] < 5.005 );
delete $params{BINARY_LOCATION} if ( $] < 5.005 );
and $params{AUTHOR} = join(", ", @{$params{AUTHOR}});
delete $params{CONFIGURE_REQUIRES} if ($eumm_version < 6.52);
delete $params{MIN_PERL_VERSION} if ($eumm_version < 6.48);
delete $params{META_MERGE} if ($eumm_version < 6.46);
delete $params{META_ADD}{prereqs} if ($eumm_version < 6.58);
delete $params{META_ADD}{'meta-spec'} if ($eumm_version < 6.58);
delete $params{META_ADD} if ($eumm_version < 6.46);
delete $params{LICENSE} if ($eumm_version < 6.31);
delete $params{AUTHOR} if ($] < 5.005);
delete $params{ABSTRACT_FROM} if ($] < 5.005);
delete $params{BINARY_LOCATION} if ($] < 5.005);

# more or less taken from Moose' Makefile.PL
if ( $params{CONFLICTS} )
if ($params{CONFLICTS})
{
my $ok = CheckConflicts(%params);
exit(0) if ( $params{PREREQ_FATAL} and not $ok );
exit(0) if ($params{PREREQ_FATAL} and not $ok);
my $cpan_smoker = grep { $_ =~ m/(?:CR_SMOKER|CPAN_REPORTER|AUTOMATED_TESTING)/ } keys %ENV;
unless ( $cpan_smoker || $ENV{PERL_MM_USE_DEFAULT} )
unless ($cpan_smoker || $ENV{PERL_MM_USE_DEFAULT})
{
sleep 4 unless ($ok);
}
Expand All @@ -124,4 +116,3 @@ sub WriteMakefile1

WriteMakefile(%params);
}

23 changes: 13 additions & 10 deletions lib/Hash/MoreUtils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ package Hash::MoreUtils;

use strict;
use warnings;
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $VERSION);

require Exporter;

@ISA = qw(Exporter);
use vars qw(@EXPORT_OK %EXPORT_TAGS $VERSION);
use base 'Exporter';

%EXPORT_TAGS = (
all => [
Expand Down Expand Up @@ -77,7 +74,7 @@ sub slice
{
my ($href, @list) = @_;
@list and return map { $_ => $href->{$_} } @list;
%{$href};
return %{$href};
}

sub slice_exists
Expand All @@ -94,15 +91,18 @@ sub slice_def
return map { $_ => $href->{$_} } grep { defined($href->{$_}) } @list;
}

## no critic (Subroutines::ProhibitSubroutinePrototypes)
sub slice_grep (&@)
{
my ($code, $href, @list) = @_;
local %_ = %{$href};
@list or @list = keys %{$href};
no warnings 'uninitialized';
no warnings 'uninitialized'; ## no critic (TestingAndDebugging::ProhibitNoWarnings)
return map { ($_ => $_{$_}) } grep { $code->($_) } @list;
}

use warnings;

=head2 C<slice_map> HASHREF[, MAP]
Returns a hash containing the (key, value) pair for every
Expand Down Expand Up @@ -143,7 +143,7 @@ sub slice_map
{
my ($href, %map) = @_;
%map and return map { $map{$_} => $href->{$_} } keys %map;
%{$href};
return %{$href};
}

sub slice_exists_map
Expand All @@ -165,10 +165,12 @@ sub slice_grep_map (&@)
my ($code, $href, %map) = @_;
%map or return goto &slice_grep;
local %_ = %{$href};
no warnings 'uninitialized';
no warnings 'uninitialized'; ## no critic (TestingAndDebugging::ProhibitNoWarnings)
return map { ($map{$_} => $_{$_}) } grep { $code->($_) } keys %map;
}

use warnings;

=head2 C<hashsort> [BLOCK,] HASHREF
my @array_of_pairs = hashsort \%hash;
Expand All @@ -190,12 +192,13 @@ sub hashsort
if ($hash)
{
my $package = caller;
no strict 'refs'; ## no critic (TestingAndDebugging::ProhibitNoStrict)
$cmp = sub {
no strict 'refs';
local ${$package . '::a'} = $a;
local ${$package . '::b'} = $b;
$code->();
};
use strict;
}
else
{
Expand Down
7 changes: 4 additions & 3 deletions t/00-load.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

use Test::More tests => 1;

BEGIN {
use_ok( 'Hash::MoreUtils' );
BEGIN
{
use_ok('Hash::MoreUtils');
}

diag( "Testing Hash::MoreUtils $Hash::MoreUtils::VERSION, Perl $], $^X" );
diag("Testing Hash::MoreUtils $Hash::MoreUtils::VERSION, Perl $], $^X");
Loading

0 comments on commit bf31e07

Please sign in to comment.