Commit | Line | Data |
---|---|---|
6bdb8877 CG |
1 | package Test::Builder::Formatter::LegacyResults; |
2 | use strict; | |
3 | use warnings; | |
4 | ||
5 | use base 'Test::Builder::Formatter'; | |
6 | ||
7 | use Test::Builder::Threads; | |
8 | ||
9 | sub init { | |
10 | my $self = shift; | |
11 | $self->reset; | |
12 | } | |
13 | ||
14 | sub reset { | |
15 | my $self = shift; | |
16 | ||
17 | $self->{Test_Results} = &share( [] ); | |
18 | $self->{Curr_Test} = 0; | |
19 | ||
20 | &share(\$self->{Curr_Test}); | |
21 | ||
22 | return; | |
23 | } | |
24 | ||
25 | sub summary { | |
26 | my($self) = shift; | |
27 | return map { $_->{'ok'} } @{ $self->{Test_Results} }; | |
28 | } | |
29 | ||
30 | sub details { | |
31 | my $self = shift; | |
32 | return @{ $self->{Test_Results} }; | |
33 | } | |
34 | ||
35 | sub current_test { | |
36 | my ($self, $num) = @_; | |
37 | ||
38 | lock( $self->{Curr_Test} ); | |
39 | if( defined $num ) { | |
40 | my $delta = $num - $self->{Curr_Test}; | |
41 | $self->{Curr_Test} = $num; | |
42 | ||
43 | # If the test counter is being pushed forward fill in the details. | |
44 | my $test_results = $self->{Test_Results}; | |
45 | if( $num > @$test_results ) { | |
46 | my $start = @$test_results ? @$test_results : 0; | |
47 | for( $start .. $num - 1 ) { | |
48 | $test_results->[$_] = &share( | |
49 | { | |
50 | 'ok' => 1, | |
51 | actual_ok => undef, | |
52 | reason => 'incrementing test number', | |
53 | type => 'unknown', | |
54 | name => undef | |
55 | } | |
56 | ); | |
57 | } | |
58 | } | |
59 | # If backward, wipe history. Its their funeral. | |
60 | elsif( $num < @$test_results ) { | |
61 | $#{$test_results} = $num - 1; | |
62 | } | |
63 | } | |
64 | return $self->{Curr_Test}; | |
65 | } | |
66 | ||
67 | sub sanity_check { | |
68 | my $self = shift; | |
69 | my ($tb) = @_; | |
70 | ||
71 | $tb->_whoa( $self->{Curr_Test} < 0, 'Says here you ran a negative number of tests!' ); | |
72 | ||
73 | $tb->_whoa( | |
74 | $self->{Curr_Test} != @{ $self->{Test_Results} }, | |
75 | 'Somehow you got a different number of results than tests ran!' | |
76 | ); | |
77 | ||
78 | return; | |
79 | } | |
80 | ||
81 | sub ok { | |
82 | my $self = shift; | |
83 | my ($item) = @_; | |
84 | ||
85 | my $result = &share( {} ); | |
86 | ||
87 | lock $self->{Curr_Test}; | |
88 | $self->{Curr_Test}++; | |
89 | ||
90 | $result->{ok} = $item->bool; | |
91 | $result->{actual_ok} = $item->real_bool; | |
92 | ||
93 | my $name = $item->name; | |
94 | if(defined $name) { | |
95 | $name =~ s|#|\\#|g; # # in a name can confuse Test::Harness. | |
96 | $result->{name} = $name; | |
97 | } | |
98 | else { | |
99 | $result->{name} = ''; | |
100 | } | |
101 | ||
102 | if($item->skip && ($item->in_todo || $item->todo)) { | |
103 | $result->{type} = 'todo_skip', | |
104 | $result->{reason} = $item->skip || $item->todo; | |
105 | } | |
106 | elsif($item->in_todo || $item->todo) { | |
107 | $result->{reason} = $item->todo; | |
108 | $result->{type} = 'todo'; | |
109 | } | |
110 | elsif($item->skip) { | |
111 | $result->{reason} = $item->skip; | |
112 | $result->{type} = 'skip'; | |
113 | } | |
114 | else { | |
115 | $result->{reason} = ''; | |
116 | $result->{type} = ''; | |
117 | } | |
118 | ||
119 | $self->{Test_Results}[ $self->{Curr_Test} - 1 ] = $result; | |
120 | } | |
121 | ||
122 | 1; | |
123 | ||
124 | __END__ | |
125 | ||
126 | =head1 NAME | |
127 | ||
128 | Test::Builder::Formatter::LegacyResults - Encapsulate some legacy stuff. | |
129 | ||
130 | =head1 DESCRIPTION | |
131 | ||
132 | Older versions kept track of test results using an array of hashes. This is now | |
133 | deprecated, but needs to still work for legacy code. | |
134 | ||
135 | =head1 TEST COMPONENT MAP | |
136 | ||
59c96aeb | 137 | [Test Script] > [Test Tool] > [Test::Builder] > [Test::Bulder::Stream] > [Event Formatter] |
6bdb8877 CG |
138 | ^ |
139 | You are here | |
140 | ||
141 | A test script uses a test tool such as L<Test::More>, which uses Test::Builder | |
142 | to produce results. The results are sent to L<Test::Builder::Stream> which then | |
143 | forwards them on to one or more formatters. The default formatter is | |
144 | L<Test::Builder::Fromatter::TAP> which produces TAP output. | |
145 | ||
146 | =head1 AUTHORS | |
147 | ||
148 | =over 4 | |
149 | ||
150 | =item Chad Granum E<lt>exodist@cpan.orgE<gt> | |
151 | ||
152 | =back | |
153 | ||
154 | =head1 SOURCE | |
155 | ||
156 | The source code repository for Test::More can be found at | |
157 | F<http://github.com/Test-More/test-more/>. | |
158 | ||
159 | =head1 COPYRIGHT | |
160 | ||
161 | Copyright 2014 Chad Granum E<lt>exodist7@gmail.comE<gt>. | |
162 | ||
163 | This program is free software; you can redistribute it and/or | |
164 | modify it under the same terms as Perl itself. | |
165 | ||
166 | See F<http://www.perl.com/perl/misc/Artistic.html> |