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 159     159   1629 use strict;
  159         319  
  159         4227  
3 159     159   766 use warnings;
  159         351  
  159         6426  
4              
5             our $VERSION = '0.000153';
6              
7 159     159   2664 use Test2::API qw/test2_add_callback_exit/;
  159         219024  
  159         45704  
8              
9             my $ADDED_HOOK = 0;
10 161 100   161   3496 sub import { test2_add_callback_exit(\&summary) unless $ADDED_HOOK++ }
11              
12 4     4 0 111 sub active { $ADDED_HOOK }
13              
14             sub summary {
15 110     110 0 113371 my ($ctx, $real, $new) = @_;
16              
17             # Avoid double-printing diagnostics if Test::Builder already loaded.
18 110 100       671 return if $INC{'Test/Builder.pm'};
19              
20 109         623 my $hub = $ctx->hub;
21 109         781 my $plan = $hub->plan;
22 109         948 my $count = $hub->count;
23 109         892 my $failed = $hub->failed;
24              
25 109 100 100     2708 $ctx->diag('No tests run!') if !$count && (!$plan || $plan ne 'SKIP');
      100        
26 109 100 100     1544 $ctx->diag('Tests were run but no plan was declared and done_testing() was not seen.')
27             if $count && !$plan;
28              
29 109 100       739 $ctx->diag("Looks like your test exited with $real after test #$count.")
30             if $real;
31              
32 109 100 100     2762 $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__