File Coverage

bin/simple_report
Criterion Covered Total %
statement 71 81 87.6
branch 31 44 70.4
condition 9 14 64.2
subroutine 6 6 100.0
pod n/a
total 117 145 80.6


line stmt bran cond sub pod time code
1             #!/usr/bin/env perl
2 7     7   381 use strict;
  7         13  
  7         1720  
3 7     7   34 use warnings;
  7         10  
  7         573  
4              
5 7     7   10450 use Getopt::Long;
  7         109846  
  7         47  
6 7     7   8613 use TAP::Parser;
  7         526062  
  7         19552  
7              
8 7         24 our $VERSION = "2.00";
9 7         36 $|++;
10              
11             # simple_report NAME
12              
13 7         3504 my($verbose, $status);
14 7         56 GetOptions("verbose+" => \$verbose,
15             "status" => \$status);
16              
17 7   50     1998 my $test_name = shift || "UNNAMED_TEST";
18 7         149 my $parser = TAP::Parser->new( { source => \*STDIN } );
19              
20 7         4264 my %totals = (
21             max => undef,
22             seen => 0,
23              
24             ok => 0,
25             todo => 0,
26             skip => 0,
27             bonus => 0,
28             unplanned => 0,
29              
30             details => {}
31             );
32              
33 7         27 my $current_test_count = 0;
34 7         11 my $unplanned = 0;
35 7         15 my $sharp = "# ";
36 7         14 my $last_item;
37              
38             # Read and analyze input.
39             TAP_LINE:
40 7         51 while( defined(my $item = $parser->next) ) {
41              
42             # If this is a "Bail out!" just quit.
43 147 50       29969 last if $item->is_bailout;
44              
45             # Comments are assumed to "belong" to the last test seen.
46 147 100       5684 if ($item->is_comment) {
47 77 100       470 next TAP_LINE if $item->as_string =~ /\A# Looks like /;
48 70         268 push @{ $totals{details}->{$current_test_count}->{lines} }, $item->as_string;
  70         244  
49 70         465 next TAP_LINE;
50             }
51              
52             # Record the predicted max test number if this is a plan line.
53             # If this is a skip_all, then quit.
54 70 100 66     486 if ($item->is_plan and not defined $totals{plan}) {
55 7 50       85 last TAP_LINE if $item->has_skip;
56             # First test plan seen.
57 7         58 $totals{max} = $item->tests_planned;
58 7         102 next TAP_LINE;
59             }
60              
61             # Should be a test; bump the test count by 1 if so.
62 63 50       425 if ($item->is_test) {
63 63         324 $current_test_count++, $totals{seen}++;
64 63         235 $totals{details}->{$current_test_count}->{item} = $item;
65             }
66              
67 63 100       180 if ($item->is_actual_ok) {
68 49         261 $totals{ok}++;
69             }
70 63 100       201 if ($item->has_todo) {
71 14         64 $totals{todo}++;
72 14 100       46 $totals{ok}++, $totals{bonus}++ if $item->todo_passed;
73             }
74 63 100       421 $totals{skip}++ if $item->has_skip;
75              
76 63 50 33     542 if ($status and not defined $totals{max} ) {
    50          
77 0         0 $unplanned++;
78 0         0 print "$sharp.";
79 0         0 $sharp = '';
80             }
81             elsif ($status) {
82 0         0 printf STDERR "$sharp %2.1d%% complete\n", ($totals{seen}*1.0/$totals{max})*100;
83             }
84             }
85 7 50       1691 print "\n" if $unplanned;
86              
87              
88             # Print summary
89 7         46 print "$test_name: tests=$totals{seen}, ",
90             "ok=$totals{ok}, ",
91 7         546 "failed=@{[$totals{seen}-$totals{ok}]}, ",
92             "skipped=$totals{skip}, ",
93             "todo=$totals{todo}";
94 7 50       105 print $totals{bonus}
95             ? " ($totals{bonus} UNEXPECTEDLY SUCCEEDED)"
96             : "";
97 7 50       53 print $totals{unplanned}
98             ? " ($totals{unplanned} UNPLANNED)"
99             : "";
100 7         60 print "\n";
101              
102 7 50       34 if ($status) {
103 0         0 print STDERR "$sharp $test_name: tests=$totals{seen}, ok=$totals{ok}, failed=@{[$totals{seen}-$totals{ok}]}, skipped=$totals{skip}, todo=$totals{todo}";
  0         0  
104 0 0       0 print STDERR $totals{bonus} ? " ($totals{bonus} UNEXPECTEDLY SUCCEEDED)" : "";
105 0 0       0 print STDERR $totals{unplanned} ? " ($totals{unplanned} UNPLANNED)" : "";
106 0         0 print STDERR "\n";
107            
108             }
109              
110             # Print details if requested
111 7 100       458 if ($verbose) {
112 4         9 for my $test_number (sort keys %{ $totals{details} }) {
  4         35  
113 36         575 my $item = $totals{details}->{$test_number}->{item};
114 36         52 my $lines = $totals{details}->{$test_number}->{lines};
115 36         90 (my $description = $item->description) =~ s/\A-\s+//;
116              
117 36 100 100     221 if ($item->has_todo and $item->todo_passed) {
    100 66        
118 4         128 printf "T %d %s\n",$test_number, $description;
119 4         15 verbose_details($lines);
120             }
121             elsif (not $item->is_ok and not $item->has_todo) {
122 4         264 printf "F %d %s\n", $test_number, $description;
123 4         19 verbose_details($lines);
124             }
125             }
126             }
127              
128             sub verbose_details {
129 8     8   14 my $lines = shift;
130             # Print detailed details (diags) if requested
131 8 100       23 if ($verbose > 1) {
132             # Super-verbose - all diags will be there, including snapshot
133 2         143 print map {"$_\n"} @$lines;
  5         15  
134             }
135             else {
136             # Plain verbose - snapshots only (if any)
137 6         16 snapshot($lines);
138             }
139             }
140              
141             sub snapshot {
142 6     6   10 my($lines) = shift;
143 6         10 print map { "$_\n" } grep { /^(See snapshot.*\z)/sm } @{ $lines };
  0         0  
  15         36  
  6         442  
144              
145             }
146              
147             __END__