@@ -308,25 +308,83 @@ def test_addon_naming(tmpdir):
308308 assert stderr == '{}:2:1: style: Variable Var violates naming convention [naming-varname]\n ' .format (test_file )
309309
310310
311- # the namingng addon only works standalone and not in CLI mode - see #12005
312- @pytest .mark .skip
313311def test_addon_namingng (tmpdir ):
314- test_file = os .path .join (tmpdir , 'test.cpp' )
315- # TODO: trigger warning
312+ addon_file = os .path .join (tmpdir , 'namingng.json' )
313+ addon_config_file = os .path .join (tmpdir , 'namingng.config.json' )
314+ with open (addon_file , 'wt' ) as f :
315+ f .write ("""
316+ {
317+ "script": "addons/namingng.py",
318+ "args": [
319+ "--configfile=%s"
320+ ]
321+ }
322+ """ % (addon_config_file ).replace ('\\ ' ,'\\ \\ ' ))
323+
324+ with open (addon_config_file , 'wt' ) as f :
325+ f .write ("""
326+ {
327+ "RE_FILE": [
328+ "[^/]*[a-z][a-z0-9_]*[a-z0-9]\\ .c\\ Z"
329+ ],
330+ "RE_VARNAME": ["[a-z]*[a-z0-9_]*[a-z0-9]\\ Z"],
331+ "RE_FUNCTIONNAME": ["[a-z][a-z0-9_]*[a-z0-9]\\ Z"],
332+ "var_prefixes": {"uint32_t": "ui32"},
333+ "function_prefixes": {"uint16_t": "ui16",
334+ "uint32_t": "ui32"},
335+ "skip_one_char_variables": false
336+ }
337+ """ .replace ('\\ ' ,'\\ \\ ' ))
338+
339+ test_file_basename = 'test_.c'
340+ test_file = os .path .join (tmpdir , test_file_basename )
316341 with open (test_file , 'wt' ) as f :
317342 f .write ("""
318- typedef int MISRA_5_6_VIOLATION;
343+ void InvalidFunction();
344+ void invalid_function_();
345+ void _invalid_function();
346+ void valid_function1();
347+ void valid_function2(int _invalid_arg);
348+ void valid_function3(int invalid_arg_);
349+ void valid_function4(int valid_arg32);
350+ void valid_function5(uint32_t invalid_arg32);
351+ void valid_function6(uint32_t ui32_valid_arg);
352+ uint16_t invalid_function7(int valid_arg);
353+ uint16_t ui16_valid_function8(int valid_arg);
319354 """ )
320355
321- args = ['--addon=namingng ' , '--enable=all' , test_file ]
356+ args = ['--addon=' + addon_file , '--verbose ' , '--enable=all' , test_file ]
322357
323358 exitcode , stdout , stderr = cppcheck (args )
324359 assert exitcode == 0
325360 lines = stdout .splitlines ()
326361 assert lines == [
327- 'Checking {} ...' .format (test_file )
362+ 'Checking {} ...' .format (test_file ),
363+ 'Defines:' ,
364+ 'Undefines:' ,
365+ 'Includes:' ,
366+ 'Platform:native'
328367 ]
329- assert stderr == ''
368+ lines = [line for line in stderr .splitlines () if line .strip () != '^' and line != '' ]
369+ expect = [
370+ '{}:0:0: style: File name {} violates naming convention [namingng-namingConvention]' .format (test_file ,test_file_basename ),
371+ '{}:7:0: style: Variable invalid_arg_ violates naming convention [namingng-namingConvention]' .format (test_file ),
372+ 'void valid_function3(int invalid_arg_);' ,
373+ '{}:9:22: style: Variable invalid_arg32 violates naming convention [namingng-namingConvention]' .format (test_file ),
374+ 'void valid_function5(uint32_t invalid_arg32);' ,
375+ '{}:2:0: style: Function InvalidFunction violates naming convention [namingng-namingConvention]' .format (test_file ),
376+ 'void InvalidFunction();' ,
377+ '{}:3:0: style: Function invalid_function_ violates naming convention [namingng-namingConvention]' .format (test_file ),
378+ 'void invalid_function_();' ,
379+ '{}:4:0: style: Function _invalid_function violates naming convention [namingng-namingConvention]' .format (test_file ),
380+ 'void _invalid_function();' ,
381+ '{}:11:10: style: Function invalid_function7 violates naming convention [namingng-namingConvention]' .format (test_file ),
382+ 'uint16_t invalid_function7(int valid_arg);' ,
383+ ]
384+ # test sorted lines; the order of messages may vary and is not of importance
385+ lines .sort ()
386+ expect .sort ()
387+ assert lines == expect
330388
331389
332390def test_addon_findcasts (tmpdir ):
0 commit comments