66import subprocess
77import sys
88import pytest
9- from testutils import cppcheck , assert_cppcheck
9+ from testutils import cppcheck
1010
1111try :
1212 # TODO: handle exitcode?
2020 pytest .skip (allow_module_level = True )
2121
2222
23+ __DEPRECATION_MSG = 'information: clang import is deprecated, it will be removed in 2.27 [clangimport]'
24+
25+
26+ # #15221 - clang import is deprecated; check the message and return the remaining stderr lines
27+ def __check_deprecation (stderr , filename ):
28+ lines = stderr .splitlines ()
29+ assert len (lines ) >= 3 , lines
30+ assert lines [0 ] == '{}:1:1: {}' .format (filename , __DEPRECATION_MSG ), lines
31+ # the message is followed by the code snippet and the caret
32+ assert lines [2 ] == '^' , lines
33+ return lines [3 :]
34+
35+
2336def __get_debug_section (title , stdout ):
2437 s = re .sub (r'0x[0-9a-fA-F]+' , '0x12345678' , stdout )
2538 s = re .sub (r'nestedIn: Struct' , 'nestedIn: Class' , s )
@@ -125,7 +138,10 @@ def test_log(tmpdir):
125138 'Checking {} ...' .format (test_file ).replace ('\\ ' , '/' ),
126139 ]
127140
128- assert_cppcheck (args , ec_exp = 0 , err_exp = [], out_exp = out_lines )
141+ exitcode , stdout , stderr = cppcheck (args )
142+ assert exitcode == 0 , stdout
143+ assert stdout .splitlines () == out_lines
144+ assert __check_deprecation (stderr , test_file ) == []
129145
130146
131147def test_include (tmp_path ):
@@ -151,7 +167,7 @@ def test_warning(tmpdir): # #12424
151167 exitcode , stdout , stderr = cppcheck (['-q' , '--enable=warning' , '--clang' , test_file ])
152168 assert exitcode == 0 , stderr # do not assert
153169 assert stdout == ''
154- assert stderr == ''
170+ assert __check_deprecation ( stderr , test_file ) == []
155171
156172
157173def __test_cmd (tmp_path , file_name , extra_args , stdout_exp_1 , content = '' ):
@@ -173,7 +189,7 @@ def __test_cmd(tmp_path, file_name, extra_args, stdout_exp_1, content=''):
173189
174190 exitcode , stdout , stderr = cppcheck (args , cwd = tmp_path )
175191 assert exitcode == 0 , stderr if not stdout else stdout
176- assert stderr == ''
192+ assert __check_deprecation ( stderr , file_name ) == []
177193 assert stdout .splitlines () == [
178194 'Checking {} ...' .format (file_name ),
179195 'clang -fsyntax-only -Xclang -ast-dump -fno-color-diagnostics {}{}' .format (stdout_exp_1 , file_name )
@@ -279,7 +295,7 @@ def test_debug_clang_output(tmp_path):
279295
280296 exitcode , stdout , stderr = cppcheck (args )
281297 assert exitcode == 0 , stderr if not stdout else stdout
282- assert stderr == ''
298+ assert __check_deprecation ( stderr , test_file ) == []
283299 assert stdout .startswith ('TranslationUnitDecl' ), stdout
284300 assert stdout .find (str (test_file )) != - 1 , stdout
285301
@@ -312,7 +328,7 @@ def test_debug_clang_output_failure_exitcode(tmp_path):
312328
313329 exitcode , stdout , stderr = cppcheck (args )
314330 assert exitcode == 0 , stderr if not stdout else stdout
315- stderr_lines = stderr . splitlines ( )
331+ stderr_lines = __check_deprecation ( stderr , test_file )
316332 assert len (stderr_lines ) > 5 , stderr_lines
317333 assert (stderr_lines [0 ] ==
318334 "Failed to execute 'clang -fsyntax-only -Xclang -ast-dump -fno-color-diagnostics -x c {} 2>&1' - (exitcode: 1 / output: {}:3:12: error: indirection requires pointer operand ('int' invalid)" .format (test_file , test_file ))
0 commit comments