Skip to content

Commit 83d4068

Browse files
committed
CI; Fixed problems in windows paths
1 parent 4a4808e commit 83d4068

3 files changed

Lines changed: 17 additions & 27 deletions

File tree

lib/importproject.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1251,7 +1251,7 @@ void ImportProject::setRelativePaths(const std::string &filename)
12511251
{
12521252
if (Path::isAbsolute(filename))
12531253
return;
1254-
const std::vector<std::string> basePaths{Path::getCurrentPath()};
1254+
const std::vector<std::string> basePaths{Path::fromNativeSeparators(Path::getCurrentPath())};
12551255
for (auto &fs: fileSettings) {
12561256
fs.filename = Path::getRelativePath(fs.filename, basePaths);
12571257
for (auto &includePath: fs.includePaths)

test/cli/test-proj2.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ def realpath(s):
2020
def 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
2727
def cppcheck_local(args):
@@ -44,8 +44,8 @@ def test_file_filter():
4444
def 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():
6565
def 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():
8383
def 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

test/cli/testutils.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,12 @@ def create_gui_project_file(project_file, root_path=None, import_project=None, p
4343
# Run Cppcheck with args
4444
def cppcheck(args):
4545
exe = None
46-
if os.path.isfile('../../cppcheck.exe'):
47-
exe = '../../cppcheck.exe'
48-
elif os.path.isfile('../../../cppcheck.exe'):
49-
exe = '../../../cppcheck.exe'
50-
elif os.path.isfile('../../bin/cppcheck.exe'):
51-
exe = '../../bin/cppcheck.exe'
52-
elif os.path.isfile('../../../bin/cppcheck.exe'):
53-
exe = '../../../bin/cppcheck.exe'
54-
elif os.path.isfile('../../bin/cppcheck'):
55-
exe = '../../bin/cppcheck'
56-
elif os.path.isfile('../../../bin/cppcheck'):
57-
exe = '../../../bin/cppcheck'
58-
elif os.path.isfile('../../cppcheck'):
59-
exe = '../../cppcheck'
60-
else:
61-
exe = '../../../cppcheck'
46+
for ext in ('', '.exe'):
47+
for base in ('../../', '../../../'):
48+
for path in ('', 'bin/', 'bin/debug/'):
49+
if (exe is None) and os.path.isfile(base + path + 'cppcheck' + ext):
50+
exe = base + path + 'cppcheck' + ext
51+
assert exe is not None
6252

6353
logging.info(exe + ' ' + ' '.join(args))
6454
p = subprocess.Popen([exe] + args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

0 commit comments

Comments
 (0)