You are viewing the version of this documentation from Perl 5.41.10. This is a development version of Perl.

CONTENTS

NAME

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

DESCRIPTION

This is a way to add behavior to the end of a test file. This code is run either when done_testing() is called, or when the test file has no more run-time code to run.

When triggered by done_testing() this will be run BEFORE the plan is calculated and sent. This means it IS safe to make test assertions in this callback.

COMPLETE CODE UP FRONT

package Test2::Plugin::MyPlugin;

use Test2::API qw{test2_add_callback_testing_done};

sub import {
    my $class = shift;

    test2_add_callback_testing_done(sub {
        ok(!$some_global, '$some_global was not set');
        print "The test file is done, or done_testing was just called\n"
    });
}

1;

LINE BY LINE

use Test2::API qw{test2_add_callback_testing_done};

This imports the test2_add_callback_testing_done() callback.