Skip to content

Commit 5e9ef71

Browse files
committed
addoninfo.cpp: use Path::join() in getFullPath()
1 parent 2f0358d commit 5e9ef71

2 files changed

Lines changed: 55 additions & 25 deletions

File tree

lib/addoninfo.cpp

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,36 @@ static std::string getFullPath(const std::string &fileName, const std::string &e
3939
return "";
4040

4141
const std::string exepath = Path::getPathFromFilename(exename);
42-
if (debug)
43-
std::cout << "looking for addon '" << (exepath + fileName) << "'" << std::endl;
44-
if (Path::isFile(exepath + fileName))
45-
return exepath + fileName;
46-
if (debug)
47-
std::cout << "looking for addon '" << (exepath + "addons/" + fileName) << "'" << std::endl;
48-
if (Path::isFile(exepath + "addons/" + fileName))
49-
return exepath + "addons/" + fileName;
42+
{
43+
std::string p = Path::join(exepath, fileName);
44+
if (debug)
45+
std::cout << "looking for addon '" << p << "'" << std::endl;
46+
if (Path::isFile(p))
47+
return p;
48+
}
49+
{
50+
std::string p = Path::join(exepath, "addons", fileName);
51+
if (debug)
52+
std::cout << "looking for addon '" << p << "'" << std::endl;
53+
if (Path::isFile(p))
54+
return p;
55+
}
5056

5157
#ifdef FILESDIR
52-
if (debug)
53-
std::cout << "looking for addon '" << (FILESDIR + ("/" + fileName)) << "'" << std::endl;
54-
if (Path::isFile(FILESDIR + ("/" + fileName)))
55-
return FILESDIR + ("/" + fileName);
56-
if (debug)
57-
std::cout << "looking for addon '" << (FILESDIR + ("/addons/" + fileName)) << "'" << std::endl;
58-
if (Path::isFile(FILESDIR + ("/addons/" + fileName)))
59-
return FILESDIR + ("/addons/" + fileName);
58+
{
59+
std::string p = Path::join(FILESDIR, fileName);
60+
if (debug)
61+
std::cout << "looking for addon '" << p << "'" << std::endl;
62+
if (Path::isFile(p))
63+
return p;
64+
}
65+
{
66+
std::string p = Path::join(FILESDIR, "addons", fileName);
67+
if (debug)
68+
std::cout << "looking for addon '" << p << "'" << std::endl;
69+
if (Path::isFile(p))
70+
return p;
71+
}
6072
#endif
6173
return "";
6274
}

test/cli/lookup_test.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -644,12 +644,14 @@ def test_addon_lookup(tmpdir):
644644
exitcode, stdout, stderr, exe = cppcheck_ex(['--debug-lookup=addon', '--addon=misra', test_file])
645645
exepath = os.path.dirname(exe)
646646
exepath_sep = exepath + os.path.sep
647+
if sys.platform == 'win32':
648+
exepath_sep = exepath_sep.replace('\\', '/')
647649
assert exitcode == 0, stdout if stdout else stderr
648650
lines = stdout.splitlines()
649651
assert lines == [
650652
"looking for addon 'misra.py'",
651653
"looking for addon '{}misra.py'".format(exepath_sep),
652-
"looking for addon '{}addons/misra.py'".format(exepath_sep), # TODO: mixed separators
654+
"looking for addon '{}addons/misra.py'".format(exepath_sep),
653655
'Checking {} ...'.format(test_file)
654656
]
655657

@@ -662,12 +664,14 @@ def test_addon_lookup_ext(tmpdir):
662664
exitcode, stdout, stderr, exe = cppcheck_ex(['--debug-lookup=addon', '--addon=misra.py', test_file])
663665
exepath = os.path.dirname(exe)
664666
exepath_sep = exepath + os.path.sep
667+
if sys.platform == 'win32':
668+
exepath_sep = exepath_sep.replace('\\', '/')
665669
assert exitcode == 0, stdout if stdout else stderr
666670
lines = stdout.splitlines()
667671
assert lines == [
668672
"looking for addon 'misra.py'",
669673
"looking for addon '{}misra.py'".format(exepath_sep),
670-
"looking for addon '{}addons/misra.py'".format(exepath_sep), # TODO: mixed separators
674+
"looking for addon '{}addons/misra.py'".format(exepath_sep),
671675
'Checking {} ...'.format(test_file)
672676
]
673677

@@ -680,12 +684,14 @@ def test_addon_lookup_notfound(tmpdir):
680684
exitcode, stdout, _, exe = cppcheck_ex(['--debug-lookup=addon', '--addon=none', test_file])
681685
exepath = os.path.dirname(exe)
682686
exepath_sep = exepath + os.path.sep
687+
if sys.platform == 'win32':
688+
exepath_sep = exepath_sep.replace('\\', '/')
683689
assert exitcode == 1, stdout
684690
lines = stdout.splitlines()
685691
assert lines == [
686692
"looking for addon 'none.py'",
687693
"looking for addon '{}none.py'".format(exepath_sep),
688-
"looking for addon '{}addons/none.py'".format(exepath_sep), # TODO: mixed separators
694+
"looking for addon '{}addons/none.py'".format(exepath_sep),
689695
'Did not find addon none.py'
690696
]
691697

@@ -696,13 +702,15 @@ def test_addon_lookup_notfound_project(tmpdir): # #13940 / #13941
696702
exitcode, stdout, _, exe = cppcheck_ex(['--debug-lookup=addon', '--addon=none', '--project={}'.format(project_file)])
697703
exepath = os.path.dirname(exe)
698704
exepath_sep = exepath + os.path.sep
705+
if sys.platform == 'win32':
706+
exepath_sep = exepath_sep.replace('\\', '/')
699707
assert exitcode == 1, stdout
700708
lines = stdout.splitlines()
701709
assert lines == [
702710
# TODO: needs to look relative to the project file first
703711
"looking for addon 'none.py'",
704712
"looking for addon '{}none.py'".format(exepath_sep),
705-
"looking for addon '{}addons/none.py'".format(exepath_sep), # TODO: mixed separators
713+
"looking for addon '{}addons/none.py'".format(exepath_sep),
706714
'Did not find addon none.py'
707715
]
708716

@@ -713,12 +721,14 @@ def test_addon_lookup_notfound_compdb(tmpdir):
713721
exitcode, stdout, _, exe = cppcheck_ex(['--debug-lookup=addon', '--addon=none', '--project={}'.format(compdb_file)])
714722
exepath = os.path.dirname(exe)
715723
exepath_sep = exepath + os.path.sep
724+
if sys.platform == 'win32':
725+
exepath_sep = exepath_sep.replace('\\', '/')
716726
assert exitcode == 1, stdout
717727
lines = stdout.splitlines()
718728
assert lines == [
719729
"looking for addon 'none.py'",
720730
"looking for addon '{}none.py'".format(exepath_sep),
721-
"looking for addon '{}addons/none.py'".format(exepath_sep), # TODO: mixed separators
731+
"looking for addon '{}addons/none.py'".format(exepath_sep),
722732
'Did not find addon none.py'
723733
]
724734

@@ -731,12 +741,14 @@ def test_addon_lookup_ext_notfound(tmpdir):
731741
exitcode, stdout, _, exe = cppcheck_ex(['--debug-lookup=addon', '--addon=none.py', test_file])
732742
exepath = os.path.dirname(exe)
733743
exepath_sep = exepath + os.path.sep
744+
if sys.platform == 'win32':
745+
exepath_sep = exepath_sep.replace('\\', '/')
734746
assert exitcode == 1, stdout
735747
lines = stdout.splitlines()
736748
assert lines == [
737749
"looking for addon 'none.py'",
738750
"looking for addon '{}none.py'".format(exepath_sep),
739-
"looking for addon '{}addons/none.py'".format(exepath_sep), # TODO: mixed separators
751+
"looking for addon '{}addons/none.py'".format(exepath_sep),
740752
'Did not find addon none.py'
741753
]
742754

@@ -749,12 +761,14 @@ def test_addon_lookup_relative_notfound(tmpdir):
749761
exitcode, stdout, _, exe = cppcheck_ex(['--debug-lookup=addon', '--addon=addon/misra.py', test_file])
750762
exepath = os.path.dirname(exe)
751763
exepath_sep = exepath + os.path.sep
764+
if sys.platform == 'win32':
765+
exepath_sep = exepath_sep.replace('\\', '/')
752766
assert exitcode == 1, stdout
753767
lines = stdout.splitlines()
754768
assert lines == [
755769
"looking for addon 'addon/misra.py'",
756770
"looking for addon '{}addon/misra.py'".format(exepath_sep),
757-
"looking for addon '{}addons/addon/misra.py'".format(exepath_sep), # TODO: mixed separators
771+
"looking for addon '{}addons/addon/misra.py'".format(exepath_sep),
758772
'Did not find addon addon/misra.py'
759773
]
760774

@@ -767,12 +781,14 @@ def test_addon_lookup_relative_noext_notfound(tmpdir):
767781
exitcode, stdout, _, exe = cppcheck_ex(['--debug-lookup=addon', '--addon=addon/misra', test_file])
768782
exepath = os.path.dirname(exe)
769783
exepath_sep = exepath + os.path.sep
784+
if sys.platform == 'win32':
785+
exepath_sep = exepath_sep.replace('\\', '/')
770786
assert exitcode == 1, stdout
771787
lines = stdout.splitlines()
772788
assert lines == [
773789
"looking for addon 'addon/misra.py'",
774790
"looking for addon '{}addon/misra.py'".format(exepath_sep),
775-
"looking for addon '{}addons/addon/misra.py'".format(exepath_sep), # TODO: mixed separators
791+
"looking for addon '{}addons/addon/misra.py'".format(exepath_sep),
776792
'Did not find addon addon/misra.py'
777793
]
778794

@@ -825,12 +841,14 @@ def test_addon_lookup_nofile(tmpdir):
825841
exitcode, stdout, stderr, exe = cppcheck_ex(['--debug-lookup=addon', '--addon=misra', test_file])
826842
exepath = os.path.dirname(exe)
827843
exepath_sep = exepath + os.path.sep
844+
if sys.platform == 'win32':
845+
exepath_sep = exepath_sep.replace('\\', '/')
828846
assert exitcode == 0, stdout if stdout else stderr
829847
lines = stdout.splitlines()
830848
assert lines == [
831849
"looking for addon 'misra.py'",
832850
"looking for addon '{}misra.py'".format(exepath_sep),
833-
"looking for addon '{}addons/misra.py'".format(exepath_sep), # TODO: mixed separators
851+
"looking for addon '{}addons/misra.py'".format(exepath_sep),
834852
'Checking {} ...'.format(test_file)
835853
]
836854

0 commit comments

Comments
 (0)