[toplevel] add --fail-on-bug option

Summary:
It can be useful in some situations for Infer to exit with an error code in
case it found a bug. A bug is anything Infer reports in infer-out/report.json.
This adds a flag `--fail-on-bug` to the toplevel infer script.

closes #139
master
Jules Villard 9 years ago
parent 2e27c5127b
commit e63269fa14

@ -4,6 +4,7 @@ import argparse
import imp
import utils
import inferlib
import json
import logging
import os
import sys
@ -164,5 +165,16 @@ def main():
analysis.analyze_and_report()
analysis.save_stats()
if args.fail_on_bug:
bugs_filename = os.path.join(args.infer_out,
utils.JSON_REPORT_FILENAME)
try:
with open(bugs_filename) as bugs_file:
bugs = json.load(bugs_file)
if len(bugs) > 0:
sys.exit(inferlib.BUG_FOUND_ERROR_CODE)
except OSError:
pass
if __name__ == '__main__':
main()

@ -21,7 +21,6 @@ import sys
import utils
BASE_INDENT = 2
JSON_REPORT = 'report.json'
# how many lines of context around each report
SOURCE_CONTEXT = 2
@ -249,7 +248,8 @@ class Selector(object):
def main():
args = base_parser.parse_args()
with open(os.path.join(args.infer_out, JSON_REPORT)) as report_file:
report_filename = os.path.join(args.infer_out, utils.JSON_REPORT_FILENAME)
with open(report_filename) as report_file:
reports = json.load(report_file)
sel = Selector(args, reports)

@ -47,6 +47,7 @@ ERROR = 'ERROR'
WARNING = 'WARNING'
INFO = 'INFO'
BUG_FOUND_ERROR_CODE = 2
def get_infer_version():
try:
@ -102,13 +103,20 @@ base_group.add_argument('-nf', '--no-filtering', action='store_true',
help='''Also show the results from the experimental
checks. Warning: some checks may contain many false
alarms''')
base_group.add_argument('--fail-on-bug', action='store_true',
help='''Exit with error code %d if Infer found
something to report'''
% BUG_FOUND_ERROR_CODE)
base_group.add_argument('-l', '--llvm', action='store_true',
help='Analyze C or C++ file using LLVM translation')
help='''[experimental] Analyze C or C++ file using the
experimental LLVM frontend''')
base_group.add_argument('--log_to_stderr', action='store_true',
help='''When set, all logging will go to stderr instead
of log file''')
base_parser.add_argument('-v', '--version', help='Get version of the analyzer',
of the log file''')
base_parser.add_argument('-v', '--version',
help='''Print the version of Infer and exit''',
action=VersionAction)

Loading…
Cancel
Save