| 1 |
.\" -*- mode: troff; coding: utf-8 -*- |
| 2 |
.\" Automatically generated by Pod::Man 5.0102 (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 |
.\" |
| 57 |
.IX Title "Test2::Formatter 3perl" |
| 58 |
.TH Test2::Formatter 3perl 2025-11-16 "perl v5.40.1" "Perl Programmers Reference Guide" |
| 59 |
.\" For nroff, turn off justification. Always turn off hyphenation; it makes |
| 60 |
.\" way too many mistakes in technical documents. |
| 61 |
.if n .ad l |
| 62 |
.nh |
| 63 |
.SH NAME |
| 64 |
Test2::Formatter \- Namespace for formatters. |
| 65 |
.SH DESCRIPTION |
| 66 |
.IX Header "DESCRIPTION" |
| 67 |
This is the namespace for formatters. This is an empty package. |
| 68 |
.SH "CREATING FORMATTERS" |
| 69 |
.IX Header "CREATING FORMATTERS" |
| 70 |
A formatter is any package or object with a \f(CW\*(C`write($event, $num)\*(C'\fR method. |
| 71 |
.PP |
| 72 |
.Vb 3 |
| 73 |
\& package Test2::Formatter::Foo; |
| 74 |
\& use strict; |
| 75 |
\& use warnings; |
| 76 |
\& |
| 77 |
\& sub write { |
| 78 |
\& my $self_or_class = shift; |
| 79 |
\& my ($event, $assert_num) = @_; |
| 80 |
\& ... |
| 81 |
\& } |
| 82 |
\& |
| 83 |
\& sub hide_buffered { 1 } |
| 84 |
\& |
| 85 |
\& sub terminate { } |
| 86 |
\& |
| 87 |
\& sub finalize { } |
| 88 |
\& |
| 89 |
\& sub supports_tables { return $BOOL } |
| 90 |
\& |
| 91 |
\& sub new_root { |
| 92 |
\& my $class = shift; |
| 93 |
\& ... |
| 94 |
\& $class\->new(@_); |
| 95 |
\& } |
| 96 |
\& |
| 97 |
\& 1; |
| 98 |
.Ve |
| 99 |
.PP |
| 100 |
The \f(CW\*(C`write\*(C'\fR method is a method, so it either gets a class or instance. The two |
| 101 |
arguments are the \f(CW$event\fR object it should record, and the \f(CW$assert_num\fR |
| 102 |
which is the number of the current assertion (ok), or the last assertion if |
| 103 |
this event is not itself an assertion. The assertion number may be any integer 0 |
| 104 |
or greater, and may be undefined in some cases. |
| 105 |
.PP |
| 106 |
The \f(CWhide_buffered()\fR method must return a boolean. This is used to tell |
| 107 |
buffered subtests whether or not to send it events as they are being buffered. |
| 108 |
See "run_subtest(...)" in Test2::API for more information. |
| 109 |
.PP |
| 110 |
The \f(CW\*(C`terminate\*(C'\fR and \f(CW\*(C`finalize\*(C'\fR methods are optional methods called that you |
| 111 |
can implement if the format you're generating needs to handle these cases, for |
| 112 |
example if you are generating XML and need close open tags. |
| 113 |
.PP |
| 114 |
The \f(CW\*(C`terminate\*(C'\fR method is called when an event's \f(CW\*(C`terminate\*(C'\fR method returns |
| 115 |
true, for example when a Test2::Event::Plan has a \f(CW\*(Aqskip_all\*(Aq\fR plan, or |
| 116 |
when a Test2::Event::Bail event is sent. The \f(CW\*(C`terminate\*(C'\fR method is passed |
| 117 |
a single argument, the Test2::Event object which triggered the terminate. |
| 118 |
.PP |
| 119 |
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 |
| 120 |
following arguments: |
| 121 |
.PP |
| 122 |
The \f(CW\*(C`supports_tables\*(C'\fR method should be true if the formatter supports directly |
| 123 |
rendering table data from the \f(CW\*(C`info\*(C'\fR facets. This is a newer feature and many |
| 124 |
older formatters may not support it. When not supported the formatter falls |
| 125 |
back to rendering \f(CW\*(C`detail\*(C'\fR instead of the \f(CW\*(C`table\*(C'\fR data. |
| 126 |
.PP |
| 127 |
The \f(CW\*(C`new_root\*(C'\fR method is used when constructing a root formatter. The default |
| 128 |
is to just delegate to the regular \f(CWnew()\fR method, most formatters can ignore |
| 129 |
this. |
| 130 |
.IP \(bu 4 |
| 131 |
The number of tests that were planned |
| 132 |
.IP \(bu 4 |
| 133 |
The number of tests actually seen |
| 134 |
.IP \(bu 4 |
| 135 |
The number of tests which failed |
| 136 |
.IP \(bu 4 |
| 137 |
A boolean indicating whether or not the test suite passed |
| 138 |
.IP \(bu 4 |
| 139 |
A boolean indicating whether or not this call is for a subtest |
| 140 |
.PP |
| 141 |
The \f(CW\*(C`new_root\*(C'\fR method is called when \f(CW\*(C`Test2::API::Stack\*(C'\fR Initializes the root |
| 142 |
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 |
| 143 |
to take extra action during construction of the root formatter, this is where |
| 144 |
they can do that. |
| 145 |
.SH SOURCE |
| 146 |
.IX Header "SOURCE" |
| 147 |
The source code repository for Test2 can be found at |
| 148 |
<https://github.com/Test\-More/test\-more/>. |
| 149 |
.SH MAINTAINERS |
| 150 |
.IX Header "MAINTAINERS" |
| 151 |
.IP "Chad Granum <[email protected]>" 4 |
| 152 |
.IX Item "Chad Granum <[email protected]>" |
| 153 |
.SH AUTHORS |
| 154 |
.IX Header "AUTHORS" |
| 155 |
.PD 0 |
| 156 |
.IP "Chad Granum <[email protected]>" 4 |
| 157 |
.IX Item "Chad Granum <[email protected]>" |
| 158 |
.PD |
| 159 |
.SH COPYRIGHT |
| 160 |
.IX Header "COPYRIGHT" |
| 161 |
Copyright 2020 Chad Granum <[email protected]>. |
| 162 |
.PP |
| 163 |
This program is free software; you can redistribute it and/or |
| 164 |
modify it under the same terms as Perl itself. |
| 165 |
.PP |
| 166 |
See <https://dev.perl.org/licenses/> |