6 use Test::More tests => 227;
8 use TAP::Parser::ResultFactory;
9 use TAP::Parser::Result;
11 use constant RESULT => 'TAP::Parser::Result';
12 use constant PLAN => 'TAP::Parser::Result::Plan';
13 use constant TEST => 'TAP::Parser::Result::Test';
14 use constant COMMENT => 'TAP::Parser::Result::Comment';
15 use constant BAILOUT => 'TAP::Parser::Result::Bailout';
16 use constant UNKNOWN => 'TAP::Parser::Result::Unknown';
19 $SIG{__WARN__} = sub { $warning = shift };
22 # Note that the are basic unit tests. More comprehensive path coverage is
23 # found in the regression tests.
26 my $factory = TAP::Parser::ResultFactory->new;
27 my %inherited_methods = (
36 my $abstract_class = bless { type => 'no_such_type' },
37 RESULT; # you didn't see this
38 run_method_tests( $abstract_class, {} ); # check the defaults
40 can_ok $abstract_class, 'type';
41 is $abstract_class->type, 'no_such_type',
42 '... and &type should return the correct result';
44 can_ok $abstract_class, 'passed';
46 ok $abstract_class->passed, '... and it should default to true';
47 like $warning, qr/^\Qpassed() is deprecated. Please use "is_ok()"/,
48 '... but it should emit a deprecation warning';
52 can_ok $factory, 'make_result';
53 eval { $factory->make_result( { type => 'no_such_type' } ) };
54 ok my $error = $@, '... and calling it with an unknown class should fail';
55 like $error, qr/^Could not determine class for.*no_such_type/s,
56 '... with an appropriate error message';
58 # register new Result types:
59 can_ok $factory, 'class_for';
60 can_ok $factory, 'register_type';
64 use vars qw($VERSION @ISA);
65 @ISA = 'TAP::Parser::Result';
66 TAP::Parser::ResultFactory->register_type( 'my_type' => __PACKAGE__ );
70 my $r = eval { $factory->make_result( { type => 'my_type' } ) };
72 isa_ok( $r, 'MyResult', 'register custom type' );
73 ok( !$error, '... and no error' );
84 raw => '... this line is junk ... ',
88 raw => '... this line is junk ... ',
89 as_string => '... this line is junk ... ',
103 raw => '# this is a comment',
104 comment => 'this is a comment',
108 raw => '# this is a comment',
109 as_string => '# this is a comment',
110 comment => 'this is a comment',
117 # test bailout tokens
124 raw => 'Bailout! This blows!',
125 bailout => 'This blows!',
129 raw => 'Bailout! This blows!',
130 as_string => 'This blows!',
163 raw => '1..0 # SKIP help me, Rhonda!',
166 explanation => 'help me, Rhonda!',
170 raw => '1..0 # SKIP help me, Rhonda!',
173 explanation => 'help me, Rhonda!',
182 my $test = run_tests(
187 description => '... and this test is fine',
190 raw => 'ok 5 and this test is fine',
198 description => '... and this test is fine',
206 as_string => 'ok 5 ... and this test is fine',
212 can_ok $test, 'actual_passed';
214 is $test->actual_passed, $test->is_actual_ok,
215 '... and it should return the correct value';
217 qr/^\Qactual_passed() is deprecated. Please use "is_actual_ok()"/,
218 '... but issue a deprecation warning';
220 can_ok $test, 'todo_failed';
222 is $test->todo_failed, $test->todo_passed,
223 '... and it should return the correct value';
225 qr/^\Qtodo_failed() is deprecated. Please use "todo_passed()"/,
226 '... but issue a deprecation warning';
235 description => '... and this test is fine',
237 explanation => 'why not?',
238 raw => 'not ok 5 and this test is fine # TODO why not?',
246 description => '... and this test is fine',
248 explanation => 'why not?',
255 'not ok 5 ... and this test is fine # TODO why not?',
262 my ( $instantiated, $value_for ) = @_;
263 my $result = instantiate($instantiated);
264 run_method_tests( $result, $value_for );
269 my $instantiated = shift;
270 my $class = $instantiated->{class};
271 ok my $result = $factory->make_result( $instantiated->{data} ),
272 'Creating $class results should succeed';
273 isa_ok $result, $class, '.. and the object it returns';
277 sub run_method_tests {
278 my ( $result, $value_for ) = @_;
279 while ( my ( $method, $default ) = each %inherited_methods ) {
280 can_ok $result, $method;
281 if ( defined( my $value = delete $value_for->{$method} ) ) {
282 is $result->$method(), $value,
283 "... and $method should be correct";
286 is $result->$method(), $default,
287 "... and $method default should be correct";
290 while ( my ( $method, $value ) = each %$value_for ) {
291 can_ok $result, $method;
292 is $result->$method(), $value, "... and $method should be correct";