From: Vincent Pit Date: Sun, 23 Sep 2012 21:10:12 +0000 (+0200) Subject: Update author tests X-Git-Tag: v0.03~5 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=aa9ca6bb3620015b44c886e95b0ed7b1353dbeee;p=perl%2Fmodules%2Fre-engine-Hooks.git Update author tests --- diff --git a/MANIFEST b/MANIFEST index 972617c..5d8f194 100644 --- a/MANIFEST +++ b/MANIFEST @@ -135,8 +135,10 @@ t/11-call-perl.t t/20-multi.t t/91-pod.t t/92-pod-coverage.t +t/93-pod-spelling.t t/95-portability-files.t t/99-kwalitee.t +t/lib/VPIT/TestHelpers.pm t/re-engine-Hooks-TestDist/Makefile.PL t/re-engine-Hooks-TestDist/TestDist.xs t/re-engine-Hooks-TestDist/lib/re/engine/Hooks/TestDist.pm diff --git a/t/91-pod.t b/t/91-pod.t index f1e1d3e..c2d16af 100644 --- a/t/91-pod.t +++ b/t/91-pod.t @@ -5,6 +5,12 @@ use warnings; use Test::More; -eval "use Test::Pod 1.14"; -plan skip_all => "Test::Pod 1.14 required for testing POD" if $@; +use lib 't/lib'; +use VPIT::TestHelpers; + +load_or_skip('Test::Pod', '1.22', [ ], + 'required for testing POD syntax'); + +eval 'use Test::Pod'; # Make Kwalitee test happy + all_pod_files_ok(); diff --git a/t/92-pod-coverage.t b/t/92-pod-coverage.t index 2625616..950d7bd 100644 --- a/t/92-pod-coverage.t +++ b/t/92-pod-coverage.t @@ -5,8 +5,16 @@ use warnings; use Test::More; -eval "use Test::Pod::Coverage 1.04 (tests => 1)"; -plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" if $@; +use lib 't/lib'; +use VPIT::TestHelpers; + +my $desc = 'required for testing POD coverage'; + +load_or_skip('Test::Pod::Coverage', '1.08', [ tests => 1 ], $desc); +load_or_skip('Pod::Coverage', '0.18', undef, $desc); + +eval 'use Test::Pod::Coverage'; # Make Kwalitee test happy + pod_coverage_ok( 're::engine::Hooks', { diff --git a/t/93-pod-spelling.t b/t/93-pod-spelling.t new file mode 100644 index 0000000..acb2587 --- /dev/null +++ b/t/93-pod-spelling.t @@ -0,0 +1,14 @@ +#!perl -T + +use strict; +use warnings; + +use Test::More; + +use lib 't/lib'; +use VPIT::TestHelpers; + +load_or_skip('Test::Pod::Spelling::CommonMistakes', '1.0', [ ], + 'required for testing POD spelling'); + +all_pod_files_ok(); diff --git a/t/95-portability-files.t b/t/95-portability-files.t index ab541f3..55a9005 100644 --- a/t/95-portability-files.t +++ b/t/95-portability-files.t @@ -5,6 +5,10 @@ use warnings; use Test::More; -eval "use Test::Portability::Files"; -plan skip_all => "Test::Portability::Files required for testing filenames portability" if $@; +use lib 't/lib'; +use VPIT::TestHelpers; + +load_or_skip('Test::Portability::Files', undef, [ ], + 'required for testing filenames portability'); + run_tests(); diff --git a/t/99-kwalitee.t b/t/99-kwalitee.t index 40f3eb0..39c7c18 100644 --- a/t/99-kwalitee.t +++ b/t/99-kwalitee.t @@ -5,14 +5,18 @@ use warnings; use Test::More; -eval { require Parse::RecDescent; 'Parse::RecDescent'->VERSION('1.967006') } - or plan skip_all => 'Parse::RecDescent version 1.967006 or greater required'; +use lib 't/lib'; +use VPIT::TestHelpers; -eval { require Module::ExtractUse; 'Module::ExtractUse'->VERSION('0.24') } - or plan skip_all => 'Module::ExtractUse version 0.24 or greater required'; +my $guard = VPIT::TestHelpers::Guard->new( + sub { unlink for glob 'Debian_CPANTS.txt*' } +); -eval { require Test::Kwalitee; 1 } - or plan skip_all => 'Test::Kwalitee required'; +my $desc = 'required to test kwalitee'; + +load_or_skip('Parse::RecDescent', '1.967006', undef, $desc); +load_or_skip('Module::ExtractUse', '0.24', undef, $desc); +load_or_skip('Test::Kwalitee', '1.01', undef, $desc); SKIP: { eval { Test::Kwalitee->import(tests => [ '-use_strict' ]); }; diff --git a/t/lib/VPIT/TestHelpers.pm b/t/lib/VPIT/TestHelpers.pm new file mode 100644 index 0000000..42ff189 --- /dev/null +++ b/t/lib/VPIT/TestHelpers.pm @@ -0,0 +1,79 @@ +package VPIT::TestHelpers; + +use strict; +use warnings; + +my %exports = ( + load_or_skip => \&load_or_skip, + skip_all => \&skip_all, +); + +sub import { + my $pkg = caller; + while (my ($name, $code) = each %exports) { + no strict 'refs'; + *{$pkg.'::'.$name} = $code; + } +} + +my $test_sub = sub { + my $sub = shift; + my $stash; + if ($INC{'Test/Leaner.pm'}) { + $stash = \%Test::Leaner::; + } else { + require Test::More; + $stash = \%Test::More::; + } + my $glob = $stash->{$sub}; + return $glob ? *$glob{CODE} : undef; +}; + +sub skip_all { $test_sub->('plan')->(skip_all => $_[0]) } + +sub diag { + my $diag = $test_sub->('diag'); + $diag->($_) for @_; +} + +our $TODO; +local $TODO; + +sub load_or_skip { + my ($pkg, $ver, $imports, $desc) = @_; + my $spec = $ver && $ver !~ /^[0._]*$/ ? "$pkg $ver" : $pkg; + local $@; + if (eval "use $spec (); 1") { + $ver = do { no strict 'refs'; ${"${pkg}::VERSION"} }; + $ver = 'undef' unless defined $ver; + if ($imports) { + my @imports = @$imports; + my $caller = (caller 0)[0]; + local $@; + my $res = eval <<"IMPORTER"; +package + $caller; +BEGIN { \$pkg->import(\@imports) } +1; +IMPORTER + skip_all "Could not import '@imports' from $pkg $ver: $@" unless $res; + } + diag "Using $pkg $ver"; + } else { + (my $file = "$pkg.pm") =~ s{::}{/}g; + delete $INC{$file}; + skip_all "$spec $desc"; + } +} + +package VPIT::TestHelpers::Guard; + +sub new { + my ($class, $code) = @_; + + bless { code => $code }, $class; +} + +sub DESTROY { $_[0]->{code}->() } + +1;