Debian Codegraph @

upstream/debian-unstable/man3/Test2::Manual::Tooling::Plugin::TestingDone.3perl

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