Debian Codegraph @

upstream/mageia-cauldron/man3pm/Test2::Formatter.3pm

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man v6.0.2 (Pod::Simple 3.45)
3 .\"
4 .\" Standard preamble:
5 .\" ========================================================================
6 .de Sp \" Vertical space (when we can't use .PP)
7 .if t .sp .5v
8 .if n .sp
9 ..
10 .de Vb \" Begin verbatim text
11 .ft CW
12 .nf
13 .ne \\$1
14 ..
15 .de Ve \" End verbatim text
16 .ft R
17 .fi
18 ..
19 .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20 .ie n \{\
21 . ds C` ""
22 . ds C' ""
23 'br\}
24 .el\{\
25 . ds C`
26 . ds C'
27 'br\}
28 .\"
29 .\" Escape single quotes in literal strings from groff's Unicode transform.
30 .ie \n(.g .ds Aq \(aq
31 .el .ds Aq '
32 .\"
33 .\" If the F register is >0, we'll generate index entries on stderr for
34 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35 .\" entries marked with X<> in POD. Of course, you'll have to process the
36 .\" output yourself in some meaningful fashion.
37 .\"
38 .\" Avoid warning from groff about undefined register 'F'.
39 .de IX
40 ..
41 .nr rF 0
42 .if \n(.g .if rF .nr rF 1
43 .if (\n(rF:(\n(.g==0)) \{\
44 . if \nF \{\
45 . de IX
46 . tm Index:\\$1\t\\n%\t"\\$2"
47 ..
48 . if !\nF==2 \{\
49 . nr % 0
50 . nr F 2
51 . \}
52 . \}
53 .\}
54 .rr rF
55 .\"
56 .\" Required to disable full justification in groff 1.23.0.
57 .if n .ds AD l
58 .\" ========================================================================
59 .\"
60 .IX Title "Test2::Formatter 3pm"
61 .TH Test2::Formatter 3pm 2025-06-24 "perl v5.42.0" "Perl Programmers Reference Guide"
62 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
63 .\" way too many mistakes in technical documents.
64 .if n .ad l
65 .nh
66 .SH NAME
67 Test2::Formatter \- Namespace for formatters.
68 .SH DESCRIPTION
69 .IX Header "DESCRIPTION"
70 This is the namespace for formatters. This is an empty package.
71 .SH "CREATING FORMATTERS"
72 .IX Header "CREATING FORMATTERS"
73 A formatter is any package or object with a \f(CW\*(C`write($event, $num)\*(C'\fR method.
74 .PP
75 .Vb 3
76 \& package Test2::Formatter::Foo;
77 \& use strict;
78 \& use warnings;
79 \&
80 \& sub write {
81 \& my $self_or_class = shift;
82 \& my ($event, $assert_num) = @_;
83 \& ...
84 \& }
85 \&
86 \& sub hide_buffered { 1 }
87 \&
88 \& sub terminate { }
89 \&
90 \& sub finalize { }
91 \&
92 \& sub supports_tables { return $BOOL }
93 \&
94 \& sub new_root {
95 \& my $class = shift;
96 \& ...
97 \& $class\->new(@_);
98 \& }
99 \&
100 \& 1;
101 .Ve
102 .PP
103 The \f(CW\*(C`write\*(C'\fR method is a method, so it either gets a class or instance. The two
104 arguments are the \f(CW$event\fR object it should record, and the \f(CW$assert_num\fR
105 which is the number of the current assertion (ok), or the last assertion if
106 this event is not itself an assertion. The assertion number may be any integer 0
107 or greater, and may be undefined in some cases.
108 .PP
109 The \f(CWhide_buffered()\fR method must return a boolean. This is used to tell
110 buffered subtests whether or not to send it events as they are being buffered.
111 See "run_subtest(...)" in Test2::API for more information.
112 .PP
113 The \f(CW\*(C`terminate\*(C'\fR and \f(CW\*(C`finalize\*(C'\fR methods are optional methods called that you
114 can implement if the format you\*(Aqre generating needs to handle these cases, for
115 example if you are generating XML and need close open tags.
116 .PP
117 The \f(CW\*(C`terminate\*(C'\fR method is called when an event\*(Aqs \f(CW\*(C`terminate\*(C'\fR method returns
118 true, for example when a Test2::Event::Plan has a \f(CW\*(Aqskip_all\*(Aq\fR plan, or
119 when a Test2::Event::Bail event is sent. The \f(CW\*(C`terminate\*(C'\fR method is passed
120 a single argument, the Test2::Event object which triggered the terminate.
121 .PP
122 The \f(CW\*(C`finalize\*(C'\fR method is always the last thing called on the formatter, \fIexcept when \fR\f(CI\*(C`terminate\*(C'\fR\fI is called for a Bail event\fR. It is passed the
123 following arguments:
124 .PP
125 The \f(CW\*(C`supports_tables\*(C'\fR method should be true if the formatter supports directly
126 rendering table data from the \f(CW\*(C`info\*(C'\fR facets. This is a newer feature and many
127 older formatters may not support it. When not supported the formatter falls
128 back to rendering \f(CW\*(C`detail\*(C'\fR instead of the \f(CW\*(C`table\*(C'\fR data.
129 .PP
130 The \f(CW\*(C`new_root\*(C'\fR method is used when constructing a root formatter. The default
131 is to just delegate to the regular \f(CWnew()\fR method, most formatters can ignore
132 this.
133 .IP \(bu 4
134 The number of tests that were planned
135 .IP \(bu 4
136 The number of tests actually seen
137 .IP \(bu 4
138 The number of tests which failed
139 .IP \(bu 4
140 A boolean indicating whether or not the test suite passed
141 .IP \(bu 4
142 A boolean indicating whether or not this call is for a subtest
143 .PP
144 The \f(CW\*(C`new_root\*(C'\fR method is called when \f(CW\*(C`Test2::API::Stack\*(C'\fR Initializes the root
145 hub for the first time. Most formatters will simply have this call \f(CW\*(C`$class\->new\*(C'\fR, which is the default behavior. Some formatters however may want
146 to take extra action during construction of the root formatter, this is where
147 they can do that.
148 .SH SOURCE
149 .IX Header "SOURCE"
150 The source code repository for Test2 can be found at
151 <https://github.com/Test\-More/test\-more/>.
152 .SH MAINTAINERS
153 .IX Header "MAINTAINERS"
154 .IP "Chad Granum <[email protected]>" 4
155 .IX Item "Chad Granum <[email protected]>"
156 .SH AUTHORS
157 .IX Header "AUTHORS"
158 .IP "Chad Granum <[email protected]>" 4
159 .IX Item "Chad Granum <[email protected]>"
160 .SH COPYRIGHT
161 .IX Header "COPYRIGHT"
162 Copyright Chad Granum <[email protected]>.
163 .PP
164 This program is free software; you can redistribute it and/or
165 modify it under the same terms as Perl itself.
166 .PP
167 See <https://dev.perl.org/licenses/>