This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Test-Simple Version Bump, 1.301001_093 (RC13)
[perl5.git] / cpan / Test-Simple / lib / Test / Stream / Event / Plan.pm
CommitLineData
518760d9
CG
1package Test::Stream::Event::Plan;
2use strict;
3use warnings;
4
5use Test::Stream::Event(
6 accessors => [qw/max directive reason/],
7 ctx_method => '_plan',
8);
9
10use Test::Stream::Carp qw/confess/;
11
12my %ALLOWED = (
13 'SKIP' => 1,
14 'NO PLAN' => 1,
15);
16
17sub init {
4bba85d0
CG
18 $_[0]->SUPER::init();
19
518760d9
CG
20 if ($_[0]->[DIRECTIVE]) {
21 $_[0]->[DIRECTIVE] = 'SKIP' if $_[0]->[DIRECTIVE] eq 'skip_all';
22 $_[0]->[DIRECTIVE] = 'NO PLAN' if $_[0]->[DIRECTIVE] eq 'no_plan';
23
24 confess "'" . $_[0]->[DIRECTIVE] . "' is not a valid plan directive"
25 unless $ALLOWED{$_[0]->[DIRECTIVE]};
26 }
27 else {
28 $_[0]->[DIRECTIVE] = '';
29 confess "Cannot have a reason without a directive!"
30 if defined $_[0]->[REASON];
31
32 confess "No number of tests specified"
33 unless defined $_[0]->[MAX];
518760d9
CG
34 }
35}
36
37sub to_tap {
38 my $self = shift;
39
40 my $max = $self->[MAX];
41 my $directive = $self->[DIRECTIVE];
42 my $reason = $self->[REASON];
43
44 return if $directive && $directive eq 'NO PLAN';
45
46 my $plan = "1..$max";
47 if ($directive) {
48 $plan .= " # $directive";
49 $plan .= " $reason" if defined $reason;
50 }
51
52 return [OUT_STD, "$plan\n"];
53}
54
55sub extra_details {
56 my $self = shift;
57 return (
58 max => $self->max || 0,
59 directive => $self->directive || undef,
60 reason => $self->reason || undef
61 );
62}
63
641;
65
66__END__
67
68=head1 NAME
69
70Test::Stream::Event::Plan - The event of a plan
71
72=encoding utf8
73
74=head1 DESCRIPTION
75
76Plan events are fired off whenever a plan is declared, done testing is called,
77or a subtext completes.
78
79=head1 SYNOPSYS
80
81 use Test::Stream::Context qw/context/;
82 use Test::Stream::Event::Plan;
83
84 my $ctx = context();
85 my $event = $ctx->plan($max, $directive, $reason);
86
87=head1 ACCESSORS
88
89=over 4
90
91=item $num = $plan->max
92
93Get the number of expected tests
94
95=item $dir = $plan->directive
96
97Get the directive (such as TODO, skip_all, or no_plan).
98
99=item $reason = $plan->reason
100
101Get the reason for the directive.
102
103=back
104
105=head1 SUMMARY FIELDS
106
107=over 4
108
109=item max
110
111Number of expected tests.
112
113=item directive
114
115Directive.
116
117=item reason
118
119Reason for directive.
120
121=back
122
123=head1 SOURCE
124
125The source code repository for Test::More can be found at
126F<http://github.com/Test-More/test-more/>.
127
128=head1 MAINTAINER
129
130=over 4
131
132=item Chad Granum E<lt>exodist@cpan.orgE<gt>
133
134=back
135
136=head1 AUTHORS
137
138The following people have all contributed to the Test-More dist (sorted using
139VIM's sort function).
140
141=over 4
142
143=item Chad Granum E<lt>exodist@cpan.orgE<gt>
144
145=item Fergal Daly E<lt>fergal@esatclear.ie>E<gt>
146
147=item Mark Fowler E<lt>mark@twoshortplanks.comE<gt>
148
149=item Michael G Schwern E<lt>schwern@pobox.comE<gt>
150
151=item 唐鳳
152
153=back
154
155=head1 COPYRIGHT
156
157There has been a lot of code migration between modules,
158here are all the original copyrights together:
159
160=over 4
161
162=item Test::Stream
163
164=item Test::Stream::Tester
165
166Copyright 2014 Chad Granum E<lt>exodist7@gmail.comE<gt>.
167
168This program is free software; you can redistribute it and/or
169modify it under the same terms as Perl itself.
170
171See F<http://www.perl.com/perl/misc/Artistic.html>
172
173=item Test::Simple
174
175=item Test::More
176
177=item Test::Builder
178
179Originally authored by Michael G Schwern E<lt>schwern@pobox.comE<gt> with much
180inspiration from Joshua Pritikin's Test module and lots of help from Barrie
181Slaymaker, Tony Bowden, blackstar.co.uk, chromatic, Fergal Daly and the perl-qa
182gang.
183
184Idea by Tony Bowden and Paul Johnson, code by Michael G Schwern
185E<lt>schwern@pobox.comE<gt>, wardrobe by Calvin Klein.
186
187Copyright 2001-2008 by Michael G Schwern E<lt>schwern@pobox.comE<gt>.
188
189This program is free software; you can redistribute it and/or
190modify it under the same terms as Perl itself.
191
192See F<http://www.perl.com/perl/misc/Artistic.html>
193
194=item Test::use::ok
195
196To the extent possible under law, 唐鳳 has waived all copyright and related
197or neighboring rights to L<Test-use-ok>.
198
199This work is published from Taiwan.
200
201L<http://creativecommons.org/publicdomain/zero/1.0>
202
203=item Test::Tester
204
205This module is copyright 2005 Fergal Daly <fergal@esatclear.ie>, some parts
206are based on other people's work.
207
208Under the same license as Perl itself
209
210See http://www.perl.com/perl/misc/Artistic.html
211
212=item Test::Builder::Tester
213
214Copyright Mark Fowler E<lt>mark@twoshortplanks.comE<gt> 2002, 2004.
215
216This program is free software; you can redistribute it
217and/or modify it under the same terms as Perl itself.
218
219=back