8 #File 'accidental-engraver.cc'
9 #Lines executed:87.70% of 252
14 str = open (f).read ()
15 m = re.search ("File '([^']+.cc)'\s*Lines executed:([0-9.]+)% of ([0-9]+)", str)
17 if m and '/usr/lib' in m.group (1):
21 cov = float (m.group (2))
22 lines = int (m.group (3))
23 pain = lines * (100.0 - cov)
25 tup = (pain, locals ().copy())
32 print 'files sorted by number of untested lines (decreasing)'
34 print '%5s (%6s): %s' % ('cov %', 'lines', 'file')
35 print '----------------------------------------------'
37 for (pain, d) in results:
38 print '%(cov)5.2f (%(lines)6d): %(file)s' % d
45 in_lines = [l for l in open (f).readlines ()]
46 (count_len, line_num_len) = tuple (map (len, in_lines[0].split( ':')[:2]))
49 c = l[:count_len].strip ()
51 n = int (l[:line_num_len].strip ())
56 l = l[line_num_len+1:]
68 elif c.strip () != '-' or l == '}\n':
75 def is_exception_chunk (ch):
77 for stat in ('warning', 'error'):
82 def print_chunk (ch, lines):
83 nums = [n-1 for (n, l) in ch]
84 for (c, n, l) in lines[min (nums):max (nums)+1]:
85 sys.stdout.write ('%8s:%8d:%s' % (c,n,l))
88 def extract_uncovered (file):
96 cs = [c for c in cs if not is_exception_chunk (c)]
97 print '\n'.join (['%d' % x for (a,x,b) in ls])
99 print 'Uncovered chunk in', file
105 p = optparse.OptionParser (usage="usage coverage.py [options] files",
107 p.add_option ("--summary",
112 p.add_option ("--uncovered",
118 (options, args) = p.parse_args ()
122 summary (['%s.gcov-summary' % s for s in args])
124 if options.uncovered:
126 extract_uncovered ('%s.gcov' % a)
129 if __name__ == '__main__':