I'm happy to announce the first rev of Test::Builder2::Tester.  It lets you
test Test:: modules without doing string compares on the TAP.  You can test a
much wider array of detail and much simpler.
https://github.com/schwern/test-more/blob/Test-Builder2/lib/Test/Builder2/Tester.pm

Here's an example testing Test::Simple ok():

    use Test::Simple tests => 2;
    use Test::Builder2::Tester;

    my $history = capture {
        ok 2+2==5, "addition";
        ok 2*2==4, "multiplication";
    };

    my $results = $history->results;

    result_like $results->[0], {
        is_pass     => 0,
        name        => "addition",
        file        => $0
    };

    result_like $results->[1], {
        is_pass     => 1,
        name        => "multiplication",
        file        => $0
    };

    done_testing;

Using Chad's idea, the code being tested is isolated from the rest of the test
inside a capture() block.  This returns the complete history of whatever
happened inside its block.  This includes every test event and result, all the
same information Test::Builder2 uses itself.  result_like() is a convenience
function which will check only the attributes you specify and ignore the rest.

This makes testing a Test:: module much more straight forward and powerful.
Most importantly, it shields the Test:: module from little changes to the test
output format.

TB2::Tester is currently a rough proof of concept.  result_like() doesn't
produce much in the way of useful diagnostics.  results_like() would likely be
more convenient.  It will eventually work with Test::Builder based modules,
but they don't work without a TAP formatter just yet.


-- 
You are wicked and wrong to have broken inside and peeked at the
implementation and then relied upon it.
        -- tchrist in <31832.969261130@chthon>

Reply via email to