@@ -1722,16 +1722,7 @@ sub list()
1722
1722
my $readSourceFile = ReadCurrentSource-> new();
1723
1723
my $data =
1724
1724
TraceFile-> load($list , $readSourceFile , $lcovutil::verify_checksum );
1725
- my $total_found = 0;
1726
- my $total_hit = 0;
1727
- my $fn_total_found = 0;
1728
- my $fn_total_hit = 0;
1729
- my $br_total_found = 0;
1730
- my $br_total_hit = 0;
1731
- my $total_mcdc = 0;
1732
- my $total_mcdc_hit = 0;
1733
- my $strlen = length (" Filename" );
1734
- my @footer ;
1725
+ my $strlen = length (" Filename" );
1735
1726
my $lastpath ;
1736
1727
my $F_LN_NUM = 0;
1737
1728
my $F_LN_RATE = 1;
@@ -1812,24 +1803,36 @@ sub list()
1812
1803
my $heading2 = sprintf (" %-*s|" , $w , " Filename" );
1813
1804
my $barlen = $w + 1;
1814
1805
1815
- foreach my $d ([' Lines' , $F_LN_NUM , $F_LN_RATE ],
1816
- [' Functions' , $F_FN_NUM , $F_FN_RATE ],
1817
- [' Branches' , $F_BR_NUM , $F_BR_RATE ],
1818
- [' MC/DC' , $F_MCDC_NUM , $F_MCDC_RATE ],
1819
- ) {
1820
- my ($type , $n , $r ) = @$d ;
1806
+ # name, total_found, total_hit, total_column_width, rate_column_width
1807
+ my @types = ([' Lines' , \&TraceInfo::sum, 0, 0, $F_LN_NUM , $F_LN_RATE ],
1808
+ [$lcovutil::func_coverage ? ' Functions' : undef ,
1809
+ \&TraceInfo::func, 0, 0, $F_FN_NUM , $F_FN_RATE
1810
+ ],
1811
+ [$lcovutil::br_coverage ? ' Branches' : undef ,
1812
+ \&TraceInfo::sumbr, 0, 0, $F_BR_NUM , $F_BR_RATE
1813
+ ],
1814
+ [$lcovutil::mcdc_coverage ? ' MC/DC' : undef ,
1815
+ \&TraceInfo::mcdc, 0, 0, $F_MCDC_NUM , $F_MCDC_RATE
1816
+ ],);
1817
+
1818
+ my $sep = ' ' ;
1819
+ foreach my $d (@types ) {
1820
+ my ($type , $cb , $found , $hit , $n , $r ) = @$d ;
1821
+ next unless $type ;
1821
1822
$w = $fwidth [$r ];
1822
- $format .= " %${w} s " ;
1823
- $heading1 .= sprintf (" %-*s | " , $w + $fwidth [$n ], $type );
1824
- $heading2 .= sprintf (" %-*s " , $w , " Rate" );
1823
+ $format .= " $sep %${w} s " ;
1824
+ $heading1 .= sprintf (" $sep %-*s " , $w + $fwidth [$n ], $type );
1825
+ $heading2 .= sprintf (" $sep %-*s " , $w , " Rate" );
1825
1826
$barlen += $w + 1;
1826
1827
# Number of coverpoints
1827
1828
$w = $fwidth [$n ];
1828
- $format .= " %${w} s| " ;
1829
- $heading2 .= sprintf (" %*s| " , $w , " Num" );
1829
+ $format .= " %${w} s" ;
1830
+ $heading2 .= sprintf (" %*s" , $w , " Num" );
1830
1831
$barlen += $w + 1;
1832
+ $sep = ' |' ;
1831
1833
}
1832
- # Line end
1834
+ --$barlen ; # no separator for last column
1835
+ # Line end
1833
1836
$format .= " \n " ;
1834
1837
$heading1 .= " \n " ;
1835
1838
$heading2 .= " \n " ;
@@ -1869,40 +1872,19 @@ sub list()
1869
1872
}
1870
1873
$print_filename = shorten_filename($print_filename , $strlen );
1871
1874
}
1872
- my $lineData = $entry -> sum();
1873
- my $branchData = $entry -> sumbr();
1874
- my $funcData = $entry -> func();
1875
- my $mcdcData = $entry -> mcdc();
1876
- my ($found , $hit , $br_found , $br_hit , $fn_found , $fn_hit , $mcdc_found ,
1877
- $mcdc_hit )
1878
- = ($lineData -> found(), $lineData -> hit(),
1879
- $branchData -> found(), $branchData -> hit(),
1880
- $funcData -> numFunc(), $funcData -> numHit(),
1881
- $mcdcData -> found(), $mcdcData -> hit());
1882
-
1883
- # Add line coverage totals
1884
- $total_found += $found ;
1885
- $total_hit += $hit ;
1886
- # Add function coverage totals
1887
- $fn_total_found += $fn_found ;
1888
- $fn_total_hit += $fn_hit ;
1889
- # Add branch coverage totals
1890
- $br_total_found += $br_found ;
1891
- $br_total_hit += $br_hit ;
1892
- $total_mcdc += $mcdc_found ;
1893
- $total_mcdc_hit += $mcdc_hit ;
1894
-
1895
1875
my @file_data ;
1896
1876
push (@file_data , $print_filename );
1897
- foreach my $d ([$hit , $found , $F_LN_RATE , $F_LN_NUM ],
1898
- [$fn_hit , $fn_found , $F_FN_RATE , $F_FN_NUM ],
1899
- [$br_hit , $br_found , $F_BR_RATE , $F_BR_NUM ],
1900
- [$mcdc_hit , $mcdc_found , $F_MCDC_RATE , $F_MCDC_NUM ],
1901
- ) {
1902
- my ($h , $f , $r , $n ) = @$d ;
1903
-
1904
- push (@file_data , shorten_rate($h , $f , $fwidth [$r ]));
1905
- push (@file_data , shorten_number($f , $fwidth [$n ]));
1877
+ foreach my $d (@types ) {
1878
+ my ($type , $cb , $total_found , $total_hit , $n , $r ) = @$d ;
1879
+ next unless defined ($type );
1880
+ my $data = &{$cb }($entry );
1881
+
1882
+ my ($found , $hit ) = $data -> get_found_and_hit();
1883
+ # add to totals
1884
+ $d -> [2] += $found , $d -> [3] += $hit ;
1885
+
1886
+ push (@file_data , shorten_rate($hit , $found , $fwidth [$r ]));
1887
+ push (@file_data , shorten_number($found , $fwidth [$n ]));
1906
1888
}
1907
1889
# Print assembled line
1908
1890
printf ($format , @file_data );
@@ -1912,19 +1894,15 @@ sub list()
1912
1894
print ((" =" x $barlen ) . " \n " );
1913
1895
1914
1896
# Assemble line parameters
1897
+ my @footer ;
1915
1898
push (@footer , sprintf (" %*s" , $strlen , " Total:" ));
1899
+ foreach my $d (@types ) {
1900
+ my ($type , $cb , $total_found , $total_hit , $n , $r ) = @$d ;
1901
+ next unless defined ($type );
1916
1902
1917
- foreach my $d ([$total_hit , $total_found , $F_LN_RATE , $F_LN_NUM ],
1918
- [$fn_total_hit , $fn_total_found , $F_FN_RATE , $F_FN_NUM ],
1919
- [$br_total_hit , $br_total_found , $F_BR_RATE , $F_BR_NUM ],
1920
- [$total_mcdc_hit , $total_mcdc , $F_MCDC_RATE , $F_MCDC_NUM ],
1921
- ) {
1922
- my ($h , $f , $r , $n ) = @$d ;
1923
-
1924
- push (@footer , shorten_rate($h , $f , $fwidth [$r ]));
1925
- push (@footer , shorten_number($f , $fwidth [$n ]));
1903
+ push (@footer , shorten_rate($total_hit , $total_found , $fwidth [$r ]));
1904
+ push (@footer , shorten_number($total_found , $fwidth [$n ]));
1926
1905
}
1927
-
1928
1906
# Print assembled line
1929
1907
printf ($format , @footer );
1930
1908
}
0 commit comments