| 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 3perl" |
| 58 |
.TH Test2::Tools 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 \- Documentation for Tools. |
| 65 |
.SH DESCRIPTION |
| 66 |
.IX Header "DESCRIPTION" |
| 67 |
Tools are packages that export test functions, typically all related to a |
| 68 |
specific aspect of testing. If you have a couple different categories of |
| 69 |
exports then you may want to break them into separate modules. |
| 70 |
.PP |
| 71 |
Tools should export testing functions. Loading tools \fBshould not\fR have side |
| 72 |
effects, or alter the behavior of other tools. If you want to alter behaviors |
| 73 |
or create side effects then you probably want to write a Test2::Plugin. |
| 74 |
.SH FAQ |
| 75 |
.IX Header "FAQ" |
| 76 |
.IP "Why is it called Test2::Tools, and not Test2::Tool?" 4 |
| 77 |
.IX Item "Why is it called Test2::Tools, and not Test2::Tool?" |
| 78 |
This question arises since Tools is the only namespace in the plural. This is |
| 79 |
because each Plugin should be a distinct unit of functionality, but a Tools |
| 80 |
dist can (and usually should) export several tools. A bundle is also typically |
| 81 |
described as a single unit. Nobody would like Test2::Bundles::Foo. |
| 82 |
.IP "Should my tools subclass Test2::Tools?" 4 |
| 83 |
.IX Item "Should my tools subclass Test2::Tools?" |
| 84 |
No. Currently this class is empty. Eventually we may want to add behavior, in |
| 85 |
which case we do not want anyone to already be subclassing it. |
| 86 |
.SH "HOW DO I WRITE A 'TOOLS' MODULE?" |
| 87 |
.IX Header "HOW DO I WRITE A 'TOOLS' MODULE?" |
| 88 |
It is very easy to write tools: |
| 89 |
.PP |
| 90 |
.Vb 3 |
| 91 |
\& package Test2::Tools::Mine |
| 92 |
\& use strict; |
| 93 |
\& use warnings; |
| 94 |
\& |
| 95 |
\& # All tools should use the context() function. |
| 96 |
\& use Test2::API qw/context/; |
| 97 |
\& |
| 98 |
\& our @EXPORTS = qw/ok plan/; |
| 99 |
\& use base \*(AqExporter\*(Aq; |
| 100 |
\& |
| 101 |
\& sub ok($;$) { |
| 102 |
\& my ($bool, $name) = @_; |
| 103 |
\& |
| 104 |
\& # All tool functions should start by grabbing a context |
| 105 |
\& my $ctx = context(); |
| 106 |
\& |
| 107 |
\& # The context is the primary interface for generating events |
| 108 |
\& $ctx\->ok($bool, $name); |
| 109 |
\& |
| 110 |
\& # When you are done you release the context |
| 111 |
\& $ctx\->release; |
| 112 |
\& |
| 113 |
\& return $bool ? 1 : 0; |
| 114 |
\& } |
| 115 |
\& |
| 116 |
\& sub plan { |
| 117 |
\& my ($max) = @_; |
| 118 |
\& my $ctx = context(); |
| 119 |
\& $ctx\->plan($max); |
| 120 |
\& $ctx\->release; |
| 121 |
\& } |
| 122 |
\& |
| 123 |
\& 1; |
| 124 |
.Ve |
| 125 |
.PP |
| 126 |
See Test2::API::Context for documentation on what the \f(CW$ctx\fR object can do. |
| 127 |
.SH SOURCE |
| 128 |
.IX Header "SOURCE" |
| 129 |
The source code repository for Test2\-Suite can be found at |
| 130 |
\&\fIhttps://github.com/Test\-More/Test2\-Suite/\fR. |
| 131 |
.SH MAINTAINERS |
| 132 |
.IX Header "MAINTAINERS" |
| 133 |
.IP "Chad Granum <[email protected]>" 4 |
| 134 |
.IX Item "Chad Granum <[email protected]>" |
| 135 |
.SH AUTHORS |
| 136 |
.IX Header "AUTHORS" |
| 137 |
.PD 0 |
| 138 |
.IP "Chad Granum <[email protected]>" 4 |
| 139 |
.IX Item "Chad Granum <[email protected]>" |
| 140 |
.PD |
| 141 |
.SH COPYRIGHT |
| 142 |
.IX Header "COPYRIGHT" |
| 143 |
Copyright 2018 Chad Granum <[email protected]>. |
| 144 |
.PP |
| 145 |
This program is free software; you can redistribute it and/or |
| 146 |
modify it under the same terms as Perl itself. |
| 147 |
.PP |
| 148 |
See \fIhttp://dev.perl.org/licenses/\fR |