Test2::Manual::Tooling::Plugin::TestExit(3) | User Contributed Perl Documentation | Test2::Manual::Tooling::Plugin::TestExit(3) |
Test2::Manual::Tooling::Plugin::TestExit - How to safely add pre-exit behaviors.
This describes the correct/safe way to add pre-exit behaviors to tests via a custom plugin.
The naive way to attempt this would be to add an "END { ... }" block. That can work, and may not cause problems.... On the other hand there are a lot of ways that can bite you. Describing all the potential problems of an END block, and how it might conflict with Test2 (Which has its own END block) is beyond the scope of this document.
package Test2::Plugin::MyPlugin; use Test2::API qw{test2_add_callback_exit}; sub import { my $class = shift; test2_add_callback_exit(sub { my ($ctx, $orig_code, $new_exit_code_ref) = @_; return if $orig_code == 42; $$new_exit_code_ref = 42; }); } 1;
Test2::Manual - Primary index of the manual.
The source code repository for Test2-Manual can be found at https://github.com/Test-More/Test2-Suite/.
Copyright 2018 Chad Granum <exodist@cpan.org>.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://dev.perl.org/licenses/
2020-10-22 | perl v5.34.0 |