@ -62,6 +62,8 @@ ALL_TESTS = [
' buck ' ,
' buck ' ,
' cc1 ' ,
' cc1 ' ,
' cmake ' ,
' cmake ' ,
' componentkit ' ,
' fail ' ,
' gradle ' ,
' gradle ' ,
' javac ' ,
' javac ' ,
' locale ' ,
' locale ' ,
@ -114,7 +116,7 @@ def save_report(reports, filename):
separators = ( ' , ' , ' : ' ) , sort_keys = True )
separators = ( ' , ' , ' : ' ) , sort_keys = True )
def run_analysis ( clean_cmds , build_cmds , extra_check , env= None ) :
def run_analysis ( clean_cmds , build_cmds , extra_check , should_fail, env= None ) :
for clean_cmd in clean_cmds :
for clean_cmd in clean_cmds :
subprocess . check_call ( clean_cmd , env = env )
subprocess . check_call ( clean_cmd , env = env )
@ -134,7 +136,16 @@ def run_analysis(clean_cmds, build_cmds, extra_check, env=None):
mode = ' w ' ,
mode = ' w ' ,
suffix = ' .out ' ,
suffix = ' .out ' ,
prefix = ' analysis_ ' ) as analysis_output :
prefix = ' analysis_ ' ) as analysis_output :
subprocess . check_call ( infer_cmd , stdout = analysis_output , env = env )
try :
subprocess . check_call ( infer_cmd ,
stdout = analysis_output , env = env )
if should_fail is not None :
# hacky since we should clean up infer-out, etc. as below
# if you made the test fails, this is your punishment
assert False
except subprocess . CalledProcessError , exn :
if exn . returncode != should_fail :
raise
json_path = os . path . join ( temp_out_dir , REPORT_JSON )
json_path = os . path . join ( temp_out_dir , REPORT_JSON )
found_errors = utils . load_json_from_path ( json_path )
found_errors = utils . load_json_from_path ( json_path )
@ -228,6 +239,7 @@ def test(name,
enabled = None ,
enabled = None ,
report_fname = None ,
report_fname = None ,
extra_check = lambda x : None ,
extra_check = lambda x : None ,
should_fail = None ,
preprocess = lambda : None ,
preprocess = lambda : None ,
postprocess = lambda errors : errors ) :
postprocess = lambda errors : errors ) :
""" Run a test.
""" Run a test.
@ -244,6 +256,10 @@ def test(name,
- [ enabled ] whether the test should attempt to run . By default it
- [ enabled ] whether the test should attempt to run . By default it
is enabled if [ [ name ] in [ to_test ] ]
is enabled if [ [ name ] in [ to_test ] ]
- [ report_fname ] where to find the expected Infer results
- [ report_fname ] where to find the expected Infer results
- [ extra_check ] some function that will be given the temporary
results directory as argument
- [ should_fail ] if not None then running infer is expected to fail
with [ should_fail ] error code
- [ preprocess ] a function to run before the clean and compile
- [ preprocess ] a function to run before the clean and compile
commands . If the function returns something non - None , use that as
commands . If the function returns something non - None , use that as
the compile commands .
the compile commands .
@ -251,6 +267,7 @@ def test(name,
modify them . It must return an Infer report .
modify them . It must return an Infer report .
Returns [ True ] if the test ran , [ False ] otherwise .
Returns [ True ] if the test ran , [ False ] otherwise .
"""
"""
# python can't into using values of arguments in the default
# python can't into using values of arguments in the default
# values of other arguments
# values of other arguments
@ -282,6 +299,7 @@ def test(name,
clean_commands ,
clean_commands ,
compile_commands ,
compile_commands ,
extra_check = extra_check ,
extra_check = extra_check ,
should_fail = should_fail ,
env = env )
env = env )
original = os . path . join ( EXPECTED_OUTPUTS_DIR , report_fname )
original = os . path . join ( EXPECTED_OUTPUTS_DIR , report_fname )
do_test ( postprocess ( errors ) , original )
do_test ( postprocess ( errors ) , original )
@ -481,6 +499,13 @@ class BuildIntegrationTest(unittest.TestCase):
' TestIgnoreImports.mm ' ] ,
' TestIgnoreImports.mm ' ] ,
' infer_args ' : [ ' --cxx ' , ' --no-filtering ' ] } ] )
' infer_args ' : [ ' --cxx ' , ' --no-filtering ' ] } ] )
def test_fail_on_issue ( self ) :
test ( ' fail ' , ' --fail-on-issue flag ' ,
CODETOANALYZE_DIR ,
[ { ' compile ' : [ ' clang ' , ' -c ' , ' hello.c ' ] ,
' infer_args ' : [ ' --fail-on-issue ' ] } ] ,
should_fail = 2 )
def test_pmd_xml_output ( self ) :
def test_pmd_xml_output ( self ) :
def pmd_check ( infer_out ) :
def pmd_check ( infer_out ) :
assert os . path . exists ( os . path . join ( infer_out , ' report.xml ' ) )
assert os . path . exists ( os . path . join ( infer_out , ' report.xml ' ) )