Debian Codegraph @

upstream/opensuse-tumbleweed/man3/Test2::Manual::Tooling::Plugin::TestingDone.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::Manual::Tooling::Plugin::TestingDone 3pm"
61 .TH Test2::Manual::Tooling::Plugin::TestingDone 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::Manual::Tooling::Plugin::TestingDone \- Run code when the test file is
68 finished, or when done_testing is called.
69 .SH DESCRIPTION
70 .IX Header "DESCRIPTION"
71 This is a way to add behavior to the end of a test file. This code is run
72 either when \fBdone_testing()\fR is called, or when the test file has no more
73 run\-time code to run.
74 .PP
75 When triggered by \fBdone_testing()\fR this will be run BEFORE the plan is calculated
76 and sent. This means it IS safe to make test assertions in this callback.
77 .SH "COMPLETE CODE UP FRONT"
78 .IX Header "COMPLETE CODE UP FRONT"
79 .Vb 1
80 \& package Test2::Plugin::MyPlugin;
81 \&
82 \& use Test2::API qw{test2_add_callback_testing_done};
83 \&
84 \& sub import {
85 \& my $class = shift;
86 \&
87 \& test2_add_callback_testing_done(sub {
88 \& ok(!$some_global, \*(Aq$some_global was not set\*(Aq);
89 \& print "The test file is done, or done_testing was just called\en"
90 \& });
91 \& }
92 \&
93 \& 1;
94 .Ve
95 .SH "LINE BY LINE"
96 .IX Header "LINE BY LINE"
97 .IP "use Test2::API qw{test2_add_callback_testing_done};" 4
98 .IX Item "use Test2::API qw{test2_add_callback_testing_done};"
99 This imports the \f(CWtest2_add_callback_testing_done()\fR callback.
100 .IP "test2_add_callback_testing_done(sub { ... });" 4
101 .IX Item "test2_add_callback_testing_done(sub { ... });"
102 This adds our callback to be called when testing is done.
103 .IP "ok(!$some_global, \*(Aq$some_global was not set\*(Aq)" 4
104 .IX Item "ok(!$some_global, '$some_global was not set')"
105 It is safe to make assertions in this type of callback. This code simply
106 asserts that some global was never set over the course of the test.
107 .IP "print ""The test file is done, or done_testing was just called\en""" 4
108 .IX Item "print ""The test file is done, or done_testing was just calledn"""
109 This prints a message when the callback is run.
110 .SH "UNDER THE HOOD"
111 .IX Header "UNDER THE HOOD"
112 Before \fBtest2_add_callback_testing_done()\fR this kind of thing was still possible,
113 but it was hard to get right, here is the code to do it:
114 .PP
115 .Vb 2
116 \& test2_add_callback_post_load(sub {
117 \& my $stack = test2_stack();
118 \&
119 \& # Insure we have at least one hub, but we do not necessarily want the
120 \& # one this returns.
121 \& $stack\->top;
122 \&
123 \& # We want the root hub, not the top one.
124 \& my ($root) = Test2::API::test2_stack\->all;
125 \&
126 \& # Make sure the hub does not believe nothing has happened.
127 \& $root\->set_active(1);
128 \&
129 \& # Now we can add our follow\-up code
130 \& $root\->follow_up(sub {
131 \& # Your callback code here
132 \& });
133 \& });
134 .Ve
135 .SH "SEE ALSO"
136 .IX Header "SEE ALSO"
137 Test2::Manual \- Primary index of the manual.
138 .SH SOURCE
139 .IX Header "SOURCE"
140 The source code repository for Test2\-Manual can be found at
141 \&\fIhttps://github.com/Test\-More/test\-more/\fR.
142 .SH MAINTAINERS
143 .IX Header "MAINTAINERS"
144 .IP "Chad Granum <[email protected]>" 4
145 .IX Item "Chad Granum <[email protected]>"
146 .SH AUTHORS
147 .IX Header "AUTHORS"
148 .IP "Chad Granum <[email protected]>" 4
149 .IX Item "Chad Granum <[email protected]>"
150 .SH COPYRIGHT
151 .IX Header "COPYRIGHT"
152 Copyright Chad Granum <[email protected]>.
153 .PP
154 This program is free software; you can redistribute it and/or
155 modify it under the same terms as Perl itself.
156 .PP
157 See \fIhttp://dev.perl.org/licenses/\fR