line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test2::Plugin::TodoFailOnSuccess; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
5183441
|
use strict; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
60
|
|
4
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
164
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.0.2'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:GSG'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
|
80
|
2
|
|
|
|
|
750
|
use Test2::API qw( |
81
|
|
|
|
|
|
|
test2_add_callback_context_init |
82
|
|
|
|
|
|
|
test2_add_callback_context_release |
83
|
2
|
|
|
2
|
|
12
|
); |
|
2
|
|
|
|
|
4
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
my $PLUGIN_LOADED = 0; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub import |
88
|
|
|
|
|
|
|
{ |
89
|
2
|
50
|
|
2
|
|
23
|
return if $PLUGIN_LOADED++; |
90
|
|
|
|
|
|
|
|
91
|
2
|
|
|
|
|
11
|
test2_add_callback_context_init ( \&on_context_init ); |
92
|
2
|
|
|
|
|
46
|
test2_add_callback_context_release( \&on_context_release ); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub on_context_init |
96
|
|
|
|
|
|
|
{ |
97
|
11
|
|
|
11
|
0
|
5006472
|
my ($ctx) = @_; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
$ctx->{_TodoFailOnSuccess_hub_listener} = $ctx->hub->listen( |
103
|
|
|
|
|
|
|
sub { |
104
|
12
|
|
|
12
|
|
10134
|
my ($hub, $event, $number) = @_; |
105
|
|
|
|
|
|
|
|
106
|
12
|
|
|
|
|
50
|
my $facet_data = $event->facet_data; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
|
111
|
12
|
|
|
|
|
696
|
my $amnesty_list = $facet_data->{amnesty}; |
112
|
12
|
100
|
66
|
|
|
82
|
return unless $amnesty_list && @$amnesty_list; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
116
|
3
|
|
|
|
|
6
|
my $assert = $facet_data->{assert}; |
117
|
3
|
100
|
66
|
|
|
21
|
return unless $assert && $assert->{pass}; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
122
|
1
|
|
|
|
|
3
|
my %todo_reasons; |
123
|
1
|
|
|
|
|
4
|
foreach my $amnesty (@$amnesty_list) { |
124
|
2
|
50
|
|
|
|
10
|
next unless $amnesty->{tag} eq 'TODO'; |
125
|
2
|
|
|
|
|
5
|
$todo_reasons{ $amnesty->{details} } = 1; |
126
|
|
|
|
|
|
|
} |
127
|
1
|
50
|
|
|
|
5
|
return unless keys %todo_reasons; |
128
|
|
|
|
|
|
|
|
129
|
1
|
|
|
|
|
3
|
my $details = $assert->{details}; |
130
|
|
|
|
|
|
|
|
131
|
1
|
|
|
|
|
5
|
foreach my $todo_reason (sort keys %todo_reasons) { |
132
|
1
|
|
|
|
|
8
|
$ctx->fail( |
133
|
|
|
|
|
|
|
qq{TODO passed unexpectedly: $details} |
134
|
|
|
|
|
|
|
); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
}, |
137
|
11
|
|
|
|
|
64
|
inherit => 1, |
138
|
|
|
|
|
|
|
); |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub on_context_release |
142
|
|
|
|
|
|
|
{ |
143
|
11
|
|
|
11
|
0
|
749
|
my ($ctx) = @_; |
144
|
|
|
|
|
|
|
|
145
|
11
|
|
|
|
|
27
|
my $hub_listener = delete $ctx->{_TodoFailOnSuccess_hub_listener}; |
146
|
11
|
50
|
|
|
|
45
|
$ctx->hub->unlisten($hub_listener) if $hub_listener; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
1; |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
__END__ |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=pod |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=encoding UTF-8 |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head1 NAME |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Test2::Plugin::TodoFailOnSuccess - Report failure if a TODO test unexpectedly passes |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 VERSION |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
version 0.0.2 |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 SYNOPSIS |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
package My::Tests; |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
use Test2::V0; |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
use Test2::Plugin::TodoFailOnSuccess; # report unexpected TODO success |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
use Test2::Tools::Basic; # for "todo" sub |
174
|
|
|
|
|
|
|
use Test2::Todo; # for "todo" object |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
sub test_something |
177
|
|
|
|
|
|
|
{ |
178
|
|
|
|
|
|
|
# Lexical scope TODO: |
179
|
|
|
|
|
|
|
# |
180
|
|
|
|
|
|
|
{ |
181
|
|
|
|
|
|
|
my $todo = todo 'Not expected to pass'; |
182
|
|
|
|
|
|
|
is $value, $expected_value, "Got expected value"; |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
# Coderef TODO: |
186
|
|
|
|
|
|
|
# |
187
|
|
|
|
|
|
|
todo 'Not expected to pass either' => sub { |
188
|
|
|
|
|
|
|
is $value, $expected_value, "Got expected value"; |
189
|
|
|
|
|
|
|
}; |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
# Object-oriented TODO: |
192
|
|
|
|
|
|
|
# |
193
|
|
|
|
|
|
|
my $todo = Test2::Todo->new( reason => 'Still not expected to pass' ); |
194
|
|
|
|
|
|
|
is $value, $expected_value, "Got expected value"; |
195
|
|
|
|
|
|
|
$todo->end; |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=head1 DESCRIPTION |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
Wrapping a test with TODO is a conventient way to avoid being tripped |
201
|
|
|
|
|
|
|
up by test failures until you have a chance to get the code working. |
202
|
|
|
|
|
|
|
It normally won't hurt to leave the TODO in place after the tests |
203
|
|
|
|
|
|
|
start passing, but if you forget to remove the TODO at that point, |
204
|
|
|
|
|
|
|
a subsequent code change could start causing new test failures which |
205
|
|
|
|
|
|
|
would then go unreported and possibly unnoticed. |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
This module provides a mechanism to trigger explicit test failures |
208
|
|
|
|
|
|
|
when TODO tests unexpectedly pass, so that you have an opportunity |
209
|
|
|
|
|
|
|
to remove the TODO. |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
If a TODO test passes, a failure will be reported with a message |
212
|
|
|
|
|
|
|
containing the test description, equivalent to doing: |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
fail "TODO passed unexpectedly: $test_description"; |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
which might appear in your TAP output along with the TODO reason as |
217
|
|
|
|
|
|
|
something like: |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
not ok 3 - TODO passed unexpectedly: Got expected value # TODO Not expected to pass |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
Note that due to the additional C<fail> being reported, you may |
222
|
|
|
|
|
|
|
see messages about your planned number of tests being exceeded, |
223
|
|
|
|
|
|
|
for example: |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
# Did not follow plan: expected 5, ran 6. |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
There are no options or arguments, just C<use Test2::Plugin::TodoFailOnSuccess> |
228
|
|
|
|
|
|
|
in your test file. |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=head1 AUTHOR |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
Grant Street Group <developers@grantstreet.com> |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
This software is Copyright (c) 2019 by Grant Street Group. |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
This is free software, licensed under: |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
The Artistic License 2.0 (GPL Compatible) |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=head1 CONTRIBUTORS |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
=for stopwords Larry Leszczynski Mark Flickinger |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=over 4 |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=item * |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
Larry Leszczynski <Larry.Leszczynski@GrantStreet.com> |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=item * |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
Mark Flickinger <mark.flickinger@grantstreet.com> |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
=back |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=cut |
259
|
|
|
|
|
|
|
|