Debian Codegraph @

upstream/mageia-cauldron/man3pm/Test2::Tools.3pm

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