forked from AndyA/Test-Harness
/
Parser.pm
1930 lines (1345 loc) · 50.8 KB
/
Parser.pm
1
2
3
4
5
6
7
8
9
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package TAP::Parser;
use strict;
use vars qw($VERSION @ISA);
use TAP::Base ();
use TAP::Parser::Grammar ();
use TAP::Parser::Result ();
use TAP::Parser::ResultFactory ();
use TAP::Parser::Source::Executable ();
use TAP::Parser::Source::Perl ();
use TAP::Parser::Source::File ();
use TAP::Parser::Source::RawTAP ();
use TAP::Parser::Source::Handle ();
use TAP::Parser::Iterator ();
use TAP::Parser::IteratorFactory ();
use TAP::Parser::SourceFactory ();
use Carp qw( confess );
=head1 NAME
TAP::Parser - Parse L<TAP|Test::Harness::TAP> output
=head1 VERSION
Version 3.18
=cut
$VERSION = '3.18';
my $DEFAULT_TAP_VERSION = 12;
my $MAX_TAP_VERSION = 13;
$ENV{TAP_VERSION} = $MAX_TAP_VERSION;
END {
# For VMS.
delete $ENV{TAP_VERSION};
}
BEGIN { # making accessors
@ISA = qw(TAP::Base);
__PACKAGE__->mk_methods(
qw(
_stream
_spool
exec
exit
is_good_plan
plan
tests_planned
tests_run
wait
version
in_todo
start_time
end_time
skip_all
source_class
perl_source_class
grammar_class
iterator_factory_class
result_factory_class
source_factory_class
)
);
} # done making accessors
=head1 SYNOPSIS
use TAP::Parser;
my $parser = TAP::Parser->new( { source => $source } );
while ( my $result = $parser->next ) {
print $result->as_string;
}
=head1 DESCRIPTION
C<TAP::Parser> is designed to produce a proper parse of TAP output. For
an example of how to run tests through this module, see the simple
harnesses C<examples/>.
There's a wiki dedicated to the Test Anything Protocol:
L<http://testanything.org>
It includes the TAP::Parser Cookbook:
L<http://testanything.org/wiki/index.php/TAP::Parser_Cookbook>
=head1 METHODS
=head2 Class Methods
=head3 C<new>
my $parser = TAP::Parser->new(\%args);
Returns a new C<TAP::Parser> object.
The arguments should be a hashref with I<one> of the following keys:
=over 4
=item * C<source>
I<TODO:> rewrite this when L<TAP::Parser::SourceFactory> is finished.
This is the preferred method of passing arguments to the constructor. To
determine how to handle the source, the following steps are taken.
If the source contains a newline, it's assumed to be a string of raw TAP
output.
If the source is a reference, it's assumed to be something to pass to
the L<TAP::Parser::Iterator::Stream> constructor. This is used
internally and you should not use it.
Otherwise, the parser does a C<-e> check to see if the source exists. If so,
it attempts to execute the source and read the output as a stream. This is by
far the preferred method of using the parser.
foreach my $file ( @test_files ) {
my $parser = TAP::Parser->new( { source => $file } );
# do stuff with the parser
}
=item * C<tap>
The value should be the complete TAP output.
=item * C<exec>
If passed an array reference, will attempt to create the iterator by
passing a L<TAP::Parser::Source::Executable> object to
L<TAP::Parser::Iterator::Source>, using the array reference strings as
the command arguments to L<IPC::Open3::open3|IPC::Open3>:
exec => [ '/usr/bin/ruby', 't/my_test.rb' ]
Note that C<source> and C<exec> are mutually exclusive.
=back
The following keys are optional.
=over 4
=item * C<callback>
If present, each callback corresponding to a given result type will be called
with the result as the argument if the C<run> method is used:
my %callbacks = (
test => \&test_callback,
plan => \&plan_callback,
comment => \&comment_callback,
bailout => \&bailout_callback,
unknown => \&unknown_callback,
);
my $aggregator = TAP::Parser::Aggregator->new;
foreach my $file ( @test_files ) {
my $parser = TAP::Parser->new(
{
source => $file,
callbacks => \%callbacks,
}
);
$parser->run;
$aggregator->add( $file, $parser );
}
=item * C<switches>
If using a Perl file as a source, optional switches may be passed which will
be used when invoking the perl executable.
my $parser = TAP::Parser->new( {
source => $test_file,
switches => '-Ilib',
} );
=item * C<test_args>
Used in conjunction with the C<source> option to supply a reference to
an C<@ARGV> style array of arguments to pass to the test program.
=item * C<spool>
If passed a filehandle will write a copy of all parsed TAP to that handle.
=item * C<merge>
If false, STDERR is not captured (though it is 'relayed' to keep it
somewhat synchronized with STDOUT.)
If true, STDERR and STDOUT are the same filehandle. This may cause
breakage if STDERR contains anything resembling TAP format, but does
allow exact synchronization.
Subtleties of this behavior may be platform-dependent and may change in
the future.
=item * C<sources>
I<Experimental>.
If set, C<sources> must be a hashref containing the names of the
L<TAP::Parser::Source> subclasses you want to load and/or configure. The
values should contain a hash of configuration that will be passed to the
source class during source detection and creation (ie: the methods
L<TAP::Parser::Source/can_handle> and L<TAP::Parser::Source/make_source>).
For example:
sources => {
Perl => { exec => '/path/to/custom/perl' },
File => { extensions => [ '.tap', '.txt' ] },
MyCustom => { some => 'config' },
}
Will cause C<TAP::Parser> to pass custom configuration to two of the TAP
sources that ship with this module - L<TAP::Parser::Source::Perl> and
L<TAP::Parser::Source::File>. It will also attempt to load the C<MyCustom>
class by looking in C<@INC> for it in this order:
TAP::Parser::Source::MyCustom
MyCustom
See L<TAP::Parser::SourceFactory>, L<TAP::Parser::Source> and subclasses for
more details.
=item * C<source_class>
I<DEPRECATED> - no longer used.
This option was introduced to let you easily customize which I<source> class
the parser should use. It defaults to L<TAP::Parser::Source::Executable>.
See also L</make_source>.
=item * C<perl_source_class>
I<DEPRECATED> - no longer used.
This option was introduced to let you easily customize which I<perl source>
class the parser should use. It defaults to L<TAP::Parser::Source::Perl>.
See also L</make_perl_source>.
=item * C<grammar_class>
This option was introduced to let you easily customize which I<grammar> class
the parser should use. It defaults to L<TAP::Parser::Grammar>.
See also L</make_grammar>.
=item * C<iterator_factory_class>
This option was introduced to let you easily customize which I<iterator>
factory class the parser should use. It defaults to
L<TAP::Parser::IteratorFactory>.
See also L</make_iterator>.
=item * C<result_factory_class>
This option was introduced to let you easily customize which I<result>
factory class the parser should use. It defaults to
L<TAP::Parser::ResultFactory>.
See also L</make_result>.
=item * C<source_factory_class>
I<NEW>.
This option was introduced to let you easily customize which I<source>
factory class the parser should use. It defaults to
L<TAP::Parser::SourceFactory>.
=back
=cut
# new() implementation supplied by TAP::Base
# This should make overriding behaviour of the Parser in subclasses easier:
sub _default_source_class {'TAP::Parser::Source::Executable'} # deprecated
sub _default_perl_source_class {'TAP::Parser::Source::Perl'} # deprecated
sub _default_grammar_class {'TAP::Parser::Grammar'}
sub _default_iterator_factory_class {'TAP::Parser::IteratorFactory'}
sub _default_result_factory_class {'TAP::Parser::ResultFactory'}
sub _default_source_factory_class {'TAP::Parser::SourceFactory'}
##############################################################################
=head2 Instance Methods
=head3 C<next>
my $parser = TAP::Parser->new( { source => $file } );
while ( my $result = $parser->next ) {
print $result->as_string, "\n";
}
This method returns the results of the parsing, one result at a time. Note
that it is destructive. You can't rewind and examine previous results.
If callbacks are used, they will be issued before this call returns.
Each result returned is a subclass of L<TAP::Parser::Result>. See that
module and related classes for more information on how to use them.
=cut
sub next {
my $self = shift;
return ( $self->{_iter} ||= $self->_iter )->();
}
##############################################################################
=head3 C<run>
$parser->run;
This method merely runs the parser and parses all of the TAP.
=cut
sub run {
my $self = shift;
while ( defined( my $result = $self->next ) ) {
# do nothing
}
}
##############################################################################
=head3 C<make_source>
I<DEPRECATED> - no longer used.
Make a new L<TAP::Parser::Source::Executable> object and return it. Passes through any
arguments given.
The C<source_class> can be customized, as described in L</new>.
=head3 C<make_perl_source>
I<DEPRECATED> - no longer used.
Make a new L<TAP::Parser::Source::Perl> object and return it. Passes through
any arguments given.
The C<perl_source_class> can be customized, as described in L</new>.
=head3 C<make_grammar>
Make a new L<TAP::Parser::Grammar> object and return it. Passes through any
arguments given.
The C<grammar_class> can be customized, as described in L</new>.
=head3 C<make_iterator>
Make a new L<TAP::Parser::Iterator> object using the parser's
L<TAP::Parser::IteratorFactory>, and return it. Passes through any arguments
given.
The C<iterator_factory_class> can be customized, as described in L</new>.
=head3 C<make_result>
Make a new L<TAP::Parser::Result> object using the parser's
L<TAP::Parser::ResultFactory>, and return it. Passes through any arguments
given.
The C<result_factory_class> can be customized, as described in L</new>.
=head3 C<make_source_factory>
Make a new L<TAP::Parser::SourceFactory> object and return it. Passes through
any arguments given.
C<source_factory_class> can be customized, as described in L</new>.
=cut
# This should make overriding behaviour of the Parser in subclasses easier:
sub make_source { shift->source_class->new(@_); } # deprecated
sub make_perl_source { shift->perl_source_class->new(@_); } # deprecated
sub make_source_factory { shift->source_factory_class->new(@_); }
sub make_grammar { shift->grammar_class->new(@_); }
sub make_iterator { shift->iterator_factory_class->make_iterator(@_); }
sub make_result { shift->result_factory_class->make_result(@_); }
{
# of the following, anything beginning with an underscore is strictly
# internal and should not be exposed.
my %initialize = (
version => $DEFAULT_TAP_VERSION,
plan => '', # the test plan (e.g., 1..3)
tap => '', # the TAP
tests_run => 0, # actual current test numbers
results => [], # TAP parser results
skipped => [], #
todo => [], #
passed => [], #
failed => [], #
actual_failed => [], # how many tests really failed
actual_passed => [], # how many tests really passed
todo_passed => [], # tests which unexpectedly succeed
parse_errors => [], # perfect TAP should have none
);
# We seem to have this list hanging around all over the place. We could
# probably get it from somewhere else to avoid the repetition.
my @legal_callback = qw(
test
version
plan
comment
bailout
unknown
yaml
ALL
ELSE
EOF
);
my @class_overrides = qw(
source_class
perl_source_class
grammar_class
iterator_factory_class
result_factory_class
source_factory_class
);
sub _initialize {
my ( $self, $arg_for ) = @_;
# everything here is basically designed to convert any TAP source to a
# stream.
# Shallow copy
my %args = %{ $arg_for || {} };
$self->SUPER::_initialize( \%args, \@legal_callback );
# get any class overrides out first:
for my $key (@class_overrides) {
my $default_method = "_default_$key";
my $val = delete $args{$key} || $self->$default_method();
$self->$key($val);
}
my $stream = delete $args{stream};
my $tap = delete $args{tap};
my $raw_source = delete $args{source};
my $sources = delete $args{sources};
my $exec = delete $args{exec};
my $merge = delete $args{merge};
my $spool = delete $args{spool};
my $switches = delete $args{switches};
my $ignore_exit = delete $args{ignore_exit};
my $test_args = delete $args{test_args} || [];
if ( 1 < grep {defined} $stream, $tap, $raw_source, $exec ) {
$self->_croak(
"You may only choose one of 'exec', 'stream', 'tap' or 'source'"
);
}
if ( my @excess = sort keys %args ) {
$self->_croak("Unknown options: @excess");
}
# convert $tap & $exec to $raw_source equiv.
my $raw_source_ref;
if ($tap) {
$raw_source_ref = \$tap;
}
elsif ($exec) {
$raw_source_ref = { exec => [ @$exec, @$test_args ] };
}
elsif ($raw_source) {
$raw_source_ref = ref($raw_source) ? $raw_source : \$raw_source;
}
if ($raw_source_ref) {
my $src_factory = $self->make_source_factory($sources);
my $source = $src_factory->make_source(
{ raw_source_ref => $raw_source_ref,
merge => $merge,
switches => $switches,
test_args => $test_args
}
);
# TODO: replace this with something like:
# my $stream = $source->get_stream; # notice no "( $self )"
$stream = $source->get_stream($self);
}
unless ($stream) {
$self->_croak('PANIC: could not determine stream');
}
while ( my ( $k, $v ) = each %initialize ) {
$self->{$k} = 'ARRAY' eq ref $v ? [] : $v;
}
$self->_stream($stream);
$self->_spool($spool);
$self->ignore_exit($ignore_exit);
return $self;
}
}
=head1 INDIVIDUAL RESULTS
If you've read this far in the docs, you've seen this:
while ( my $result = $parser->next ) {
print $result->as_string;
}
Each result returned is a L<TAP::Parser::Result> subclass, referred to as
I<result types>.
=head2 Result types
Basically, you fetch individual results from the TAP. The six types, with
examples of each, are as follows:
=over 4
=item * Version
TAP version 12
=item * Plan
1..42
=item * Pragma
pragma +strict
=item * Test
ok 3 - We should start with some foobar!
=item * Comment
# Hope we don't use up the foobar.
=item * Bailout
Bail out! We ran out of foobar!
=item * Unknown
... yo, this ain't TAP! ...
=back
Each result fetched is a result object of a different type. There are common
methods to each result object and different types may have methods unique to
their type. Sometimes a type method may be overridden in a subclass, but its
use is guaranteed to be identical.
=head2 Common type methods
=head3 C<type>
Returns the type of result, such as C<comment> or C<test>.
=head3 C<as_string>
Prints a string representation of the token. This might not be the exact
output, however. Tests will have test numbers added if not present, TODO and
SKIP directives will be capitalized and, in general, things will be cleaned
up. If you need the original text for the token, see the C<raw> method.
=head3 C<raw>
Returns the original line of text which was parsed.
=head3 C<is_plan>
Indicates whether or not this is the test plan line.
=head3 C<is_test>
Indicates whether or not this is a test line.
=head3 C<is_comment>
Indicates whether or not this is a comment. Comments will generally only
appear in the TAP stream if STDERR is merged to STDOUT. See the
C<merge> option.
=head3 C<is_bailout>
Indicates whether or not this is bailout line.
=head3 C<is_yaml>
Indicates whether or not the current item is a YAML block.
=head3 C<is_unknown>
Indicates whether or not the current line could be parsed.
=head3 C<is_ok>
if ( $result->is_ok ) { ... }
Reports whether or not a given result has passed. Anything which is B<not> a
test result returns true. This is merely provided as a convenient shortcut
which allows you to do this:
my $parser = TAP::Parser->new( { source => $source } );
while ( my $result = $parser->next ) {
# only print failing results
print $result->as_string unless $result->is_ok;
}
=head2 C<plan> methods
if ( $result->is_plan ) { ... }
If the above evaluates as true, the following methods will be available on the
C<$result> object.
=head3 C<plan>
if ( $result->is_plan ) {
print $result->plan;
}
This is merely a synonym for C<as_string>.
=head3 C<directive>
my $directive = $result->directive;
If a SKIP directive is included with the plan, this method will return it.
1..0 # SKIP: why bother?
=head3 C<explanation>
my $explanation = $result->explanation;
If a SKIP directive was included with the plan, this method will return the
explanation, if any.
=head2 C<pragma> methods
if ( $result->is_pragma ) { ... }
If the above evaluates as true, the following methods will be available on the
C<$result> object.
=head3 C<pragmas>
Returns a list of pragmas each of which is a + or - followed by the
pragma name.
=head2 C<commment> methods
if ( $result->is_comment ) { ... }
If the above evaluates as true, the following methods will be available on the
C<$result> object.
=head3 C<comment>
if ( $result->is_comment ) {
my $comment = $result->comment;
print "I have something to say: $comment";
}
=head2 C<bailout> methods
if ( $result->is_bailout ) { ... }
If the above evaluates as true, the following methods will be available on the
C<$result> object.
=head3 C<explanation>
if ( $result->is_bailout ) {
my $explanation = $result->explanation;
print "We bailed out because ($explanation)";
}
If, and only if, a token is a bailout token, you can get an "explanation" via
this method. The explanation is the text after the mystical "Bail out!" words
which appear in the tap output.
=head2 C<unknown> methods
if ( $result->is_unknown ) { ... }
There are no unique methods for unknown results.
=head2 C<test> methods
if ( $result->is_test ) { ... }
If the above evaluates as true, the following methods will be available on the
C<$result> object.
=head3 C<ok>
my $ok = $result->ok;
Returns the literal text of the C<ok> or C<not ok> status.
=head3 C<number>
my $test_number = $result->number;
Returns the number of the test, even if the original TAP output did not supply
that number.
=head3 C<description>
my $description = $result->description;
Returns the description of the test, if any. This is the portion after the
test number but before the directive.
=head3 C<directive>
my $directive = $result->directive;
Returns either C<TODO> or C<SKIP> if either directive was present for a test
line.
=head3 C<explanation>
my $explanation = $result->explanation;
If a test had either a C<TODO> or C<SKIP> directive, this method will return
the accompanying explantion, if present.
not ok 17 - 'Pigs can fly' # TODO not enough acid
For the above line, the explanation is I<not enough acid>.
=head3 C<is_ok>
if ( $result->is_ok ) { ... }
Returns a boolean value indicating whether or not the test passed. Remember
that for TODO tests, the test always passes.
B<Note:> this was formerly C<passed>. The latter method is deprecated and
will issue a warning.
=head3 C<is_actual_ok>
if ( $result->is_actual_ok ) { ... }
Returns a boolean value indicating whether or not the test passed, regardless
of its TODO status.
B<Note:> this was formerly C<actual_passed>. The latter method is deprecated
and will issue a warning.
=head3 C<is_unplanned>
if ( $test->is_unplanned ) { ... }
If a test number is greater than the number of planned tests, this method will
return true. Unplanned tests will I<always> return false for C<is_ok>,
regardless of whether or not the test C<has_todo> (see
L<TAP::Parser::Result::Test> for more information about this).
=head3 C<has_skip>
if ( $result->has_skip ) { ... }
Returns a boolean value indicating whether or not this test had a SKIP
directive.
=head3 C<has_todo>
if ( $result->has_todo ) { ... }
Returns a boolean value indicating whether or not this test had a TODO
directive.
Note that TODO tests I<always> pass. If you need to know whether or not
they really passed, check the C<is_actual_ok> method.
=head3 C<in_todo>
if ( $parser->in_todo ) { ... }
True while the most recent result was a TODO. Becomes true before the
TODO result is returned and stays true until just before the next non-
TODO test is returned.
=head1 TOTAL RESULTS
After parsing the TAP, there are many methods available to let you dig through
the results and determine what is meaningful to you.
=head2 Individual Results
These results refer to individual tests which are run.
=head3 C<passed>
my @passed = $parser->passed; # the test numbers which passed
my $passed = $parser->passed; # the number of tests which passed
This method lets you know which (or how many) tests passed. If a test failed
but had a TODO directive, it will be counted as a passed test.
=cut
sub passed { @{ shift->{passed} } }
=head3 C<failed>
my @failed = $parser->failed; # the test numbers which failed
my $failed = $parser->failed; # the number of tests which failed
This method lets you know which (or how many) tests failed. If a test passed
but had a TODO directive, it will B<NOT> be counted as a failed test.
=cut
sub failed { @{ shift->{failed} } }
=head3 C<actual_passed>
# the test numbers which actually passed
my @actual_passed = $parser->actual_passed;
# the number of tests which actually passed
my $actual_passed = $parser->actual_passed;
This method lets you know which (or how many) tests actually passed,
regardless of whether or not a TODO directive was found.
=cut
sub actual_passed { @{ shift->{actual_passed} } }
*actual_ok = \&actual_passed;
=head3 C<actual_ok>
This method is a synonym for C<actual_passed>.
=head3 C<actual_failed>
# the test numbers which actually failed
my @actual_failed = $parser->actual_failed;
# the number of tests which actually failed
my $actual_failed = $parser->actual_failed;
This method lets you know which (or how many) tests actually failed,
regardless of whether or not a TODO directive was found.
=cut
sub actual_failed { @{ shift->{actual_failed} } }
##############################################################################
=head3 C<todo>
my @todo = $parser->todo; # the test numbers with todo directives
my $todo = $parser->todo; # the number of tests with todo directives
This method lets you know which (or how many) tests had TODO directives.
=cut
sub todo { @{ shift->{todo} } }
=head3 C<todo_passed>
# the test numbers which unexpectedly succeeded
my @todo_passed = $parser->todo_passed;
# the number of tests which unexpectedly succeeded
my $todo_passed = $parser->todo_passed;
This method lets you know which (or how many) tests actually passed but were
declared as "TODO" tests.
=cut
sub todo_passed { @{ shift->{todo_passed} } }
##############################################################################
=head3 C<todo_failed>
# deprecated in favor of 'todo_passed'. This method was horribly misnamed.
This was a badly misnamed method. It indicates which TODO tests unexpectedly
succeeded. Will now issue a warning and call C<todo_passed>.
=cut
sub todo_failed {
warn
'"todo_failed" is deprecated. Please use "todo_passed". See the docs.';
goto &todo_passed;
}
=head3 C<skipped>
my @skipped = $parser->skipped; # the test numbers with SKIP directives
my $skipped = $parser->skipped; # the number of tests with SKIP directives
This method lets you know which (or how many) tests had SKIP directives.
=cut
sub skipped { @{ shift->{skipped} } }
=head2 Pragmas
=head3 C<pragma>
Get or set a pragma. To get the state of a pragma:
if ( $p->pragma('strict') ) {
# be strict
}
To set the state of a pragma:
$p->pragma('strict', 1); # enable strict mode
=cut
sub pragma {
my ( $self, $pragma ) = splice @_, 0, 2;
return $self->{pragma}->{$pragma} unless @_;
if ( my $state = shift ) {
$self->{pragma}->{$pragma} = 1;
}
else {
delete $self->{pragma}->{$pragma};
}
return;
}
=head3 C<pragmas>
Get a list of all the currently enabled pragmas:
my @pragmas_enabled = $p->pragmas;
=cut
sub pragmas { sort keys %{ shift->{pragma} || {} } }
=head2 Summary Results
These results are "meta" information about the total results of an individual
test program.
=head3 C<plan>
my $plan = $parser->plan;
Returns the test plan, if found.
=head3 C<good_plan>
Deprecated. Use C<is_good_plan> instead.