tests/iwyu.py: print diff if descrepancy is found

This commit is contained in:
josch
2014-09-20 14:39:24 +02:00
parent e10ed72a48
commit 122db2ed82

View File

@@ -4,18 +4,23 @@ from __future__ import print_function
import json
import subprocess
import shlex
with open("compile_commands.json", "r") as f:
tunits = json.load(f)
result = 0
for tu in tunits:
_,rest = tu["command"].split(" ",1)
_,cmd = tu["command"].split(" ",1)
cmd = "%s %s"%("iwyu", cmd)
cmd = shlex.split(cmd)
# iwyu does not distinguish between different outcomes of its check
# so instead, we grep its stderr output
# see http://code.google.com/p/include-what-you-use/issues/detail?id=157
ret = subprocess.call("%s %s 2>&1 | grep \"has correct #\""%("iwyu", rest), shell=True)
if ret != 0:
ret = subprocess.Popen(cmd, stderr=subprocess.PIPE)
_,ret = ret.communicate()
if "has correct #" not in ret:
result += 1
print(ret)
exit(result)