1TAP::Parser::Result(3)User Contributed Perl DocumentationTAP::Parser::Result(3)
2
3
4
6 TAP::Parser::Result - Base class for TAP::Parser output objects
7
9 Version 3.42
10
12 # abstract class - not meant to be used directly
13 # see TAP::Parser::ResultFactory for preferred usage
14
15 # directly:
16 use TAP::Parser::Result;
17 my $token = {...};
18 my $result = TAP::Parser::Result->new( $token );
19
20 DESCRIPTION
21 This is a simple base class used by TAP::Parser to store objects that
22 represent the current bit of test output data from TAP (usually a
23 single line). Unless you're subclassing, you probably won't need to
24 use this module directly.
25
26 METHODS
27 "new"
28
29 # see TAP::Parser::ResultFactory for preferred usage
30
31 # to use directly:
32 my $result = TAP::Parser::Result->new($token);
33
34 Returns an instance the appropriate class for the test token passed in.
35
36 Boolean methods
37 The following methods all return a boolean value and are to be
38 overridden in the appropriate subclass.
39
40 · "is_plan"
41
42 Indicates whether or not this is the test plan line.
43
44 1..3
45
46 · "is_pragma"
47
48 Indicates whether or not this is a pragma line.
49
50 pragma +strict
51
52 · "is_test"
53
54 Indicates whether or not this is a test line.
55
56 ok 1 Is OK!
57
58 · "is_comment"
59
60 Indicates whether or not this is a comment.
61
62 # this is a comment
63
64 · "is_bailout"
65
66 Indicates whether or not this is bailout line.
67
68 Bail out! We're out of dilithium crystals.
69
70 · "is_version"
71
72 Indicates whether or not this is a TAP version line.
73
74 TAP version 4
75
76 · "is_unknown"
77
78 Indicates whether or not the current line could be parsed.
79
80 ... this line is junk ...
81
82 · "is_yaml"
83
84 Indicates whether or not this is a YAML chunk.
85
86 "raw"
87
88 print $result->raw;
89
90 Returns the original line of text which was parsed.
91
92 "type"
93
94 my $type = $result->type;
95
96 Returns the "type" of a token, such as "comment" or "test".
97
98 "as_string"
99
100 print $result->as_string;
101
102 Prints a string representation of the token. This might not be the
103 exact output, however. Tests will have test numbers added if not
104 present, TODO and SKIP directives will be capitalized and, in general,
105 things will be cleaned up. If you need the original text for the
106 token, see the "raw" method.
107
108 "is_ok"
109
110 if ( $result->is_ok ) { ... }
111
112 Reports whether or not a given result has passed. Anything which is
113 not a test result returns true. This is merely provided as a
114 convenient shortcut.
115
116 "passed"
117
118 Deprecated. Please use "is_ok" instead.
119
120 "has_directive"
121
122 if ( $result->has_directive ) {
123 ...
124 }
125
126 Indicates whether or not the given result has a TODO or SKIP directive.
127
128 "has_todo"
129
130 if ( $result->has_todo ) {
131 ...
132 }
133
134 Indicates whether or not the given result has a TODO directive.
135
136 "has_skip"
137
138 if ( $result->has_skip ) {
139 ...
140 }
141
142 Indicates whether or not the given result has a SKIP directive.
143
144 "set_directive"
145
146 Set the directive associated with this token. Used internally to fake
147 TODO tests.
148
150 Please see "SUBCLASSING" in TAP::Parser for a subclassing overview.
151
152 Remember: if you want your subclass to be automatically used by the
153 parser, you'll have to register it with "register_type" in
154 TAP::Parser::ResultFactory.
155
156 If you're creating a completely new result type, you'll probably need
157 to subclass TAP::Parser::Grammar too, or else it'll never get used.
158
159 Example
160 package MyResult;
161
162 use strict;
163
164 use base 'TAP::Parser::Result';
165
166 # register with the factory:
167 TAP::Parser::ResultFactory->register_type( 'my_type' => __PACKAGE__ );
168
169 sub as_string { 'My results all look the same' }
170
172 TAP::Object, TAP::Parser, TAP::Parser::ResultFactory,
173 TAP::Parser::Result::Bailout, TAP::Parser::Result::Comment,
174 TAP::Parser::Result::Plan, TAP::Parser::Result::Pragma,
175 TAP::Parser::Result::Test, TAP::Parser::Result::Unknown,
176 TAP::Parser::Result::Version, TAP::Parser::Result::YAML,
177
178
179
180perl v5.30.0 2019-07-26 TAP::Parser::Result(3)