Subject: | Fix for Test::Builder 1.5 |
Hi,
The attached patch fixes Test::HasVersion's tests for Test::Builder1.5.
Test::Builder 1.5 adds a TAP version header to the TAP output, so the
plan is no longer the first thing to come out. This could be hacked
around in the test, but its safer to use Test::Builder::Tester which
will better roll with TAP formatting changes.
It also fixes the code so all_pm_version_ok() reports failure from the
point where it's called, not inside HasVersion.pm.
Subject: | tb.patch |
diff --git a/HasVersion.pm b/HasVersion.pm
index aefc19c..3a6ea58 100644
--- a/HasVersion.pm
+++ b/HasVersion.pm
@@ -167,6 +167,7 @@ the plan is left untouched.
sub all_pm_version_ok {
my @pm_files = all_pm_files(@_);
+ local $Test::Builder::Level = $Test::Builder::Level + 1;
$Test->plan(tests => scalar @pm_files) unless $Test->has_plan;
for (@pm_files) {
pm_version_ok($_);
diff --git a/t/04_all.ok.t b/t/04_all.ok.t
index f009de7..93f0880 100755
--- a/t/04_all.ok.t
+++ b/t/04_all.ok.t
@@ -1,14 +1,8 @@
#!/usr/bin/perl
-use Test::More tests => 4 + 3;
-
-use File::Spec;
-my $null = File::Spec->devnull;
-
-ok(chdir "t/eg/", "cd t/eg");
-my @tap = `$^X -Mblib ../../t/97_has_version.t 2>$null`;
-ok(scalar @tap, 't/97_has_version.t run ok');
-ok(chdir "../..", "cd ../..");
+use Test::Builder::Tester tests => 1;
+use Test::More;
+use Test::HasVersion;
my @expected = (
'A.pm' => 'ok',
@@ -16,12 +10,18 @@ my @expected = (
'lib/B/C.pm' => 'not ok',
);
-like(shift @tap, qr/^1\.\.3/, 'good plan');
+test_out("1..3");
+
+my $count = 1;
+while(@expected) {
+ my $file = shift @expected;
+ my $want = shift @expected;
+ test_out("$want $count - $file has version");
+ test_fail(+5) if $want eq 'not ok';
+ $count++;
+}
-for (@tap) {
- next if /^#/;
- my $f = shift @expected;
- my $ans = shift @expected;
- like($_, qr/^$ans \d+ - $f/, $ans eq 'ok' ? "$f has version" : "$f has no version");
+chdir "t/eg/" or die "Can't chdir to t/eg";
+all_pm_version_ok();
-}
\ No newline at end of file
+test_test("all_pm_version_ok() including failures");