1Test2::Manual::Tooling:U:sPelrugCionn:t:rTiTebesustttie2nd:g:DPMoeanrnelu(a3Dl)o:c:uTmoeonltiantgi:o:nPlugin::TestingDone(3)
2
3
4

NAME

6       Test2::Manual::Tooling::Plugin::TestingDone - Run code when the test
7       file is finished, or when done_testing is called.
8

DESCRIPTION

10       This is a way to add behavior to the end of a test file. This code is
11       run either when done_testing() is called, or when the test file has no
12       more run-time code to run.
13
14       When triggered by done_testing() this will be run BEFORE the plan is
15       calculated and sent. This means it IS safe to make test assertions in
16       this callback.
17

COMPLETE CODE UP FRONT

19           package Test2::Plugin::MyPlugin;
20
21           use Test2::API qw{test2_add_callback_testing_done};
22
23           sub import {
24               my $class = shift;
25
26               test2_add_callback_testing_done(sub {
27                   ok(!$some_global, '$some_global was not set');
28                   print "The test file is done, or done_testing was just called\n"
29               });
30           }
31
32           1;
33

LINE BY LINE

35       use Test2::API qw{test2_add_callback_testing_done};
36           This imports the test2_add_callback_testing_done() callback.
37
38       test2_add_callback_testing_done(sub { ... });
39           This adds our callback to be called when testing is done.
40
41       ok(!$some_global, '$some_global was not set')
42           It is safe to make assertions in this type of callback. This code
43           simply asserts that some global was never set over the course of
44           the test.
45
46       print "The test file is done, or done_testing was just called\n"
47           This prints a message when the callback is run.
48

UNDER THE HOOD

50       Before test2_add_callback_testing_done() this kind of thing was still
51       possible, but it was hard to get right, here is the code to do it:
52
53           test2_add_callback_post_load(sub {
54               my $stack = test2_stack();
55
56               # Insure we have at least one hub, but we do not necessarily want the
57               # one this returns.
58               $stack->top;
59
60               # We want the root hub, not the top one.
61               my ($root) = Test2::API::test2_stack->all;
62
63               # Make sure the hub does not believe nothing has happened.
64               $root->set_active(1);
65
66               # Now we can add our follow-up code
67               $root->follow_up(sub {
68                   # Your callback code here
69               });
70           });
71

SEE ALSO

73       Test2::Manual - Primary index of the manual.
74

SOURCE

76       The source code repository for Test2-Manual can be found at
77       https://github.com/Test-More/Test2-Suite/.
78

MAINTAINERS

80       Chad Granum <exodist@cpan.org>
81

AUTHORS

83       Chad Granum <exodist@cpan.org>
84
86       Copyright 2018 Chad Granum <exodist@cpan.org>.
87
88       This program is free software; you can redistribute it and/or modify it
89       under the same terms as Perl itself.
90
91       See http://dev.perl.org/licenses/
92
93
94
95perl v5.36.0                    Te2s0t223:-:0M3a-n2u3al::Tooling::Plugin::TestingDone(3)
Impressum