t/92-pod-coverage.t
t/95-portability-files.t
t/99-kwalitee.t
+t/lib/VPIT/TestHelpers.pm
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.14', [ ],
+ 'required for testing POD syntax');
+
+eval 'use Test::Pod'; # Make Kwalitee test happy
+
all_pod_files_ok();
use Test::More;
-eval "use Test::Pod::Coverage 1.04";
-plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" if $@;
-all_pod_coverage_ok( );
+use lib 't/lib';
+use VPIT::TestHelpers;
+
+load_or_skip('Test::Pod::Coverage', '1.04', [ ],
+ 'required for testing POD coverage');
+
+eval 'use Test::Pod::Coverage'; # Make Kwalitee test happy
+
+all_pod_coverage_ok();
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();
use Test::More;
-sub VPIT::Guard::DESTROY { unlink for glob 'Debian_CPANTS.txt*' }
+use lib 't/lib';
+use VPIT::TestHelpers;
-my $guard = bless { }, 'VPIT::Guard';
+my $guard = VPIT::TestHelpers::Guard->new(
+ sub { unlink for glob 'Debian_CPANTS.txt*' }
+);
-eval { require Parse::RecDescent; 'Parse::RecDescent'->VERSION('1.967006') }
- or plan skip_all => 'Parse::RecDescent version 1.967006 or greater required';
+my $desc = 'required to test kwalitee';
-eval { require Module::ExtractUse; 'Module::ExtractUse'->VERSION('0.24') }
- or plan skip_all => 'Module::ExtractUse version 0.24 or greater required';
-
-eval { require Test::Kwalitee; 1 }
- or plan skip_all => 'Test::Kwalitee required';
+load_or_skip('Parse::RecDescent', '1.967006', undef, $desc);
+load_or_skip('Module::ExtractUse', '0.24', undef, $desc);
+load_or_skip('Test::Kwalitee', undef, undef, $desc);
SKIP: {
eval { Test::Kwalitee->import(); };
--- /dev/null
+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;
+ }
+}
+
+sub skip_all {
+ my ($msg) = @_;
+ require Test::More;
+ Test::More::plan(skip_all => $msg);
+}
+
+sub diag {
+ require Test::More;
+ Test::More::diag($_) for @_;
+}
+
+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 {
+ skip_all "$spec $desc";
+ }
+}
+
+package VPIT::TestHelpers::Guard;
+
+sub new {
+ my ($class, $code) = @_;
+
+ bless { code => $code }, $class;
+}
+
+sub DESTROY { $_[0]->{code}->() }
+
+1;