Upgrade to Test::Harness 3.14
[p5sagit/p5-mst-13.2.git] / ext / Test / Harness / t / harness-subclass.t
1 #!/usr/bin/perl -w
2
3 BEGIN {
4     if ( $ENV{PERL_CORE} ) {
5         chdir 't';
6         @INC = ( '../lib', '../ext/Test/Harness/t/lib' );
7     }
8     else {
9         unshift @INC, 't/lib';
10     }
11 }
12
13 use strict;
14 use TAP::Harness;
15 use Test::More tests => 13;
16
17 my %class_map = (
18     aggregator_class  => 'My::TAP::Parser::Aggregator',
19     formatter_class   => 'My::TAP::Formatter::Console',
20     multiplexer_class => 'My::TAP::Parser::Multiplexer',
21     parser_class      => 'My::TAP::Parser',
22     scheduler_class   => 'My::TAP::Parser::Scheduler',
23 );
24
25 my %loaded = ();
26
27 # Synthesize our subclasses
28 for my $class ( values %class_map ) {
29     ( my $base_class = $class ) =~ s/^My:://;
30     use_ok($base_class);
31
32     no strict 'refs';
33     @{"${class}::ISA"} = ($base_class);
34     *{"${class}::new"} = sub {
35         my $pkg = shift;
36         $loaded{$pkg} = 1;
37
38         # Can't use SUPER outside a package
39         return $base_class->can('new')->( $pkg, @_ );
40     };
41 }
42
43 {
44     ok my $harness = TAP::Harness->new( { %class_map, verbosity => -9 } ),
45       'created harness';
46     isa_ok $harness, 'TAP::Harness';
47
48     # Test dynamic loading
49     ok !$INC{'NOP.pm'}, 'NOP not loaded';
50     ok my $nop = $harness->_construct('NOP'), 'loaded and created';
51     isa_ok $nop, 'NOP';
52     ok $INC{'NOP.pm'}, 'NOP loaded';
53
54     my $aggregate = $harness->runtests(
55         File::Spec->catfile(
56             (   $ENV{PERL_CORE}
57                 ? ( File::Spec->updir, 'ext', 'Test', 'Harness' )
58                 : ()
59             ),
60             't',
61             'sample-tests',
62             'simple'
63         )
64     );
65
66     isa_ok $aggregate, 'My::TAP::Parser::Aggregator';
67
68     is_deeply \%loaded,
69       { 'My::TAP::Parser::Aggregator' => 1,
70         'My::TAP::Formatter::Console' => 1,
71         'My::TAP::Parser'             => 1,
72         'My::TAP::Parser::Scheduler'  => 1,
73       },
74       'loaded our classes';
75 }