| 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::Subtest 3perl" |
| 58 |
.TH Test2::Tools::Subtest 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::Subtest \- Tools for writing subtests |
| 65 |
.SH DESCRIPTION |
| 66 |
.IX Header "DESCRIPTION" |
| 67 |
This package exports subs that let you write subtests. |
| 68 |
.PP |
| 69 |
There are two types of subtests, buffered and streamed. Streamed subtests mimic |
| 70 |
subtests from Test::More in that they render all events as soon as they are |
| 71 |
produced. Buffered subtests wait until the subtest completes before rendering |
| 72 |
any results. |
| 73 |
.PP |
| 74 |
The main difference is that streamed subtests are unreadable when combined with |
| 75 |
concurrency. Buffered subtests look fine with any number of concurrent threads |
| 76 |
and processes. |
| 77 |
.SH SYNOPSIS |
| 78 |
.IX Header "SYNOPSIS" |
| 79 |
.SS BUFFERED |
| 80 |
.IX Subsection "BUFFERED" |
| 81 |
.Vb 1 |
| 82 |
\& use Test2::Tools::Subtest qw/subtest_buffered/; |
| 83 |
\& |
| 84 |
\& subtest_buffered my_test => sub { |
| 85 |
\& ok(1, "subtest event A"); |
| 86 |
\& ok(1, "subtest event B"); |
| 87 |
\& }; |
| 88 |
.Ve |
| 89 |
.PP |
| 90 |
This will produce output like this: |
| 91 |
.PP |
| 92 |
.Vb 5 |
| 93 |
\& ok 1 \- my_test { |
| 94 |
\& ok 1 \- subtest event A |
| 95 |
\& ok 2 \- subtest event B |
| 96 |
\& 1..2 |
| 97 |
\& } |
| 98 |
.Ve |
| 99 |
.SS STREAMED |
| 100 |
.IX Subsection "STREAMED" |
| 101 |
The default option is 'buffered'. If you want streamed subtests, |
| 102 |
the way Test::Builder does it, use this: |
| 103 |
.PP |
| 104 |
.Vb 1 |
| 105 |
\& use Test2::Tools::Subtest qw/subtest_streamed/; |
| 106 |
\& |
| 107 |
\& subtest_streamed my_test => sub { |
| 108 |
\& ok(1, "subtest event A"); |
| 109 |
\& ok(1, "subtest event B"); |
| 110 |
\& }; |
| 111 |
.Ve |
| 112 |
.PP |
| 113 |
This will produce output like this: |
| 114 |
.PP |
| 115 |
.Vb 5 |
| 116 |
\& # Subtest: my_test |
| 117 |
\& ok 1 \- subtest event A |
| 118 |
\& ok 2 \- subtest event B |
| 119 |
\& 1..2 |
| 120 |
\& ok 1 \- Subtest: my_test |
| 121 |
.Ve |
| 122 |
.SH "IMPORTANT NOTE" |
| 123 |
.IX Header "IMPORTANT NOTE" |
| 124 |
You can use \f(CW\*(C`bail_out\*(C'\fR or \f(CW\*(C`skip_all\*(C'\fR in a subtest, but not in a BEGIN block |
| 125 |
or \f(CW\*(C`use\*(C'\fR statement. This is due to the way flow control works within a BEGIN |
| 126 |
block. This is not normally an issue, but can happen in rare conditions using |
| 127 |
eval, or script files as subtests. |
| 128 |
.SH EXPORTS |
| 129 |
.IX Header "EXPORTS" |
| 130 |
.ie n .IP "subtest_streamed $name => $sub" 4 |
| 131 |
.el .IP "subtest_streamed \f(CW$name\fR => \f(CW$sub\fR" 4 |
| 132 |
.IX Item "subtest_streamed $name => $sub" |
| 133 |
.PD 0 |
| 134 |
.ie n .IP "subtest_streamed($name, $sub, @args)" 4 |
| 135 |
.el .IP "subtest_streamed($name, \f(CW$sub\fR, \f(CW@args\fR)" 4 |
| 136 |
.IX Item "subtest_streamed($name, $sub, @args)" |
| 137 |
.ie n .IP "subtest_streamed $name => \e%params, $sub" 4 |
| 138 |
.el .IP "subtest_streamed \f(CW$name\fR => \e%params, \f(CW$sub\fR" 4 |
| 139 |
.IX Item "subtest_streamed $name => %params, $sub" |
| 140 |
.ie n .IP "subtest_streamed($name, \e%params, $sub, @args)" 4 |
| 141 |
.el .IP "subtest_streamed($name, \e%params, \f(CW$sub\fR, \f(CW@args\fR)" 4 |
| 142 |
.IX Item "subtest_streamed($name, %params, $sub, @args)" |
| 143 |
.PD |
| 144 |
Run subtest coderef, stream events as they happen. |
| 145 |
.Sp |
| 146 |
\&\f(CW\*(C`\e%params\*(C'\fR is a hashref with any arguments you wish to pass into hub |
| 147 |
construction. |
| 148 |
.ie n .IP "subtest_buffered $name => $sub" 4 |
| 149 |
.el .IP "subtest_buffered \f(CW$name\fR => \f(CW$sub\fR" 4 |
| 150 |
.IX Item "subtest_buffered $name => $sub" |
| 151 |
.PD 0 |
| 152 |
.ie n .IP "subtest_buffered($name, $sub, @args)" 4 |
| 153 |
.el .IP "subtest_buffered($name, \f(CW$sub\fR, \f(CW@args\fR)" 4 |
| 154 |
.IX Item "subtest_buffered($name, $sub, @args)" |
| 155 |
.ie n .IP "subtest_buffered $name => \e%params, $sub" 4 |
| 156 |
.el .IP "subtest_buffered \f(CW$name\fR => \e%params, \f(CW$sub\fR" 4 |
| 157 |
.IX Item "subtest_buffered $name => %params, $sub" |
| 158 |
.ie n .IP "subtest_buffered($name, \e%params, $sub, @args)" 4 |
| 159 |
.el .IP "subtest_buffered($name, \e%params, \f(CW$sub\fR, \f(CW@args\fR)" 4 |
| 160 |
.IX Item "subtest_buffered($name, %params, $sub, @args)" |
| 161 |
.PD |
| 162 |
Run subtest coderef, render events all at once when subtest is complete. |
| 163 |
.Sp |
| 164 |
\&\f(CW\*(C`\e%params\*(C'\fR is a hashref with any arguments you wish to pass into hub |
| 165 |
construction. |
| 166 |
.SH SOURCE |
| 167 |
.IX Header "SOURCE" |
| 168 |
The source code repository for Test2\-Suite can be found at |
| 169 |
\&\fIhttps://github.com/Test\-More/Test2\-Suite/\fR. |
| 170 |
.SH MAINTAINERS |
| 171 |
.IX Header "MAINTAINERS" |
| 172 |
.IP "Chad Granum <[email protected]>" 4 |
| 173 |
.IX Item "Chad Granum <[email protected]>" |
| 174 |
.SH AUTHORS |
| 175 |
.IX Header "AUTHORS" |
| 176 |
.PD 0 |
| 177 |
.IP "Chad Granum <[email protected]>" 4 |
| 178 |
.IX Item "Chad Granum <[email protected]>" |
| 179 |
.PD |
| 180 |
.SH COPYRIGHT |
| 181 |
.IX Header "COPYRIGHT" |
| 182 |
Copyright 2018 Chad Granum <[email protected]>. |
| 183 |
.PP |
| 184 |
This program is free software; you can redistribute it and/or |
| 185 |
modify it under the same terms as Perl itself. |
| 186 |
.PP |
| 187 |
See \fIhttp://dev.perl.org/licenses/\fR |