9681aa7f0d272bff80c14a67f23f68fea9f6bce0
[p5sagit/p5-mst-13.2.git] / lib / Test / Harness / t / callback.t
1 #!/usr/bin/perl -w
2
3 BEGIN {
4     if( $ENV{PERL_CORE} ) {
5         chdir 't';
6         @INC = ('../lib', 'lib');
7     }
8     else {
9         unshift @INC, 't/lib';
10     }
11 }
12
13 use Test::More;
14 use File::Spec;
15
16 BEGIN {
17     use vars qw( %samples );
18     
19     %samples = (
20             bailout     => [qw( header test test test bailout )],
21             combined    => ['header', ('test') x 10],
22             descriptive => ['header', ('test') x 5 ],
23             duplicates  => ['header', ('test') x 11 ],
24             head_end    => [qw( other test test test test 
25                                 other header other other )],
26             head_fail   => [qw( other test test test test
27                                 other header other other )],
28             no_nums     => ['header', ('test') x 5 ],
29             out_of_order=> [('test') x 10, 'header', ('test') x 5],
30             simple      => [qw( header test test test test test )],
31             simple_fail => [qw( header test test test test test )],
32             'skip'      => [qw( header test test test test test )],
33             skipall     => [qw( header )],
34             skipall_nomsg => [qw( header )],
35             skip_nomsg  => [qw( header test )],
36             taint       => [qw( header test )],
37             'todo'      => [qw( header test test test test test )],
38             todo_inline => [qw( header test test test )],
39             vms_nit     => [qw( header other test test )],
40             with_comments => [qw( other header other test other test test
41                                   test other other test other )],
42            );
43     plan tests => 2 + scalar keys %samples;
44 }
45
46 BEGIN { use_ok( 'Test::Harness::Straps' ); }
47
48 my $Curdir = File::Spec->curdir;
49 my $SAMPLE_TESTS = $ENV{PERL_CORE}
50                     ? File::Spec->catdir($Curdir, 'lib', 'sample-tests')
51                     : File::Spec->catdir($Curdir, 't',   'sample-tests');
52
53 my $strap = Test::Harness::Straps->new;
54 isa_ok( $strap, 'Test::Harness::Straps' );
55 $strap->set_callback(
56     sub {
57         my($self, $line, $type, $totals) = @_;
58         push @out, $type;
59     }
60 );
61
62 for my $test ( sort keys %samples ) {
63     my $expect = $samples{$test};
64
65     local @out = ();
66     $strap->analyze_file(File::Spec->catfile($SAMPLE_TESTS, $test));
67
68     is_deeply(\@out, $expect,   "$test callback");
69 }