Merge branch 'typos' into 'main'
[tor.git] / scripts / test / cov-blame
blob601f211952dac2bfd835c7a1edcab6824449e4dd
1 #!/usr/bin/python
3 import os
4 import re
5 import subprocess
6 import sys
8 def handle_file(source_fname, cov_fname):
10 lines_blm = subprocess.Popen(["git", "blame", source_fname], stdout=subprocess.PIPE).stdout.readlines()
11 lines_cov = open(cov_fname).readlines()
13 # XXXX expensive!
14 while re.match(r'\s*-:\s*0:', lines_cov[0]):
15 del lines_cov[0]
17 if len(lines_blm) != len(lines_cov):
18 print >>sys.stderr, "MISMATCH IN NUMBER OF LINES in",source_fname
20 for b,c in zip(lines_blm, lines_cov):
21 m = re.match(r'\s*([^\s:]+):', c)
22 if not m:
23 print >>sys.stderr, "CONFUSING LINE %r"% c
24 cov = 'X'
25 elif m.group(1) == '-':
26 cov = '-'
27 elif m.group(1)[0] == '#':
28 cov = '#'
29 elif m.group(1)[0].isdigit():
30 cov = '1'
31 else:
32 print >>sys.stderr, "CONFUSING LINE %r"% c
33 cov = 'X'
35 print cov, b,
37 COV_DIR = sys.argv[1]
38 SOURCES = sys.argv[2:]
40 for fn in SOURCES:
41 _, base = os.path.split(fn)
42 cfn = os.path.join(COV_DIR, base)
43 cfn += ".gcov"
44 if os.path.exists(cfn):
45 handle_file(fn, cfn)
46 else:
47 print >>sys.stderr, "NO FILE EXISTS CALLED ",cfn