4 if ( $ENV{PERL_CORE} ) {
6 @INC = ( '../lib', 'lib' );
14 use vars qw(%INIT %CUSTOM);
16 use Test::More tests => 24;
17 use File::Spec::Functions qw( catfile );
19 use_ok('TAP::Parser::SubclassTest');
21 # TODO: foreach my $source ( ... )
22 my $t_dir = $ENV{PERL_CORE} ? 'lib' : 't';
26 my $source = catfile( $t_dir, 'subclass_tests', 'perl_source' );
27 my $p = TAP::Parser::SubclassTest->new( { source => $source } );
29 # The grammar is lazily constructed so we need to ask for it to
30 # trigger it's creation.
31 my $grammer = $p->_grammar;
33 ok( $p->{initialized}, 'new subclassed parser' );
35 is( $p->source_class => 'MySource', 'source_class' );
36 is( $p->perl_source_class => 'MyPerlSource', 'perl_source_class' );
37 is( $p->grammar_class => 'MyGrammar', 'grammar_class' );
38 is( $p->iterator_factory_class => 'MyIteratorFactory',
39 'iterator_factory_class'
41 is( $p->result_factory_class => 'MyResultFactory',
42 'result_factory_class'
45 is( $INIT{MyPerlSource}, 1, 'initialized MyPerlSource' );
46 is( $CUSTOM{MyPerlSource}, 1, '... and it was customized' );
47 is( $INIT{MyGrammar}, 1, 'initialized MyGrammar' );
48 is( $CUSTOM{MyGrammar}, 1, '... and it was customized' );
50 # make sure overrided make_* methods work...
53 is( $CUSTOM{MySource}, 1, 'make custom source' );
55 is( $CUSTOM{MyPerlSource}, 1, 'make custom perl source' );
57 is( $CUSTOM{MyGrammar}, 1, 'make custom grammar' );
59 is( $CUSTOM{MyIterator}, 1, 'make custom iterator' );
61 is( $CUSTOM{MyResult}, 1, 'make custom result' );
63 # make sure parser helpers use overrided classes too (the parser should
64 # be the central source of configuration/overriding functionality)
65 # The source is already tested above (parser doesn't keep a copy of the
66 # source currently). So only one to check is the Grammar:
68 my $r = $p->_grammar->tokenize;
69 isa_ok( $r, 'MyResult', 'i has results' );
70 is( $INIT{MyResult}, 1, 'initialized MyResult' );
71 is( $CUSTOM{MyResult}, 1, '... and it was customized' );
72 is( $INIT{MyResultFactory}, 1, '"initialized" MyResultFactory' );
75 SKIP: { # non-perl source
81 my $file = catfile( $t_dir, 'data', 'catme.1' );
82 my $p = TAP::Parser::SubclassTest->new( { exec => [ $cat => $file ] } );
84 is( $INIT{MySource}, 1, 'initialized MySource subclass' );
85 is( $CUSTOM{MySource}, 1, '... and it was customized' );
86 is( $INIT{MyIterator}, 1, 'initialized MyIterator subclass' );
87 is( $CUSTOM{MyIterator}, 1, '... and it was customized' );