do not crash when pygments crashes

Summary:
When syntax highlighting the source excerpts that Infer prints on stdout, we
would crash if `pygments.lexers` did not find a suitable class given the name
of the source file. Instead, do not colorize when that's the case.

Reviewed By: martinoluca

Differential Revision: D3358115

fbshipit-source-id: ccb9b41
master
Jules Villard 9 years ago committed by Facebook Github Bot 4
parent 7ec8f59998
commit 6bb3b30c36

@ -55,7 +55,11 @@ def syntax_highlighting(source_name, mode, s):
if pygments is None or mode == PLAIN_FORMATTER:
return s
lexer = pygments.lexers.get_lexer_for_filename(source_name)
try:
lexer = pygments.lexers.get_lexer_for_filename(source_name)
except pygments.lexers.ClassNotFound:
return s
formatter = None
if mode == TERMINAL_FORMATTER:
if not sys.stdout.isatty():

@ -63,6 +63,7 @@ ALL_TESTS = [
'javac',
'locale',
'make',
'unknown_ext',
'utf8_in_pwd',
'waf',
]
@ -375,7 +376,7 @@ class BuildIntegrationTest(unittest.TestCase):
return
print('\nRunning utf8_in_pwd integration test')
utf8_in_pwd_path = os.path.join(CODETOANALYZE_DIR, 'utf8_ιn_pwd')
utf8_in_pwd_path = os.path.join(CODETOANALYZE_DIR, u'utf8_\u03B9n_pwd')
# copy non-unicode dir to one with unicode in it
shutil.rmtree(utf8_in_pwd_path, True) # remove just in case
@ -400,6 +401,22 @@ class BuildIntegrationTest(unittest.TestCase):
report_name='utf8_in_pwd_make_report.json')
shutil.rmtree(utf8_in_pwd_path, True) # remove copied dir
def test_unknown_extension(self):
if 'unknown_ext' not in to_test:
print('\nSkipping unknown extension integration test')
return
print('\nRunning unknown extension integration test')
root = CODETOANALYZE_DIR
errors = run_analysis(
root,
[],
[['clang', '-x', 'c', '-c', 'hello.unknown_ext']],
INFER_EXECUTABLE)
original = os.path.join(EXPECTED_OUTPUTS_DIR,
'unknown_ext_report.json')
do_test(errors, original)
if __name__ == '__main__':
# hackish capturing of the arguments after '--'

@ -0,0 +1,7 @@
[
{
"bug_type": "NULL_DEREFERENCE",
"file": "hello.unknown_ext",
"procedure": "test"
}
]
Loading…
Cancel
Save