Skip to content

Commit

Permalink
Update python version
Browse files Browse the repository at this point in the history
  • Loading branch information
anderson- committed Apr 11, 2020
1 parent 705fb20 commit 84342a7
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions tools/coverage.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
import sys
import os
import re
Expand All @@ -7,25 +7,24 @@
if __name__ == '__main__':
"""Show .gcov file statistics."""
multiline_section = True if '-m' in sys.argv else False
cols = ('Name', 'Lines', 'Miss', 'Cover', 'Missing')
ts = [15, 6, 6, 8, 10] # table spaces
t_header = '%%-%ds %%%ds %%%ds %%%ds %%-%ds' % tuple(ts)
t_line = '-' * (sum(ts) + 4)
ts[3] -= 1
t_row = '%%-%ds %%%dd %%%dd %%%d.2f%%%% %%-%ds' % tuple(ts)
header = '{:15} {:>6} {:>6} {:>8} {:>10}'.format('Name', 'Lines', 'Miss',
'Cover', 'Missing')
print()
print(header)
t_line = '-' * len(header)
print(t_line)

total_line_count = 0
total_miss = 0
total_cover = 0
print t_header % cols
print t_line
for file in os.listdir('.'):
if file.endswith('.gcov'):
lines = open(file).readlines();
lines = open(file).readlines()
not_empty = 0
miss = 0
miss_sec = []
for line in lines:
search = re.search('#####:\s*?(\d+)', line)
search = re.search(r'#####:\s*?(\d+)', line)
if search:
miss += 1
line_n = int(search.group(1))
Expand All @@ -38,21 +37,26 @@
line_count = miss + not_empty
file_coverage = (float(not_empty) / (line_count)) * 100
file = file[:-5]
if len(file) > ts[0]:
file = file[:(ts[0] - 3)] + '...'
if len(file) > 15:
file = file[:(15 - 3)] + '...'
n_sections = ''
for sec in miss_sec:
for a, b in miss_sec:
n_sections += f'{a}' if a == b else f'{a}-{b}'
if multiline_section:
n_sections += ('%d\n' % sec[0]) if sec[0] == sec[1] else ('%d-%d\n' % tuple(sec))
n_sections += (sum(ts) - 4) * ' '
n_sections += f'\n{" ":{len(header) - 9}}'
else:
n_sections += ('%d, ' % sec[0]) if sec[0] == sec[1] else ('%d-%d, ' % tuple(sec))
n_sections += ', '
if multiline_section:
n_sections = n_sections[:n_sections.rfind('\n')]
print t_row % (file, line_count, miss, file_coverage, n_sections[:-2])
else:
n_sections = n_sections[:-2]
print(f'{file:15s} {line_count:6d} {miss:6d}',
f'{file_coverage:7.02f}% {n_sections}')
total_line_count += line_count
total_miss += miss
total_cover += file_coverage * line_count
print t_line
total_cover /= total_line_count
print t_row % ('TOTAL', total_line_count, total_miss, total_cover, '')
print(t_line)
print(f'{"TOTAL":15} {total_line_count:6d} {total_miss:6d}',
f'{total_cover:7.2f}%')
print()

0 comments on commit 84342a7

Please sign in to comment.