From 83d406806fbb5704e7e0d2ecbbfd981b8dbfcbff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 12 Jun 2021 12:45:31 +0200 Subject: [PATCH] CI; Fixed problems in windows paths --- lib/importproject.cpp | 2 +- test/cli/test-proj2.py | 20 ++++++++++---------- test/cli/testutils.py | 22 ++++++---------------- 3 files changed, 17 insertions(+), 27 deletions(-) diff --git a/lib/importproject.cpp b/lib/importproject.cpp index 27743a906..c4cd7f3ce 100644 --- a/lib/importproject.cpp +++ b/lib/importproject.cpp @@ -1251,7 +1251,7 @@ void ImportProject::setRelativePaths(const std::string &filename) { if (Path::isAbsolute(filename)) return; - const std::vector basePaths{Path::getCurrentPath()}; + const std::vector basePaths{Path::fromNativeSeparators(Path::getCurrentPath())}; for (auto &fs: fileSettings) { fs.filename = Path::getRelativePath(fs.filename, basePaths); for (auto &includePath: fs.includePaths) diff --git a/test/cli/test-proj2.py b/test/cli/test-proj2.py index edfa9495f..868d832dd 100644 --- a/test/cli/test-proj2.py +++ b/test/cli/test-proj2.py @@ -20,8 +20,8 @@ def realpath(s): def create_compile_commands(): j = [{'directory': realpath('proj2/a'), 'command': 'gcc -c a.c', 'file': 'a.c'}, {'directory': realpath('proj2'), 'command': 'gcc -c b/b.c', 'file': 'b/b.c'}] - f = open('proj2/' + COMPILE_COMMANDS_JSON, 'wt') - f.write(json.dumps(j)) + with open('proj2/' + COMPILE_COMMANDS_JSON, 'wt') as f: + f.write(json.dumps(j)) # Run Cppcheck from project path def cppcheck_local(args): @@ -44,8 +44,8 @@ def test_file_filter(): def test_local_path(): create_compile_commands() ret, stdout, stderr = cppcheck_local(['--project=compile_commands.json']) - file1 = 'a/a.c' - file2 = 'b/b.c' + file1 = os.path.join('a', 'a.c') + file2 = os.path.join('b', 'b.c') assert ret == 0, stdout assert stdout.find('Checking %s ...' % file1) >= 0 assert stdout.find('Checking %s ...' % file2) >= 0 @@ -65,8 +65,8 @@ def test_local_path_maxconfigs(): def test_relative_path(): create_compile_commands() ret, stdout, stderr = cppcheck(['--project=proj2/' + COMPILE_COMMANDS_JSON]) - file1 = 'proj2/a/a.c' - file2 = 'proj2/b/b.c' + file1 = os.path.join('proj2', 'a', 'a.c') + file2 = os.path.join('proj2', 'b', 'b.c') assert ret == 0, stdout assert stdout.find('Checking %s ...' % file1) >= 0 assert stdout.find('Checking %s ...' % file2) >= 0 @@ -83,8 +83,8 @@ def test_absolute_path(): def test_gui_project_loads_compile_commands_1(): create_compile_commands() ret, stdout, stderr = cppcheck(['--project=proj2/proj2.cppcheck']) - file1 = 'proj2/a/a.c' - file2 = 'proj2/b/b.c' + file1 = os.path.join('proj2', 'a', 'a.c') + file2 = os.path.join('proj2', 'b', 'b.c') assert ret == 0, stdout assert stdout.find('Checking %s ...' % file1) >= 0 assert stdout.find('Checking %s ...' % file2) >= 0 @@ -96,8 +96,8 @@ def test_gui_project_loads_compile_commands_2(): import_project='compile_commands.json', exclude_paths=[exclude_path_1]) ret, stdout, stderr = cppcheck(['--project=proj2/test.cppcheck']) - file1 = 'proj2/a/a.c' - file2 = 'proj2/b/b.c' # Excluded by test.cppcheck + file1 = os.path.join('proj2', 'a', 'a.c') + file2 = os.path.join('proj2', 'b', 'b.c') # Excluded by test.cppcheck assert ret == 0, stdout assert stdout.find('Checking %s ...' % file1) >= 0 assert stdout.find('Checking %s ...' % file2) < 0 diff --git a/test/cli/testutils.py b/test/cli/testutils.py index 2ced12b31..599fd1865 100644 --- a/test/cli/testutils.py +++ b/test/cli/testutils.py @@ -43,22 +43,12 @@ def create_gui_project_file(project_file, root_path=None, import_project=None, p # Run Cppcheck with args def cppcheck(args): exe = None - if os.path.isfile('../../cppcheck.exe'): - exe = '../../cppcheck.exe' - elif os.path.isfile('../../../cppcheck.exe'): - exe = '../../../cppcheck.exe' - elif os.path.isfile('../../bin/cppcheck.exe'): - exe = '../../bin/cppcheck.exe' - elif os.path.isfile('../../../bin/cppcheck.exe'): - exe = '../../../bin/cppcheck.exe' - elif os.path.isfile('../../bin/cppcheck'): - exe = '../../bin/cppcheck' - elif os.path.isfile('../../../bin/cppcheck'): - exe = '../../../bin/cppcheck' - elif os.path.isfile('../../cppcheck'): - exe = '../../cppcheck' - else: - exe = '../../../cppcheck' + for ext in ('', '.exe'): + for base in ('../../', '../../../'): + for path in ('', 'bin/', 'bin/debug/'): + if (exe is None) and os.path.isfile(base + path + 'cppcheck' + ext): + exe = base + path + 'cppcheck' + ext + assert exe is not None logging.info(exe + ' ' + ' '.join(args)) p = subprocess.Popen([exe] + args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)