File Coverage

blib/lib/Test2/Plugin/ExitSummary.pm
Criterion Covered Total %
statement 21 21 100.0
branch 12 12 100.0
condition 17 18 94.4
subroutine 6 6 100.0
pod 0 2 0.0
total 56 59 94.9


line stmt bran cond sub pod time code
1             package Test2::Plugin::ExitSummary;
2 160     160   1722 use strict;
  160         334  
  160         4859  
3 160     160   854 use warnings;
  160         340  
  160         6356  
4              
5             our $VERSION = '0.000156';
6              
7 160     160   2847 use Test2::API qw/test2_add_callback_exit/;
  160         230036  
  160         50315  
8              
9             my $ADDED_HOOK = 0;
10 162 100   162   3598 sub import { test2_add_callback_exit(\&summary) unless $ADDED_HOOK++ }
11              
12 4     4 0 97 sub active { $ADDED_HOOK }
13              
14             sub summary {
15 111     111 0 120779 my ($ctx, $real, $new) = @_;
16              
17             # Avoid double-printing diagnostics if Test::Builder already loaded.
18 111 100       775 return if $INC{'Test/Builder.pm'};
19              
20 110         677 my $hub = $ctx->hub;
21 110         844 my $plan = $hub->plan;
22 110         1369 my $count = $hub->count;
23 110         928 my $failed = $hub->failed;
24              
25 110 100 100     1070 $ctx->diag('No tests run!') if !$count && (!$plan || $plan ne 'SKIP');
      100        
26 110 100 100     1573 $ctx->diag('Tests were run but no plan was declared and done_testing() was not seen.')
27             if $count && !$plan;
28              
29 110 100       1040 $ctx->diag("Looks like your test exited with $real after test #$count.")
30             if $real;
31              
32 110 100 100     2951 $ctx->diag("Did not follow plan: expected $plan, ran $count.")
      66        
      100        
33             if $plan && $plan =~ m/^[0-9]+$/ && defined $count && $count != $plan;
34             }
35              
36             1;
37              
38             __END__