1Test2::Formatter(3) User Contributed Perl Documentation Test2::Formatter(3)
2
3
4
6 Test2::Formatter - Namespace for formatters.
7
9 This is the namespace for formatters. This is an empty package.
10
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
49 tell buffered subtests whether or not to send it events as they are
50 being buffered. See "run_subtest(...)" in Test2::API for more
51 information.
52
53 The "terminate" and "finalize" methods are optional methods called that
54 you can implement if the format you're generating needs to handle these
55 cases, for example if you are generating XML and need close open tags.
56
57 The "terminate" method is called when an event's "terminate" method
58 returns true, for example when a Test2::Event::Plan has a 'skip_all'
59 plan, or when a Test2::Event::Bail event is sent. The "terminate"
60 method is passed a single argument, the Test2::Event object which
61 triggered the terminate.
62
63 The "finalize" method is always the last thing called on the formatter,
64 except when "terminate" is called for a Bail event. It is passed the
65 following arguments:
66
67 The "supports_tables" method should be true if the formatter supports
68 directly rendering table data from the "info" facets. This is a newer
69 feature and many older formatters may not support it. When not
70 supported the formatter falls back to rendering "detail" instead of the
71 "table" data.
72
73 The "new_root" method is used when constructing a root formatter. The
74 default is to just delegate to the regular "new()" method, most
75 formatters can ignore this.
76
77 • The number of tests that were planned
78
79 • The number of tests actually seen
80
81 • The number of tests which failed
82
83 • A boolean indicating whether or not the test suite passed
84
85 • A boolean indicating whether or not this call is for a subtest
86
87 The "new_root" method is called when "Test2::API::Stack" Initializes
88 the root hub for the first time. Most formatters will simply have this
89 call "$class->new", which is the default behavior. Some formatters
90 however may want to take extra action during construction of the root
91 formatter, this is where they can do that.
92
94 The source code repository for Test2 can be found at
95 http://github.com/Test-More/test-more/.
96
98 Chad Granum <exodist@cpan.org>
99
101 Chad Granum <exodist@cpan.org>
102
104 Copyright 2020 Chad Granum <exodist@cpan.org>.
105
106 This program is free software; you can redistribute it and/or modify it
107 under the same terms as Perl itself.
108
109 See http://dev.perl.org/licenses/
110
111
112
113perl v5.34.0 2022-03-05 Test2::Formatter(3)