1 package Test2::Formatter;
5 our $VERSION = '1.302195';
11 return if $class eq __PACKAGE__;
12 return if $ADDED{$class}++;
14 Test2::API::test2_formatter_add($class);
19 return $class->new(@_);
22 sub supports_tables { 0 }
24 sub hide_buffered { 1 }
40 Test2::Formatter - Namespace for formatters.
44 This is the namespace for formatters. This is an empty package.
46 =head1 CREATING FORMATTERS
48 A formatter is any package or object with a C<write($event, $num)> method.
50 package Test2::Formatter::Foo;
55 my $self_or_class = shift;
56 my ($event, $assert_num) = @_;
60 sub hide_buffered { 1 }
66 sub supports_tables { return $BOOL }
76 The C<write> method is a method, so it either gets a class or instance. The two
77 arguments are the C<$event> object it should record, and the C<$assert_num>
78 which is the number of the current assertion (ok), or the last assertion if
79 this event is not itself an assertion. The assertion number may be any integer 0
80 or greater, and may be undefined in some cases.
82 The C<hide_buffered()> method must return a boolean. This is used to tell
83 buffered subtests whether or not to send it events as they are being buffered.
84 See L<Test2::API/"run_subtest(...)"> for more information.
86 The C<terminate> and C<finalize> methods are optional methods called that you
87 can implement if the format you're generating needs to handle these cases, for
88 example if you are generating XML and need close open tags.
90 The C<terminate> method is called when an event's C<terminate> method returns
91 true, for example when a L<Test2::Event::Plan> has a C<'skip_all'> plan, or
92 when a L<Test2::Event::Bail> event is sent. The C<terminate> method is passed
93 a single argument, the L<Test2::Event> object which triggered the terminate.
95 The C<finalize> method is always the last thing called on the formatter, I<<
96 except when C<terminate> is called for a Bail event >>. It is passed the
99 The C<supports_tables> method should be true if the formatter supports directly
100 rendering table data from the C<info> facets. This is a newer feature and many
101 older formatters may not support it. When not supported the formatter falls
102 back to rendering C<detail> instead of the C<table> data.
104 The C<new_root> method is used when constructing a root formatter. The default
105 is to just delegate to the regular C<new()> method, most formatters can ignore
110 =item * The number of tests that were planned
112 =item * The number of tests actually seen
114 =item * The number of tests which failed
116 =item * A boolean indicating whether or not the test suite passed
118 =item * A boolean indicating whether or not this call is for a subtest
122 The C<new_root> method is called when C<Test2::API::Stack> Initializes the root
123 hub for the first time. Most formatters will simply have this call C<<
124 $class->new >>, which is the default behavior. Some formatters however may want
125 to take extra action during construction of the root formatter, this is where
130 The source code repository for Test2 can be found at
131 F<http://github.com/Test-More/test-more/>.
137 =item Chad Granum E<lt>exodist@cpan.orgE<gt>
145 =item Chad Granum E<lt>exodist@cpan.orgE<gt>
151 Copyright 2020 Chad Granum E<lt>exodist@cpan.orgE<gt>.
153 This program is free software; you can redistribute it and/or
154 modify it under the same terms as Perl itself.
156 See F<http://dev.perl.org/licenses/>