@@ -206,6 +206,26 @@ def test_ctu_unused_declaration(checker, tmp_path, summary, rule, used_first):
206206 assert 'a.c-1-13-%d' % rule in checker .existing_violations
207207 assert 'b.c-1-13-%d' % rule not in checker .existing_violations
208208
209+ @pytest .mark .parametrize ('summary,rule_unique,rule_unused' , [
210+ ('MisraTypedefInfo' , 506 , 203 ),
211+ ('MisraTagName' , 507 , 204 )
212+ ])
213+ def test_ctu_declaration_location (checker , tmp_path , summary , rule_unique , rule_unused ):
214+ # The same name declared at a.h:1 and b.h:1 (both included by two files) and at b.h:2
215+ ctu_info = tmp_path / 'test.ctu-info'
216+ with open (ctu_info , 'wt' ) as f :
217+ for declaration in [{'name' : 'X' , 'file' : 'a.h' , 'line' : 1 , 'column' : 13 , 'used' : False },
218+ {'name' : 'X' , 'file' : 'a.h' , 'line' : 1 , 'column' : 13 , 'used' : True },
219+ {'name' : 'X' , 'file' : 'b.h' , 'line' : 1 , 'column' : 13 , 'used' : True },
220+ {'name' : 'X' , 'file' : 'b.h' , 'line' : 1 , 'column' : 13 , 'used' : False },
221+ {'name' : 'X' , 'file' : 'b.h' , 'line' : 2 , 'column' : 13 , 'used' : False }]:
222+ f .write (json .dumps ({'summary' : summary , 'data' : [declaration ]}) + '\n ' )
223+ checker .analyse_ctu_info ([str (ctu_info )])
224+ assert checker .existing_violations == {'a.h-1-13-%d' % rule_unique ,
225+ 'b.h-1-13-%d' % rule_unique ,
226+ 'b.h-2-13-%d' % rule_unique ,
227+ 'b.h-2-13-%d' % rule_unused }
228+
209229def test_platform (checker ):
210230 test_file = os .path .join ('addons' ,'test' ,'misra' ,'misra-test.c' )
211231 dump_create (test_file , "--language=c++" )
0 commit comments