@@ -90,6 +90,37 @@ def test_preprocessor_error(tmpdir):
9090 assert exitcode != 0
9191
9292
93+ # without -D the header is loaded by Preprocessor::loadAllIncludes(), with -D by Preprocessor::preprocess()
94+ @pytest .mark .parametrize ("extra_args" , [[], ['-DA' ]])
95+ def test_simplecpp_portability_header (tmpdir , extra_args ):
96+ test_file = os .path .join (tmpdir , 'test.c' )
97+ with open (test_file , 'wt' ) as f :
98+ f .write ('#include "test.h"\n ' )
99+ test_h = os .path .join (tmpdir , 'test.h' )
100+ with open (test_h , 'wt' ) as f :
101+ f .write ('#ifdef A\n int a;\n #endif\n int x;' ) # no newline at end of file
102+
103+ args = ['-q' , '--enable=portability' , '--template=simple' ] + extra_args + [test_file ]
104+
105+ _ , _ , stderr = cppcheck (args )
106+ assert stderr == '{}:4:7: portability: No newline at end of file is undefined behavior in C. [simplecppPortabilityNoEofNewline]\n ' .format (test_h )
107+
108+
109+ @pytest .mark .parametrize ("extra_args" , [[], ['-DA' ]])
110+ def test_simplecpp_portability_header_inline_suppr (tmpdir , extra_args ):
111+ test_file = os .path .join (tmpdir , 'test.c' )
112+ with open (test_file , 'wt' ) as f :
113+ f .write ('#include "test.h"\n ' )
114+ test_h = os .path .join (tmpdir , 'test.h' )
115+ with open (test_h , 'wt' ) as f :
116+ f .write ('#ifdef A\n int a;\n #endif\n // cppcheck-suppress simplecppPortabilityNoEofNewline\n int x;' )
117+
118+ args = ['-q' , '--enable=portability' , '--inline-suppr' , '--template=simple' ] + extra_args + [test_file ]
119+
120+ _ , _ , stderr = cppcheck (args )
121+ assert stderr == ''
122+
123+
93124__ANSI_BOLD = "\x1b [1m"
94125__ANSI_FG_RED = "\x1b [31m"
95126__ANSI_FG_DEFAULT = "\x1b [39m"
0 commit comments