Ovid wrote:
> So we can preserve diagnostics, but we need help in cleaning up those
> damned line numbers. Hook::LexWrap didn't have the magic I thought it
> would.
ok() is now inside a wrapper so you're one level further down then it thinks.
Just add one to $Level and then take it back off again afterwards.
wrap 'Test::Builder::ok',
pre => sub {
$_[0]->{XXX_test_failed} = 0;
$Test::Builder::Level++;
},
post => sub {
$Test::Builder::Level--;
$_[0]->{XXX_test_failed} = ![ $_[0]->summary ]->[-1];
};
> Below is how I did it. See the 'import' method. There's a lot more
> work to be done to get fine-grained control, but the line numbers are
> the important bit.
Not everything prints more diagnostics, like ok() itself.
$ perl -wle 'use OurMore "fail", "no_plan"; ok(0); ok(1); ok(0); ok(1)'
not ok 1
# Failed test at -e line 1.
ok 2
not ok 3
# Failed test at -e line 1.
ok 4
1..4
# Looks like you failed 2 tests of 4.
But you can probably special case that and fail().
The bigger problem is what happens if a function calls diag() more than once,
like Test::Exception.
$ perl -wle 'use OurMore "no_plan"; throws_ok { die; } qr/foo/; pass()'
not ok 1 - threw Regexp ((?-xism:foo))
# Failed test 'threw Regexp ((?-xism:foo))'
# at -e line 1.
# expecting: Regexp ((?-xism:foo))
# found: Died at -e line 1.
ok 2
1..2
# Looks like you failed 1 test of 2.
$ perl -wle 'use OurMore "fail", "no_plan"; throws_ok { die; } qr/foo/;
pass()'
not ok 1 - threw Regexp ((?-xism:foo))
# Failed test 'threw Regexp ((?-xism:foo))'
# at -e line 1.
# expecting: Regexp ((?-xism:foo))
Test failed. Halting at OurMore.pm line 55.
1..1
# Looks like you failed 1 test of 1.
# Looks like your test died just after 1.
(Note the lack of "found")
--
94. Crucifixes do not ward off officers, and I should not test that.
-- The 213 Things Skippy Is No Longer Allowed To Do In The U.S. Army
http://skippyslist.com/?page_id=3