| 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::Tools::Tester 3perl" |
| 58 |
.TH Test2::Tools::Tester 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::Tools::Tester \- Tools to help you test other testing tools. |
| 65 |
.SH DESCRIPTION |
| 66 |
.IX Header "DESCRIPTION" |
| 67 |
This is a collection of tools that are useful when testing other test tools. |
| 68 |
.SH SYNOPSIS |
| 69 |
.IX Header "SYNOPSIS" |
| 70 |
.Vb 1 |
| 71 |
\& use Test2::Tools::Tester qw/event_groups filter_events facets/; |
| 72 |
\& |
| 73 |
\& use Test2::Tools::Basic qw/plan pass ok/; |
| 74 |
\& use Test2::Tools::Compare qw/is like/; |
| 75 |
\& |
| 76 |
\& my $events = intercept { |
| 77 |
\& plan 11; |
| 78 |
\& |
| 79 |
\& pass(\*(Aqpass\*(Aq); |
| 80 |
\& ok(1, \*(Aqpass\*(Aq); |
| 81 |
\& |
| 82 |
\& is(1, 1, "pass"); |
| 83 |
\& like(1, 1, "pass"); |
| 84 |
\& }; |
| 85 |
\& |
| 86 |
\& # Grab events generated by tools in Test2::Tools::Basic |
| 87 |
\& my $basic = filter $events => \*(AqTest2::Tools::Basic\*(Aq; |
| 88 |
\& |
| 89 |
\& # Grab events generated by Test2::Tools::Basic; |
| 90 |
\& my $compare = filter $events => \*(AqTest2::Tools::Compare\*(Aq; |
| 91 |
\& |
| 92 |
\& # Grab events generated by tools named \*(Aqok\*(Aq. |
| 93 |
\& my $oks = filter $events => qr/.*::ok$/; |
| 94 |
\& |
| 95 |
\& my $grouped = group_events $events; |
| 96 |
\& # Breaks events into this structure: |
| 97 |
\& { |
| 98 |
\& \*(Aq_\|_NA_\|_\*(Aq => [ ... ], |
| 99 |
\& \*(AqTest2::Tools::Basic\*(Aq => { |
| 100 |
\& \*(Aq_\|_ALL_\|_\*(Aq => [ $events\->[0], $events\->[1], $events\->[2] ], |
| 101 |
\& plan => [ $events\->[0] ], |
| 102 |
\& pass => [ $events\->[1] ], |
| 103 |
\& ok => [ $events\->[2] ], |
| 104 |
\& }, |
| 105 |
\& Test2::Tools::Compare => { ... }, |
| 106 |
\& } |
| 107 |
\& |
| 108 |
\& # Get an arrayref of all the assert facets from the list of events. |
| 109 |
\& my $assert_facets = facets assert => $events; |
| 110 |
\& # [ |
| 111 |
\& # bless({ details => \*(Aqpass\*(Aq, pass => 1}, \*(AqTest2::EventFacet::Assert\*(Aq), |
| 112 |
\& # bless({ details => \*(Aqpass\*(Aq, pass => 1}, \*(AqTest2::EventFacet::Assert\*(Aq), |
| 113 |
\& # ] |
| 114 |
\& |
| 115 |
\& # Same, but for info facets |
| 116 |
\& my $info_facets = facets info => $events; |
| 117 |
.Ve |
| 118 |
.SH EXPORTS |
| 119 |
.IX Header "EXPORTS" |
| 120 |
No subs are exported by default. |
| 121 |
.ie n .IP "$array_ref = filter $events => $PACKAGE" 4 |
| 122 |
.el .IP "\f(CW$array_ref\fR = filter \f(CW$events\fR => \f(CW$PACKAGE\fR" 4 |
| 123 |
.IX Item "$array_ref = filter $events => $PACKAGE" |
| 124 |
.PD 0 |
| 125 |
.ie n .IP "$array_ref = filter $events => $PACKAGE1, $PACKAGE2" 4 |
| 126 |
.el .IP "\f(CW$array_ref\fR = filter \f(CW$events\fR => \f(CW$PACKAGE1\fR, \f(CW$PACKAGE2\fR" 4 |
| 127 |
.IX Item "$array_ref = filter $events => $PACKAGE1, $PACKAGE2" |
| 128 |
.ie n .IP "$array_ref = filter $events => qr/match/" 4 |
| 129 |
.el .IP "\f(CW$array_ref\fR = filter \f(CW$events\fR => qr/match/" 4 |
| 130 |
.IX Item "$array_ref = filter $events => qr/match/" |
| 131 |
.ie n .IP "$array_ref = filter $events => qr/match/, $PACKAGE" 4 |
| 132 |
.el .IP "\f(CW$array_ref\fR = filter \f(CW$events\fR => qr/match/, \f(CW$PACKAGE\fR" 4 |
| 133 |
.IX Item "$array_ref = filter $events => qr/match/, $PACKAGE" |
| 134 |
.PD |
| 135 |
This function takes an arrayref of events as the first argument. All additional |
| 136 |
arguments must either be a package name, or a regex. Any event that is |
| 137 |
generated by a tool in any of the package, or by a tool that matches any of the |
| 138 |
regexes, will be returned in an arrayref. |
| 139 |
.ie n .IP "$grouped = group_events($events)" 4 |
| 140 |
.el .IP "\f(CW$grouped\fR = group_events($events)" 4 |
| 141 |
.IX Item "$grouped = group_events($events)" |
| 142 |
This function iterates all the events in the argument arrayref and splits them |
| 143 |
into groups. The resulting data structure is: |
| 144 |
.Sp |
| 145 |
.Vb 1 |
| 146 |
\& { PACKAGE => { SUBNAME => [ $EVENT1, $EVENT2, ... }} |
| 147 |
.Ve |
| 148 |
.Sp |
| 149 |
If the package of an event is not known it will be put into and arrayref under |
| 150 |
the '_\|_NA_\|_' key at the root of the structure. If a sub name is not known it |
| 151 |
will typically go under the '_\|_ANON_\|_' key in under the package name. |
| 152 |
.Sp |
| 153 |
In addition there is an '_\|_ALL_\|_' key under each package which stores all of |
| 154 |
the events sorted into that group. |
| 155 |
.Sp |
| 156 |
A more complete example: |
| 157 |
.Sp |
| 158 |
.Vb 9 |
| 159 |
\& { |
| 160 |
\& \*(Aq_\|_NA_\|_\*(Aq => [ $event\->[3] ], |
| 161 |
\& \*(AqTest2::Tools::Basic\*(Aq => { |
| 162 |
\& \*(Aq_\|_ALL_\|_\*(Aq => [ $events\->[0], $events\->[1], $events\->[2] ], |
| 163 |
\& plan => [ $events\->[0] ], |
| 164 |
\& pass => [ $events\->[1] ], |
| 165 |
\& ok => [ $events\->[2] ], |
| 166 |
\& }, |
| 167 |
\& } |
| 168 |
.Ve |
| 169 |
.ie n .IP "$arrayref = facets TYPE => $events" 4 |
| 170 |
.el .IP "\f(CW$arrayref\fR = facets TYPE => \f(CW$events\fR" 4 |
| 171 |
.IX Item "$arrayref = facets TYPE => $events" |
| 172 |
This function will compile a list of all facets of the specified type that are |
| 173 |
found in the arrayref of events. If the facet has a \f(CW\*(C`Test2::EventFacet::TYPE\*(C'\fR |
| 174 |
package available then the facet will be constructed into an instance of the |
| 175 |
class, otherwise it is left as a hashref. Facet Order is preserved. |
| 176 |
.Sp |
| 177 |
.Vb 5 |
| 178 |
\& my $assert_facets = facets assert => $events; |
| 179 |
\& # [ |
| 180 |
\& # bless({ details => \*(Aqpass\*(Aq, pass => 1}, \*(AqTest2::EventFacet::Assert\*(Aq), |
| 181 |
\& # bless({ details => \*(Aqpass\*(Aq, pass => 1}, \*(AqTest2::EventFacet::Assert\*(Aq), |
| 182 |
\& # ] |
| 183 |
.Ve |
| 184 |
.SH SOURCE |
| 185 |
.IX Header "SOURCE" |
| 186 |
The source code repository for Test2\-Suite can be found at |
| 187 |
\&\fIhttps://github.com/Test\-More/Test2\-Suite/\fR. |
| 188 |
.SH MAINTAINERS |
| 189 |
.IX Header "MAINTAINERS" |
| 190 |
.IP "Chad Granum <[email protected]>" 4 |
| 191 |
.IX Item "Chad Granum <[email protected]>" |
| 192 |
.SH AUTHORS |
| 193 |
.IX Header "AUTHORS" |
| 194 |
.PD 0 |
| 195 |
.IP "Chad Granum <[email protected]>" 4 |
| 196 |
.IX Item "Chad Granum <[email protected]>" |
| 197 |
.PD |
| 198 |
.SH COPYRIGHT |
| 199 |
.IX Header "COPYRIGHT" |
| 200 |
Copyright 2018 Chad Granum <[email protected]>. |
| 201 |
.PP |
| 202 |
This program is free software; you can redistribute it and/or |
| 203 |
modify it under the same terms as Perl itself. |
| 204 |
.PP |
| 205 |
See \fIhttp://dev.perl.org/licenses/\fR |