44import os
55import re
66import subprocess
7+ import pytest
78from testutils import cppcheck
89
10+ try :
11+ subprocess .call (['clang' , '--version' ])
12+ except OSError :
13+ pytest .skip ("'clang' does not exist" , allow_module_level = True )
14+
915
1016def get_debug_section (title , stdout ):
1117 s = re .sub (r'0x[0-9a-fA-F]+' , '0x12345678' , stdout )
@@ -21,7 +27,7 @@ def get_debug_section(title, stdout):
2127 s = re .sub (r"return '[a-zA-Z0-9: *]+'" , "return" , s )
2228
2329 pos1 = s .find (title )
24- assert pos1 > 0
30+ assert pos1 > 0 , 'title not found'
2531 pos1 = s .find ('\n ' , pos1 ) + 1
2632 assert pos1 > 0
2733 pos2 = s .find ("\n ##" , pos1 )
@@ -31,50 +37,38 @@ def get_debug_section(title, stdout):
3137
3238
3339def check_symbol_database (code ):
34- # Only compare symboldatabases if clang is found in PATH
35- try :
36- subprocess .call (['clang' , '--version' ])
37- except OSError :
38- return
39-
4040 testfile = 'test.cpp'
4141 with open (testfile , 'w+t' ) as f :
4242 f .write (code )
43- ret1 , stdout1 , stderr1 = cppcheck (['--clang' , '--debug' , '-v' , testfile ])
44- ret2 , stdout2 , stderr2 = cppcheck (['--debug' , '-v' , testfile ])
43+ ret1 , stdout1 , _ = cppcheck (['--clang' , '--debug' , '-v' , testfile ])
44+ ret2 , stdout2 , _ = cppcheck (['--debug' , '-v' , testfile ])
4545 os .remove (testfile )
46+ assert 0 == ret1 , stdout1
47+ assert 0 == ret2 , stdout2
4648 assert get_debug_section ('### Symbol database' , stdout1 ) == get_debug_section ('### Symbol database' , stdout2 )
4749
4850
4951def check_ast (code ):
50- # Only compare syntax trees if clang is found in PATH
51- try :
52- subprocess .call (['clang' , '--version' ])
53- except OSError :
54- return
55-
5652 testfile = 'test.cpp'
5753 with open (testfile , 'w+t' ) as f :
5854 f .write (code )
59- ret1 , stdout1 , stderr1 = cppcheck (['--clang' , '--debug' , '-v' , testfile ])
60- ret2 , stdout2 , stderr2 = cppcheck (['--debug' , '-v' , testfile ])
55+ ret1 , stdout1 , _ = cppcheck (['--clang' , '--debug' , '-v' , testfile ])
56+ ret2 , stdout2 , _ = cppcheck (['--debug' , '-v' , testfile ])
6157 os .remove (testfile )
58+ assert 0 == ret1 , stdout1
59+ assert 0 == ret2 , stdout1
6260 assert get_debug_section ('##AST' , stdout1 ) == get_debug_section ('##AST' , stdout2 )
6361
6462
6563def todo_check_ast (code ):
66- # Only compare syntax trees if clang is found in PATH
67- try :
68- subprocess .call (['clang' , '--version' ])
69- except OSError :
70- return
71-
7264 testfile = 'test.cpp'
7365 with open (testfile , 'w+t' ) as f :
7466 f .write (code )
75- ret1 , stdout1 , stderr1 = cppcheck (['--clang' , '--debug' , '-v' , testfile ])
76- ret2 , stdout2 , stderr2 = cppcheck (['--debug' , '-v' , testfile ])
67+ ret1 , stdout1 , _ = cppcheck (['--clang' , '--debug' , '-v' , testfile ])
68+ ret2 , stdout2 , _ = cppcheck (['--debug' , '-v' , testfile ])
7769 os .remove (testfile )
70+ assert 0 == ret1 , stdout1
71+ assert 0 == ret2 , stdout2
7872 assert get_debug_section ('##AST' , stdout1 ) != get_debug_section ('##AST' , stdout2 )
7973
8074
0 commit comments