blib/lib/Test2/Tools/AfterSubtest.pm

filter: Statementstmt 100% 18 / 18 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 1 totaltotal 96.4% 27 / 28 CC 2 SCAR 2.2
CC
2
Cov
100%
__ANON__
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
↑ Summary
1 package Test2::Tools::AfterSubtest;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Test2::API qw/context_do/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 our @EXPORT = qw/after_subtest/;
8  
9 1 ▶sub after_subtest {
Subroutine after_subtest: called CC=1 SCAR=0.0
Pod undocumented
10 1 ▶ context_do {
Subroutine __ANON__: called CC=1 SCAR=0.0
11 1 my ($ctx, $cb) = @_;
12 8 ▶ $ctx->hub->listen(sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
13 8 ▶ $cb->() if ref($_[1]) eq 'Test2::Event::Subtest';
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[1] eq "Test2::Event::Subtest" 1 7 8
14 1 }, inherit => 1);
15 1 } @_;
16 }
17  
18 =pod
19  
20 =encoding UTF-8
21  
22 =head1 NAME
23  
24 Test2::Tools::AfterSubtest - Test2 after_subtest callback
25  
26 =head1 DESCRIPTION
27  
28 Exports an C<after_subtest> function that can be passed a callback to be
29 executed after every subtest.
30  
31 Useful for things like cleaning up the database after each test.
32  
33 =head1 SYNOPSIS
34  
35 use Test2::Bundle::More;
36 use Test2::Tools::AfterSubtest;
37 after_subtest(sub {
38 diag 'Subtest has finished;
39 });
40 subtest 'test' => sub {
41 ok('subtest runs');
42 };
43  
44 =cut
45  
46 2 1;
↑ Summary