Debian Codegraph @

upstream/opensuse-tumbleweed/man3/Test2::Tools::Grab.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::Grab 3pm"
61 .TH Test2::Tools::Grab 3pm 2026-03-09 "perl v5.42.1" "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::Grab \- Temporarily intercept all events without adding a scope
68 level.
69 .SH DESCRIPTION
70 .IX Header "DESCRIPTION"
71 This package provides a function that returns an object that grabs all events.
72 Once the object is destroyed events will once again be sent to the main hub.
73 .SH SYNOPSIS
74 .IX Header "SYNOPSIS"
75 .Vb 1
76 \& use Test2::Tools::Grab;
77 \&
78 \& my $grab = grab();
79 \&
80 \& # Generate some events, they are intercepted.
81 \& ok(1, "pass");
82 \& ok(0, "fail");
83 \&
84 \& my $events_a = $grab\->flush;
85 \&
86 \& # Generate some more events, they are intercepted.
87 \& ok(1, "pass");
88 \& ok(0, "fail");
89 \&
90 \& my $events_b = $grab\->finish;
91 .Ve
92 .SH EXPORTS
93 .IX Header "EXPORTS"
94 .ie n .IP "$grab = \fBgrab()\fR" 4
95 .el .IP "\f(CW$grab\fR = \fBgrab()\fR" 4
96 .IX Item "$grab = grab()"
97 This lets you intercept all events for a section of code without adding
98 anything to your call stack. This is useful for things that are sensitive to
99 changes in the stack depth.
100 .Sp
101 .Vb 3
102 \& my $grab = grab();
103 \& ok(1, \*(Aqfoo\*(Aq);
104 \& ok(0, \*(Aqbar\*(Aq);
105 \&
106 \& my $events = $grab\->finish;
107 \&
108 \& is(@$events, 2, "grabbed 2 events.");
109 .Ve
110 .Sp
111 If the \f(CW$grab\fR object is destroyed without calling \f(CWfinish()\fR, it will
112 automatically clean up after itself and restore the parent hub.
113 .Sp
114 .Vb 5
115 \& {
116 \& my $grab = grab();
117 \& # Things are grabbed
118 \& }
119 \& # Things are back to normal
120 .Ve
121 .Sp
122 By default the hub used has \f(CW\*(C`no_ending\*(C'\fR set to true. This will prevent the hub
123 from enforcing that you issued a plan and ran at least 1 test. You can turn
124 enforcement back one like this:
125 .Sp
126 .Vb 1
127 \& $grab\->hub\->set_no_ending(0);
128 .Ve
129 .Sp
130 With \f(CW\*(C`no_ending\*(C'\fR turned off, \f(CW\*(C`finish\*(C'\fR will run the post\-test checks to
131 enforce the plan and that tests were run. In many cases this will result in
132 additional events in your events array.
133 .SH "SEE ALSO"
134 .IX Header "SEE ALSO"
135 Test2::Util::Grabber \- The object constructed and returned by this tool.
136 .SH SOURCE
137 .IX Header "SOURCE"
138 The source code repository for Test2 can be found at
139 \&\fIhttps://github.com/Test\-More/test\-more/\fR.
140 .SH MAINTAINERS
141 .IX Header "MAINTAINERS"
142 .IP "Chad Granum <[email protected]>" 4
143 .IX Item "Chad Granum <[email protected]>"
144 .SH AUTHORS
145 .IX Header "AUTHORS"
146 .IP "Chad Granum <[email protected]>" 4
147 .IX Item "Chad Granum <[email protected]>"
148 .SH COPYRIGHT
149 .IX Header "COPYRIGHT"
150 Copyright Chad Granum <[email protected]>.
151 .PP
152 This program is free software; you can redistribute it and/or
153 modify it under the same terms as Perl itself.
154 .PP
155 See \fIhttp://dev.perl.org/licenses/\fR