Add ARM files
[dh-make-perl] / dev / arm / libtest-harness-perl / libtest-harness-perl-3.12 / t / callbacks.t
1 #!/usr/bin/perl -wT
2
3 use strict;
4 use lib 't/lib';
5
6 use Test::More tests => 10;
7
8 use TAP::Parser;
9 use TAP::Parser::IteratorFactory;
10
11 my $tap = <<'END_TAP';
12 1..5
13 ok 1 - input file opened
14 ... this is junk
15 not ok first line of the input valid # todo some data
16 # this is a comment
17 ok 3 - read the rest of the file
18 not ok 4 - this is a real failure
19 ok 5 # skip we have no description
20 END_TAP
21
22 my @tests;
23 my $plan_output;
24 my $todo      = 0;
25 my $skip      = 0;
26 my %callbacks = (
27     test => sub {
28         my $test = shift;
29         push @tests => $test;
30         $todo++ if $test->has_todo;
31         $skip++ if $test->has_skip;
32     },
33     plan => sub {
34         my $plan = shift;
35         $plan_output = $plan->as_string;
36     }
37 );
38
39 my $factory = TAP::Parser::IteratorFactory->new;
40 my $stream  = $factory->make_iterator( [ split /\n/ => $tap ] );
41 my $parser  = TAP::Parser->new(
42     {   stream    => $stream,
43         callbacks => \%callbacks,
44     }
45 );
46
47 can_ok $parser, 'run';
48 $parser->run;
49 is $plan_output, '1..5', 'Plan callbacks should succeed';
50 is scalar @tests, $parser->tests_run, '... as should the test callbacks';
51
52 @tests       = ();
53 $plan_output = '';
54 $todo        = 0;
55 $skip        = 0;
56 my $else = 0;
57 my $all  = 0;
58 my $end  = 0;
59 %callbacks = (
60     test => sub {
61         my $test = shift;
62         push @tests => $test;
63         $todo++ if $test->has_todo;
64         $skip++ if $test->has_skip;
65     },
66     plan => sub {
67         my $plan = shift;
68         $plan_output = $plan->as_string;
69     },
70     EOF => sub {
71         $end = 1 if $all == 8;
72     },
73     ELSE => sub {
74         $else++;
75     },
76     ALL => sub {
77         $all++;
78     },
79 );
80
81 $stream = $factory->make_iterator( [ split /\n/ => $tap ] );
82 $parser = TAP::Parser->new(
83     {   stream    => $stream,
84         callbacks => \%callbacks,
85     }
86 );
87
88 can_ok $parser, 'run';
89 $parser->run;
90 is $plan_output, '1..5', 'Plan callbacks should succeed';
91 is scalar @tests, $parser->tests_run, '... as should the test callbacks';
92 is $else, 2, '... and the correct number of "ELSE" lines should be seen';
93 is $all,  8, '... and the correct total number of lines should be seen';
94 is $end,  1, 'EOF callback correctly called';
95
96 # Check callback name policing
97
98 %callbacks = (
99     sometest => sub { },
100     plan     => sub { },
101     random   => sub { },
102     ALL      => sub { },
103     ELSES    => sub { },
104 );
105
106 $stream = $factory->make_iterator( [ split /\n/ => $tap ] );
107 eval {
108     $parser = TAP::Parser->new(
109         {   stream    => $stream,
110             callbacks => \%callbacks,
111         }
112     );
113 };
114
115 like $@, qr/Callback/, 'Bad callback keys faulted';