rewrite home page redirect
[dh-make-perl] / dev / i386 / libtest-harness-perl / libtest-harness-perl-3.12 / t / bailout.t
1 #!/usr/bin/perl -wT
2
3 use strict;
4 use lib 't/lib';
5
6 use Test::More tests => 33;
7
8 use TAP::Parser;
9
10 my $tap = <<'END_TAP';
11 1..4
12 ok 1 - input file opened
13 ... this is junk
14 not ok first line of the input valid # todo some data
15 # this is a comment
16 ok 3 - read the rest of the file
17 not ok 4 - this is a real failure
18 Bail out!  We ran out of foobar.
19 END_TAP
20 my $parser = TAP::Parser->new( { tap => $tap } );
21 isa_ok $parser, 'TAP::Parser',
22   '... we should be able to parse bailed out tests';
23
24 my @results;
25 while ( my $result = $parser->next ) {
26     push @results => $result;
27 }
28
29 can_ok $parser, 'passed';
30 is $parser->passed, 3,
31   '... and we shold have the correct number of passed tests';
32 is_deeply [ $parser->passed ], [ 1, 2, 3 ],
33   '... and get a list of the passed tests';
34
35 can_ok $parser, 'failed';
36 is $parser->failed, 1, '... and the correct number of failed tests';
37 is_deeply [ $parser->failed ], [4], '... and get a list of the failed tests';
38
39 can_ok $parser, 'actual_passed';
40 is $parser->actual_passed, 2,
41   '... and we shold have the correct number of actually passed tests';
42 is_deeply [ $parser->actual_passed ], [ 1, 3 ],
43   '... and get a list of the actually passed tests';
44
45 can_ok $parser, 'actual_failed';
46 is $parser->actual_failed, 2,
47   '... and the correct number of actually failed tests';
48 is_deeply [ $parser->actual_failed ], [ 2, 4 ],
49   '... or get a list of the actually failed tests';
50
51 can_ok $parser, 'todo';
52 is $parser->todo, 1,
53   '... and we should have the correct number of TODO tests';
54 is_deeply [ $parser->todo ], [2], '... and get a list of the TODO tests';
55
56 ok !$parser->skipped,
57   '... and we should have the correct number of skipped tests';
58
59 # check the plan
60
61 can_ok $parser, 'plan';
62 is $parser->plan,          '1..4', '... and we should have the correct plan';
63 is $parser->tests_planned, 4,      '... and the correct number of tests';
64
65 # results() is sane?
66
67 ok @results, 'The parser should return results';
68 is scalar @results, 8, '... and there should be one for each line';
69
70 # check the test plan
71
72 my $result = shift @results;
73 ok $result->is_plan, 'We should have a plan';
74
75 # a normal, passing test
76
77 my $test = shift @results;
78 ok $test->is_test, '... and a test';
79
80 # junk lines should be preserved
81
82 my $unknown = shift @results;
83 ok $unknown->is_unknown, '... and an unknown line';
84
85 # a failing test, which also happens to have a directive
86
87 my $failed = shift @results;
88 ok $failed->is_test, '... and another test';
89
90 # comments
91
92 my $comment = shift @results;
93 ok $comment->is_comment, '... and a comment';
94
95 # another normal, passing test
96
97 $test = shift @results;
98 ok $test->is_test, '... and another test';
99
100 # a failing test
101
102 $failed = shift @results;
103 ok $failed->is_test, '... and yet another test';
104
105 # ok 5 # skip we have no description
106 # skipped test
107 my $bailout = shift @results;
108 ok $bailout->is_bailout, 'And finally we should have a bailout';
109 is $bailout->as_string,  'We ran out of foobar.',
110   '... and as_string() should return the explanation';
111 is $bailout->raw, 'Bail out!  We ran out of foobar.',
112   '... and raw() should return the explanation';
113 is $bailout->explanation, 'We ran out of foobar.',
114   '... and it should have the correct explanation';