@@ -20,8 +20,8 @@ def realpath(s):
2020def create_compile_commands ():
2121 j = [{'directory' : realpath ('proj2/a' ), 'command' : 'gcc -c a.c' , 'file' : 'a.c' },
2222 {'directory' : realpath ('proj2' ), 'command' : 'gcc -c b/b.c' , 'file' : 'b/b.c' }]
23- f = open ('proj2/' + COMPILE_COMMANDS_JSON , 'wt' )
24- f .write (json .dumps (j ))
23+ with open ('proj2/' + COMPILE_COMMANDS_JSON , 'wt' ) as f :
24+ f .write (json .dumps (j ))
2525
2626# Run Cppcheck from project path
2727def cppcheck_local (args ):
@@ -44,8 +44,8 @@ def test_file_filter():
4444def test_local_path ():
4545 create_compile_commands ()
4646 ret , stdout , stderr = cppcheck_local (['--project=compile_commands.json' ])
47- file1 = 'a/ a.c'
48- file2 = 'b/ b.c'
47+ file1 = os . path . join ( 'a' , ' a.c')
48+ file2 = os . path . join ( 'b' , ' b.c')
4949 assert ret == 0 , stdout
5050 assert stdout .find ('Checking %s ...' % file1 ) >= 0
5151 assert stdout .find ('Checking %s ...' % file2 ) >= 0
@@ -65,8 +65,8 @@ def test_local_path_maxconfigs():
6565def test_relative_path ():
6666 create_compile_commands ()
6767 ret , stdout , stderr = cppcheck (['--project=proj2/' + COMPILE_COMMANDS_JSON ])
68- file1 = 'proj2/a/ a.c'
69- file2 = 'proj2/b/ b.c'
68+ file1 = os . path . join ( 'proj2' , 'a' , ' a.c')
69+ file2 = os . path . join ( 'proj2' , 'b' , ' b.c')
7070 assert ret == 0 , stdout
7171 assert stdout .find ('Checking %s ...' % file1 ) >= 0
7272 assert stdout .find ('Checking %s ...' % file2 ) >= 0
@@ -83,8 +83,8 @@ def test_absolute_path():
8383def test_gui_project_loads_compile_commands_1 ():
8484 create_compile_commands ()
8585 ret , stdout , stderr = cppcheck (['--project=proj2/proj2.cppcheck' ])
86- file1 = 'proj2/a/ a.c'
87- file2 = 'proj2/b/ b.c'
86+ file1 = os . path . join ( 'proj2' , 'a' , ' a.c')
87+ file2 = os . path . join ( 'proj2' , 'b' , ' b.c')
8888 assert ret == 0 , stdout
8989 assert stdout .find ('Checking %s ...' % file1 ) >= 0
9090 assert stdout .find ('Checking %s ...' % file2 ) >= 0
@@ -96,8 +96,8 @@ def test_gui_project_loads_compile_commands_2():
9696 import_project = 'compile_commands.json' ,
9797 exclude_paths = [exclude_path_1 ])
9898 ret , stdout , stderr = cppcheck (['--project=proj2/test.cppcheck' ])
99- file1 = 'proj2/a/ a.c'
100- file2 = 'proj2/b/ b.c' # Excluded by test.cppcheck
99+ file1 = os . path . join ( 'proj2' , 'a' , ' a.c')
100+ file2 = os . path . join ( 'proj2' , 'b' , ' b.c') # Excluded by test.cppcheck
101101 assert ret == 0 , stdout
102102 assert stdout .find ('Checking %s ...' % file1 ) >= 0
103103 assert stdout .find ('Checking %s ...' % file2 ) < 0
0 commit comments