diff --git a/xt/20_run.t b/xt/20_run.t deleted file mode 100644 index f52fa62a..00000000 --- a/xt/20_run.t +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env perl - -use strict; -use warnings; - -use Test::Class::Load qw; diff --git a/xt/21_run.t b/xt/21_run.t new file mode 100644 index 00000000..567d1263 --- /dev/null +++ b/xt/21_run.t @@ -0,0 +1,59 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +use lib 'xt/lib'; +use Module::Find; + +my @BAD_MODULES = qw( + Test::SNMP::Info::MAU + Test::SNMP::Info::Layer3::C4000 +); + +my @found = findallmod 'Test::SNMP::Info'; +unshift @found, 'Test::SNMP::Info'; + +# pass a specific module to test, +# using e.g. "prove xt/21_run.t :: Test::SNMP::Info::MAU" +if (scalar @ARGV) { @found = @ARGV } + +# cannot do this inline with findallmod +@found = sort { (scalar split m/::/, $a) <=> (scalar split m/::/, $b) + or + $a cmp $b } @found; + +my $total = scalar @found - scalar @BAD_MODULES; +my $count = 0; + +# fake test plan +print "1..$total\n"; + +foreach my $module (@found) { + if (grep m/^${module}$/, @BAD_MODULES) { + # printf STDERR "!!> skipping: %s\n", $module; + next; + } + + my $preamble = <<'END_CODE_PREAMBLE'; + # this is to avoid annoying plan warnings with the way subtests are done + { + use Hook::LexWrap; + use Test::Builder; + no warnings 'redefine'; + wrap *Test::Builder::diag, pre => sub { + $_[-1] = 1 + if $_[1] and $_[1] =~ m/Tests were run but no plan was declared/; + }; + } +END_CODE_PREAMBLE + + my $code = <<"END_CODE"; + $module->builder->current_test($count); + Test::More::subtest '$module' => sub { $module->runtests() }; +END_CODE + + # printf STDERR "--> %d: %s\n", ($count + 1), $module; + system (qw{perl -Ilib -Ixt/lib}, "-M$module", '-e', $preamble . $code); + ++$count; +} diff --git a/xt/lib/My/Test/Class.pm b/xt/lib/My/Test/Class.pm index e4bd6683..4758a550 100644 --- a/xt/lib/My/Test/Class.pm +++ b/xt/lib/My/Test/Class.pm @@ -41,7 +41,8 @@ use base qw; # Don't run the base tests defined in this class, run them in subclasses only My::Test::Class->SKIP_CLASS(1); -INIT { Test::Class->runtests } +# add a test which runs "use Test::Class::Load qw;" and uncomment: +# INIT { Test::Class->runtests } my $EMPTY = q{}; diff --git a/xt/lib/Test/SNMP/Info/MAU.pm b/xt/lib/Test/SNMP/Info/MAU.pm index 3605a846..7fbd84c5 100644 --- a/xt/lib/Test/SNMP/Info/MAU.pm +++ b/xt/lib/Test/SNMP/Info/MAU.pm @@ -173,4 +173,4 @@ sub mau_set_i_duplex_admin : Tests(3) { undef, q(Mock set duplex call to bad duplex type 'full-x' fails)); } -1; \ No newline at end of file +1;