diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index b35a411e3..6ef6b578f 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -25,6 +25,7 @@ #include "timer.h" #include "settings.h" #include "cmdlineparser.h" +#include "path.h" // xml is used in rules #include "tinyxml/tinyxml.h" @@ -254,9 +255,10 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[]) { path = 2 + argv[i]; } + path = Path::fromNativeSeparators(path); // If path doesn't end with / or \, add it - if (path[path.length()-1] != '/' && path[path.length()-1] != '\\') + if (path[path.length()-1] != '/') path += '/'; _settings->_includePaths.push_back(path); diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index 661c1a9ab..c4d5b9f97 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -24,6 +24,7 @@ #include // EXIT_SUCCESS and EXIT_FAILURE #include "cmdlineparser.h" #include "filelister.h" +#include "path.h" CppCheckExecutor::CppCheckExecutor() { @@ -63,9 +64,10 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c iter != _settings._includePaths.end(); ++iter) { - if (!getFileLister()->isDirectory(iter->c_str())) + const std::string path(Path::toNativeSeparators(*iter)); + if (!getFileLister()->isDirectory(path.c_str())) { - std::cout << "cppcheck: error: Couldn't find path given by -I '" + *iter + "'" << std::endl; + std::cout << "cppcheck: error: Couldn't find path given by -I '" + path + "'" << std::endl; return false; } } diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 5f5b4ff44..467ad7f58 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -1537,10 +1537,11 @@ void Preprocessor::handleIncludes(std::string &code, const std::string &filePath includePaths2.push_front(""); for (std::list::const_iterator iter = includePaths2.begin(); iter != includePaths2.end(); ++iter) { - fin.open((*iter + filename).c_str()); + const std::string path(Path::toNativeSeparators(*iter)); + fin.open((path + filename).c_str()); if (fin.is_open()) { - filename = *iter + filename; + filename = path + filename; fileOpened = true; break; } diff --git a/test/testcmdlineparser.cpp b/test/testcmdlineparser.cpp index 6d45d09bb..3caba1749 100644 --- a/test/testcmdlineparser.cpp +++ b/test/testcmdlineparser.cpp @@ -51,6 +51,9 @@ private: TEST_CASE(defines3); TEST_CASE(includesnopath); TEST_CASE(includes); + TEST_CASE(includesslash); + TEST_CASE(includesbackslash); + TEST_CASE(includesnospace); TEST_CASE(includes2); TEST_CASE(enabledAll); TEST_CASE(enabledStyle); @@ -276,6 +279,36 @@ private: ASSERT_EQUALS(" include/", settings._includePaths.front()); } + void includesslash() + { + REDIRECT; + const char *argv[] = {"cppcheck", "-I include/", "file.cpp"}; + Settings settings; + CmdLineParser parser(&settings); + ASSERT(parser.ParseFromArgs(3, argv)); + ASSERT_EQUALS(" include/", settings._includePaths.front()); + } + + void includesbackslash() + { + REDIRECT; + const char *argv[] = {"cppcheck", "-I include\\", "file.cpp"}; + Settings settings; + CmdLineParser parser(&settings); + ASSERT(parser.ParseFromArgs(3, argv)); + ASSERT_EQUALS(" include/", settings._includePaths.front()); + } + + void includesnospace() + { + REDIRECT; + const char *argv[] = {"cppcheck", "-Iinclude", "file.cpp"}; + Settings settings; + CmdLineParser parser(&settings); + ASSERT(parser.ParseFromArgs(3, argv)); + ASSERT_EQUALS("include/", settings._includePaths.front()); + } + void includes2() { REDIRECT;