bin/simple_report

filter: Statementstmt 95.1% 59 / 62 Branchbran 86.6% 26 / 30 Conditioncond 88.4% 23 / 26 MC/DCmcdc 69.2% 9 / 13 Subroutinesub 100% 8 / 8 Podpod n/a totaltotal 89.9% 125 / 139 CC 15 SCAR 20.3
CC
15
Cov
92%
should_capture
12.1
coded_type
4.3
BEGIN
1.0
CRAP 7.6
« blib/lib/App/SimpleScan/TestSpec.pm ↑ Summary blib/lib/App/SimpleScan.pm »
1 #!/usr/bin/env perl
2 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 11 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 11 our $VERSION = "2.00";
8 11 $|++;
9  
10 11 ▶use TAP::Parser;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 11 my ($verbose, $status);
13 11 GetOptions(
14 "verbose+" => \$verbose,
15 "status" => \$status,
16 );
17  
18 11 ▶my $test_name = shift || "UNNAMED_TEST";
Condition50%1/2
shift @ARGV || 'UNNAMED_TEST'
l!l
011
MC/DC0%0/1
shift @ARGV || 'UNNAMED_TEST'
shift @ARGV
Truth table50%1/2
A
A= shift @ARGV
Aresult
11
00
19  
20 11 my %totals = (
21 details => [],
22 );
23 # Create a new TAP parser
24 11 my $parser = TAP::Parser->new({ source => \*STDIN });
25  
26 # Continuous capture is off to start. We'll turn it on if
27 # --verbose was on and we get a capturable test.
28 11 my $continue_capture = 0;
29  
30 11 ▶while ( my $result = $parser->next ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $result = $parser->next) 155 11 166
31 155 ▶ if (should_capture($result)) {
Branch: 2 branches
BranchTrueFalseTotal
if (should_capture($result)) { } 14 141 155
elsif ($verbose and $continue_capture and $result->is_comment) { } 26 227 253
32 14 push @{ $totals{details} }, [coded_type($result), $result->number, cleanup($result->description)];
33 ▶ } elsif ($verbose and $continue_capture and $result->is_comment ) {
Condition100%6/6
$verbose and $continue_capture and $result->is_comment
!ll&&!rl&&r
112326
$verbose and $continue_capture
!ll&&!rl&&r
575529
MC/DC100%3/3
$verbose and $continue_capture and $result->is_comment
$verbose $continue_capture $result->is_comment
Truth table100%4/4
A and B and C
A= $verboseB= $continue_captureC= $result->is_comment
ABCresult
0XX0
10X0
1100
1111
34 26 ▶ push @{ $totals{details} }, [$result->raw] unless $result->raw =~ /Looks like/;
Branch: 1 branch
BranchTrueFalseTotal
unless $result->raw =~ /Looks like/ 22 4 26
35 }
36 }
37  
38 14 ▶sub cleanup {
Subroutine cleanup: called CC=1 SCAR=0.0
39 14 my($description) = @_;
40 14 $description =~ s/\- //;
41 14 $description;
42 }
43  
44 14 ▶sub coded_type {
Subroutine coded_type: called CC=4 SCAR=14.6
45 14 my($result) = @_;
46 14 ▶ return 'S' if $result->directive eq 'SKIP';
Branch: 1 branch
BranchTrueFalseTotal
if $result->directive eq "SKIP" 0 14 14
47 14 ▶ return 'F' if !$result->is_ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $result->is_ok 7 7 14
48 7 ▶ return 'T' if $result->directive eq 'TODO';
Branch: 1 branch
BranchTrueFalseTotal
if $result->directive eq "TODO" 7 0 7
49 0 return '!'; # Should be a "can't happen".
50 }
51  
52 155 ▶sub should_capture {
Subroutine should_capture: called CC=12 SCAR=24.9
53 155 my($result) = @_;
54  
55 # Don't switch capture status for non-test.
56 155 ▶ return 0 unless $result->is_test;
Branch: 1 branch
BranchTrueFalseTotal
unless $result->is_test 96 59 155
57  
58 # This is a test, so turn off continuous capture.
59 # We my turn it back on.
60 59 $continue_capture = 0;
61  
62 # Skip SKIPs.
63 59 ▶ return 0 if $result->directive && $result->directive eq 'SKIP';
Branch: 1 branch
BranchTrueFalseTotal
if $result->directive and $result->directive eq "SKIP" 7 52 59
Condition100%3/3
$result->directive and $result->directive eq "SKIP"
!ll&&!rl&&r
38147
MC/DC100%2/2
$result->directive and $result->directive eq "SKIP"
$result->directive $result->directive eq "SKIP"
Truth table100%3/3
A and B
A= $result->directiveB= $result->directive eq "SKIP"
ABresult
0X0
100
111
64  
65 # Skip failing TODOs, capture passing TODOs; capture all other actual tests
66 52 ▶ if ( ($result->directive && $result->directive eq 'TODO' && $result->is_actual_ok) ||
Branch: 1 branch
BranchTrueFalseTotal
if ($result->directive and $result->directive eq "TODO" and $result->is_actual_ok or not $result->directive || $result->is_ok) 14 38 52
Condition91%11/12
$result->directive and $result->directive eq "TODO" and $result->is_actual_ok or not $result->directive || $result->is_ok
l!l&&r!l&&!r
7738
$result->directive and $result->directive eq "TODO" and $result->is_actual_ok
!ll&&!rl&&r
3877
$result->directive and $result->directive eq "TODO"
!ll&&!rl&&r
38014
$result->directive || $result->is_ok
l!l&&r!l&&!r
7317
MC/DC80%4/5
$result->directive and $result->directive eq "TODO" and $result->is_actual_ok or not $result->directive || $result->is_ok
$result->directive $result->directive eq "TODO" $result->is_actual_ok $result->directive $result->is_ok
Truth table40%4/10
A and B and C or not(D || E)
A= $result->directiveB= $result->directive eq "TODO"C= $result->is_actual_okD= $result->directiveE= $result->is_ok
ABCDEresult
111XX1
0XX001
10X001
110001
0XX1X0
0XX010
10X1X0
10X010
1101X0
110010
67 (!$result->directive && !$result->is_ok) ){
68 14 ▶ $continue_capture = 1 if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 8 6 14
69 14 return 1;
70 }
71  
72 # Capture all other actual tests
73 38 ▶ return 1 if !$result->directive && !$result->is_ok;
Branch: 1 branch
BranchTrueFalseTotal
if not $result->directive || $result->is_ok 0 38 38
Condition66%2/3
$result->directive || $result->is_ok
l!l&&r!l&&!r
7310
MC/DC0%0/2
$result->directive || $result->is_ok
$result->directive $result->is_ok
Truth table66%2/3
A || B
A= $result->directiveB= $result->is_ok
ABresult
1X1
011
000
74 }
75  
76 # Summarize.
77 11 $totals{ seen } = scalar $parser->tests_run;
78 11 $totals{ ok } = scalar $parser->actual_passed - scalar $parser->todo_passed;
79 11 $totals{ fail } = scalar $parser->failed + scalar $parser->todo_passed;
80 11 $totals{ todo } = scalar $parser->todo;
81 11 $totals{ skip } = scalar $parser->skipped;
82 11 $totals{ bonus } = scalar $parser->todo_passed;
83  
84  
85  
86 # Print summary
87 11 print "$test_name: tests=$totals{seen}, ok=$totals{ok}, failed=@{[$totals{fail}]}, skipped=$totals{skip}, todo=$totals{todo}";
88 11 ▶print " ($totals{bonus} UNEXPECTEDLY SUCCEEDED)" if $totals{bonus};
Branch: 1 branch
BranchTrueFalseTotal
if $totals{"bonus"} 7 4 11
89 11 print "\n";
90  
91 11 ▶if ($status) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status) 0 11 11
92 0 print STDERR "# $test_name: tests=$totals{seen}, ok=$totals{ok}, failed=@{[$totals{seen} - $totals{ok}]}, skipped=$totals{skip}, todo=$totals{todo}, unexpected_success=$totals{bonus}\n";
93 }
94  
95 # Print detailed diagnostics if verbose
96 11 ▶if ($verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose) 4 7 11
97 4 foreach my $test (@{$totals{details}}) {
98 30 print "@$test\n";
99 }
100 }
101  
102 =pod
103  
104 # Print summary
105 print "$test_name: tests=$totals{seen}, ok=$totals{ok}, failed=@{[$totals{seen}-$totals{ok}]}, skipped=$totals{skip}, todo=$totals{todo}";
106 print (($totals{bonus} ? " ($totals{bonus} UNEXPECTEDLY SUCCEEDED)" : ""), "\n");
107 if ($status) {
108 print STDERR "$sharp $test_name: tests=$totals{seen}, ok=$totals{ok}, failed=@{[$totals{seen}-$totals{ok}]}, skipped=$totals{skip}, todo=$totals{todo}";
109 print STDERR (($totals{bonus} ? " ($totals{bonus} UNEXPECTEDLY SUCCEEDED)" : ""),"\n");
110 }
111  
112 # Print details if requested
113 if ($verbose) {
114 my $test_num = 0;
115 for my $test_detail (@{$totals{details}}) {
116 $test_num++;
117  
118 if ($test_detail->{type} eq 'todo') {
119 if ($test_detail->{actual_ok}) {
120 print "T $test_num $test_detail->{name}\n";
121 snapshot($test_detail);
122 }
123 }
124 next if $test_detail->{'ok'};
125 print "F $test_num $test_detail->{name}\n";
126  
127 # Print detailed details (diags) if requested
128 if ($verbose > 1) {
129 # All diags will be there, including snapshot
130 my $diags = "# ".$test_detail->{diagnostics};
131 chomp $diags;
132 $diags =~ s/\n/\n# /g;
133 print "$diags\n";
134 }
135 else {
136 # Verbose report - snapshots only (if any)
137 snapshot($test_detail);
138 }
139 }
140 }
141  
142 sub snapshot {
143 my ($test_detail) = shift;
144 return if !$test_detail->{diagnostics};
145  
146 my($snapshot) = ($test_detail->{diagnostics} =~ /^(See snapshot.*\z)/sm);
147 print ("# ",$snapshot) if $snapshot;
148 }
149  
150 =cut
151  
152  
153 __END__
« blib/lib/App/SimpleScan/TestSpec.pm ↑ Summary blib/lib/App/SimpleScan.pm »