1Test2::Formatter(3)   User Contributed Perl Documentation  Test2::Formatter(3)
2
3
4

NAME

6       Test2::Formatter - Namespace for formatters.
7

DESCRIPTION

9       This is the namespace for formatters. This is an empty package.
10

CREATING FORMATTERS

12       A formatter is any package or object with a "write($event, $num)"
13       method.
14
15           package Test2::Formatter::Foo;
16           use strict;
17           use warnings;
18
19           sub write {
20               my $self_or_class = shift;
21               my ($event, $assert_num) = @_;
22               ...
23           }
24
25           sub hide_buffered { 1 }
26
27           sub terminate { }
28
29           sub finalize { }
30
31           sub supports_tables { return $BOOL }
32
33           sub new_root {
34               my $class = shift;
35               ...
36               $class->new(@_);
37           }
38
39           1;
40
41       The "write" method is a method, so it either gets a class or instance.
42       The two arguments are the $event object it should record, and the
43       $assert_num which is the number of the current assertion (ok), or the
44       last assertion if this event is not itself an assertion. The assertion
45       number may be any integer 0 or greater, and may be undefined in some
46       cases.
47
48       The hide_buffered() method must return a boolean. This is used to tell
49       buffered subtests whether or not to send it events as they are being
50       buffered.  See "run_subtest(...)" in Test2::API for more information.
51
52       The "terminate" and "finalize" methods are optional methods called that
53       you can implement if the format you're generating needs to handle these
54       cases, for example if you are generating XML and need close open tags.
55
56       The "terminate" method is called when an event's "terminate" method
57       returns true, for example when a Test2::Event::Plan has a 'skip_all'
58       plan, or when a Test2::Event::Bail event is sent. The "terminate"
59       method is passed a single argument, the Test2::Event object which
60       triggered the terminate.
61
62       The "finalize" method is always the last thing called on the formatter,
63       except when "terminate" is called for a Bail event. It is passed the
64       following arguments:
65
66       The "supports_tables" method should be true if the formatter supports
67       directly rendering table data from the "info" facets. This is a newer
68       feature and many older formatters may not support it. When not
69       supported the formatter falls back to rendering "detail" instead of the
70       "table" data.
71
72       The "new_root" method is used when constructing a root formatter. The
73       default is to just delegate to the regular new() method, most
74       formatters can ignore this.
75
76       •   The number of tests that were planned
77
78       •   The number of tests actually seen
79
80       •   The number of tests which failed
81
82       •   A boolean indicating whether or not the test suite passed
83
84       •   A boolean indicating whether or not this call is for a subtest
85
86       The "new_root" method is called when "Test2::API::Stack" Initializes
87       the root hub for the first time. Most formatters will simply have this
88       call "$class->new", which is the default behavior. Some formatters
89       however may want to take extra action during construction of the root
90       formatter, this is where they can do that.
91

SOURCE

93       The source code repository for Test2 can be found at
94       http://github.com/Test-More/test-more/.
95

MAINTAINERS

97       Chad Granum <exodist@cpan.org>
98

AUTHORS

100       Chad Granum <exodist@cpan.org>
101
103       Copyright 2020 Chad Granum <exodist@cpan.org>.
104
105       This program is free software; you can redistribute it and/or modify it
106       under the same terms as Perl itself.
107
108       See http://dev.perl.org/licenses/
109
110
111
112perl v5.36.0                      2023-03-15               Test2::Formatter(3)
Impressum