Subject: | TODOs inside test groups do not work properly (Patch included) |
Date: | Tue, 19 Mar 2013 11:57:01 -0500 |
To: | bug-Test-Group [...] rt.cpan.org |
From: | James Otting <otting [...] cpanel.net> |
Module: Test::Group 0.18
perl 5.10.1 on Centos 6.4
TODOs inside test groups are not properly marked as such in TAP output,
causing them to show as failures. This is the same issue as reported in
rt by Dvaid Storrs in June of 2011. I've found and (I believe) fixed the
issue. A patch is included below.
--- Test/Group.pm 2013-03-14 17:01:39.275840601 -0500
+++ Test/Group.pm 2013-03-14 17:02:43.041718993 -0500
@@ -457,16 +457,9 @@
no warnings "redefine";
my ($OK, $TODO_string) = $subTest->as_Test_Builder_params;
- # I tried to put a "local $TODO = " here, but that didn't work and
- # I lack the patience to dig up the whole story about
- # Test::Builder->caller not doing The Right Thing here (yet
- # elsewhere it does when it apparently shouldn't, e.g. in
- # L</run>). So here goes a sleazy local-method trick to get the
- # TODO status across to Test::Builder; the trick has an adherence
- # in L</ok>, which see.
- local *Test::Builder::todo = sub { $TODO_string };
- local $Test::Builder::Level = $Test::Builder::Level + $Level;
+ $Test->todo_start($TODO_string);
$Test->ok($OK, $name);
+ $Test->todo_end();
return $OK ? 1 : 0;
}
This fix appears to work properly for test structures like the following.
#!/usr/bin/perl
use Test::More tests => 2;
use Test::Group;
test "something" => sub {
pass("Ok");
TODO: {
local $TODO = "this part does not work yet";
fail("Expected fail");
}
pass("Works");
};
pass("Works");