NAME
Fennec::Assert::Interceptor - Intercept results generated by asserts in order to test them.
DESCRIPTION
When writing custom assertion libraries it helps to be able to test the results they generate. Test::Builder does this using Test::Builder::Tester which captures output and requires you to generate the same output seperetly and compare them. Frankly I hate Test::Builders tester.
Fennec's interceptor assertion library provides a function that lets you capture results generated within a codeblock. All output is captured and returned as an arrayref of Fennec::Output objects. You can then check the result and diag objects themselves. This provides additional tools for working with the returned results.
SYNOPSIS
use Fennec asserts => [ 'Core', 'Interceptor' ];
tests verify_results => sub {
my $results = capture {
ok( 1, "pass" );
ok( 0, "fail" );
diag( "a diag message" );
};
my @lines = ( ln(-4), ln(-3) );
ok( $results->[0]->pass, "First result passed" );
is( $results->[0]->name, "pass", "First result name" );
is( $results->[0]->line, $lines[0], "Correct result line number" );
isa_ok( $results->[0], 'Fennec::Output::Result' );
ok( !$results->[1]->pass, "Second result failed" );
is( $results->[1]->name, "fail", "Second result name" );
is( $results->[1]->line, $lines[1], "Correct result line number" );
isa_ok( $results->[1], 'Fennec::Output::Result' );
is_deeply(
$results->[2]->stderr,
[ "a diag message" ],
"diag message"
);
isa_ok( $results->[2], 'Fennec::Output::Diag' );
};
1;
FUNCTIONS
- $results = capture { ... }
-
Capture and return all the results generated within a codeblock.
- $line = ln( $int )
-
Return the current line number plus $int. Useful for determining what line number a result should have.
- result_line_number_is( $result, $line; $name )
-
Check the line number of a result.
- result_line_numbers_are( \@results, @lines )
-
Check the line numbers of several results.
AUTHORS
Chad Granum exodist7@gmail.com
COPYRIGHT
Copyright (C) 2010 Chad Granum
Fennec is free software; Standard perl licence.
Fennec is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.