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
41 def __init__ (self, range, all_lines, file):
43 self.all_lines = all_lines
47 return self.range[1] - self.range[0]
49 return ''.join ([l[0] for l in self.lines()])
52 return self.all_lines[self.range[0]:
55 self.range = (min (self.range[0] -1, 0),
58 print 'uncovered chunk in', self.file
59 for (c, n, l) in self.lines ():
60 sys.stdout.write ('%8s:%8d:%s' % (c,n,l))
65 in_lines = [l for l in open (f).readlines ()]
66 (count_len, line_num_len) = tuple (map (len, in_lines[0].split( ':')[:2]))
69 c = l[:count_len].strip ()
71 n = int (l[:line_num_len].strip ())
76 l = l[line_num_len+1:]
82 def get_chunks (ls, file):
88 elif c.strip () != '-' or l == '}\n':
90 nums = [n-1 for (n, l) in chunk]
91 chunks.append (Chunk ((min (nums), max (nums)+1),
98 def widen_chunk (ch, ls):
102 return [(n, l) for (c, n, l) in ls[a:b]]
105 def is_exception_chunk (ch):
107 for stat in ('warning', 'error'):
112 def is_inspection_chunk (ch):
114 for stat in ('::print',):
119 def extract_uncovered (file):
121 ls = read_gcov (file)
126 cs = get_chunks (ls, file)
129 for stat in ('warning', 'error', 'print'):
135 return [c for c in cs if interesting (c)]
139 p = optparse.OptionParser (usage="usage coverage.py [options] files",
141 p.add_option ("--summary",
146 p.add_option ("--uncovered",
152 (options, args) = p.parse_args ()
156 summary (['%s.gcov-summary' % s for s in args])
158 if options.uncovered:
161 uncovered += extract_uncovered ('%s.gcov' % a)
163 uncovered = [(c.length (), c) for c in uncovered]
166 for (score, c) in uncovered:
171 if __name__ == '__main__':