diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index 2c879daa904..00c39e55fee 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -391,7 +391,10 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a std::string platform; char defaultSign = '\0'; - std::vector lookupPaths{argv[0]}; + std::vector lookupPaths{ + Path::getCurrentPath(), // TODO: do we want to look in CWD? + Path::getPathFromFilename(argv[0]) + }; bool executorAuto = true; @@ -1142,7 +1145,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a platform = project.guiProject.platform; // look for external files relative to project first - lookupPaths.insert(lookupPaths.cbegin(), projectFile); + lookupPaths.insert(lookupPaths.cbegin(), Path::getPathFromFilename(projectFile)); const auto& projectFileGui = project.guiProject.projectFile; if (!projectFileGui.empty()) { diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index ce900e4230a..5e74e35556e 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -1142,8 +1142,11 @@ bool MainWindow::getCppcheckSettings(Settings& settings, Suppressions& supprs) const QString platform = mProjectFile->getPlatform(); if (platform.endsWith(".xml")) { - const QString applicationFilePath = QCoreApplication::applicationFilePath(); - settings.platform.loadFromFile(applicationFilePath.toStdString().c_str(), platform.toStdString()); + const std::vector paths = { + Path::getCurrentPath(), // TODO: do we want to look in CWD? + QCoreApplication::applicationFilePath().toStdString(), + }; + settings.platform.loadFromFile(paths, platform.toStdString()); } else { for (int i = Platform::Type::Native; i <= Platform::Type::Unix64; i++) { const auto p = static_cast(i); diff --git a/gui/projectfiledialog.cpp b/gui/projectfiledialog.cpp index ef7baf18562..04d1847d477 100644 --- a/gui/projectfiledialog.cpp +++ b/gui/projectfiledialog.cpp @@ -208,8 +208,12 @@ ProjectFileDialog::ProjectFileDialog(ProjectFile *projectFile, bool premium, QWi for (const QFileInfo& item : dir.entryInfoList()) { const QString platformFile = item.fileName(); + const std::vector paths = { + Path::getCurrentPath(), // TODO: do we want to look in CWD? + applicationFilePath.toStdString(), + }; Platform plat2; - if (!plat2.loadFromFile(applicationFilePath.toStdString().c_str(), platformFile.toStdString())) + if (!plat2.loadFromFile(paths, platformFile.toStdString())) continue; if (platformFiles.indexOf(platformFile) == -1) diff --git a/lib/platform.cpp b/lib/platform.cpp index 7669b2266f3..77133398e88 100644 --- a/lib/platform.cpp +++ b/lib/platform.cpp @@ -170,27 +170,19 @@ bool Platform::set(const std::string& platformstr, std::string& errstr, const st errstr = "unrecognized platform: '" + platformstr + "' (no lookup)."; return false; } - else { - bool found = false; - for (const std::string& path : paths) { - if (debug) - std::cout << "looking for platform '" + platformstr + "' relative to '" + path + "'" << std::endl; - if (loadFromFile(path.c_str(), platformstr, debug)) { - found = true; - break; - } - } - if (!found) { - errstr = "unrecognized platform: '" + platformstr + "'."; - return false; - } + else if (!loadFromFile(paths, platformstr, debug)) { + errstr = "unrecognized platform: '" + platformstr + "'."; + return false; } return true; } -bool Platform::loadFromFile(const char exename[], const std::string &filename, bool debug) +bool Platform::loadFromFile(const std::vector& paths, const std::string &filename, bool debug) { + if (debug) + std::cout << "looking for platform '" + filename + "'" << std::endl; + const bool is_abs_path = Path::isAbsolute(filename); std::string fullfilename(filename); @@ -200,20 +192,33 @@ bool Platform::loadFromFile(const char exename[], const std::string &filename, b fullfilename += ".xml"; // TODO: use native separators - std::vector filenames{ - fullfilename, - }; - if (!is_abs_path) { - filenames.push_back("platforms/" + fullfilename); - if (exename && (std::string::npos != Path::fromNativeSeparators(exename).find('/'))) { - filenames.push_back(Path::getPathFromFilename(Path::fromNativeSeparators(exename)) + fullfilename); - filenames.push_back(Path::getPathFromFilename(Path::fromNativeSeparators(exename)) + "platforms/" + fullfilename); + std::vector filenames; + if (is_abs_path) + { + filenames.push_back(fullfilename); + } + else { + // TODO: drop duplicated paths + for (const std::string& path : paths) + { + if (path.empty()) + continue; // TODO: error out instead? + + std::string ppath = Path::fromNativeSeparators(path); + if (ppath.back() != '/') + ppath += '/'; + // TODO: look in platforms first? + filenames.push_back(ppath + fullfilename); + filenames.push_back(ppath + "platforms/" + fullfilename); } #ifdef FILESDIR std::string filesdir = FILESDIR; - if (!filesdir.empty() && filesdir[filesdir.size()-1] != '/') - filesdir += '/'; - filenames.push_back(filesdir + ("platforms/" + fullfilename)); + if (!filesdir.empty()) { + if (filesdir.back() != '/') + filesdir += '/'; + // TODO: look in filesdir? + filenames.push_back(filesdir + "platforms/" + fullfilename); + } #endif } diff --git a/lib/platform.h b/lib/platform.h index 86d1ccdfc2f..b4136250969 100644 --- a/lib/platform.h +++ b/lib/platform.h @@ -44,6 +44,7 @@ namespace tinyxml2 { * @brief Platform settings */ class CPPCHECKLIB Platform { + friend class TestPlatform; private: static long long min_value(std::uint8_t bit) { assert(bit > 0); @@ -68,6 +69,9 @@ class CPPCHECKLIB Platform { /** provides list of defines specified by the limit.h/climits includes */ std::string getLimitsDefines(bool c99) const; + + /** load platform from xml document, primarily for testing */ + bool loadFromXmlDocument(const tinyxml2::XMLDocument *doc); public: Platform(); @@ -137,15 +141,13 @@ class CPPCHECKLIB Platform { /** * load platform file - * @param exename application path + * @param paths the additional paths to look into * @param filename platform filename * @param debug log verbose information about the lookup * @return returns true if file was loaded successfully */ - bool loadFromFile(const char exename[], const std::string &filename, bool debug = false); + bool loadFromFile(const std::vector& paths, const std::string &filename, bool debug = false); - /** load platform from xml document, primarily for testing */ - bool loadFromXmlDocument(const tinyxml2::XMLDocument *doc); /** * @brief Returns true if platform type is Windows diff --git a/test/cli/lookup_test.py b/test/cli/lookup_test.py index a1197c51395..63afdb1912f 100644 --- a/test/cli/lookup_test.py +++ b/test/cli/lookup_test.py @@ -341,44 +341,42 @@ def test_platform_lookup_builtin(tmpdir): ] -@pytest.mark.skip # TODO: performs additional lookups when run via symlink in CI +@pytest.mark.skip # TODO: fails when not run from the root folder def test_platform_lookup(tmpdir): test_file = os.path.join(tmpdir, 'test.c') with open(test_file, 'wt'): pass - exitcode, stdout, stderr, exe = cppcheck_ex(['--debug-lookup=platform', '--platform=avr8', test_file]) - exepath = os.path.dirname(exe) - exepath_bin = os.path.join(exepath, 'cppcheck') + exitcode, stdout, stderr = cppcheck(['--debug-lookup=platform', '--platform=avr8', test_file]) + cwd = os.getcwd() if sys.platform == 'win32': - exepath_bin += '.exe' + cwd = cwd.replace('\\', '/') assert exitcode == 0, stdout if stdout else stderr lines = stdout.splitlines() assert lines == [ - "looking for platform 'avr8' relative to '{}'".format(exepath_bin), - "try to load platform file 'avr8.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=avr8.xml", - "try to load platform file 'platforms/avr8.xml' ... Success", + "looking for platform 'avr8'", + "try to load platform file '{}/avr8.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/avr8.xml".format(cwd, cwd), + "try to load platform file '{}/platforms/avr8.xml' ... Success".format(cwd), 'Checking {} ...'.format(test_file) ] -@pytest.mark.skip # TODO: performs additional lookups when run via symlink in CI +@pytest.mark.skip # TODO: fails when not run from the root folder def test_platform_lookup_ext(tmpdir): test_file = os.path.join(tmpdir, 'test.c') with open(test_file, 'wt'): pass - exitcode, stdout, stderr, exe = cppcheck_ex(['--debug-lookup=platform', '--platform=avr8.xml', test_file]) - exepath = os.path.dirname(exe) - exepath_bin = os.path.join(exepath, 'cppcheck') + exitcode, stdout, stderr = cppcheck(['--debug-lookup=platform', '--platform=avr8.xml', test_file]) + cwd = os.getcwd() if sys.platform == 'win32': - exepath_bin += '.exe' + cwd = cwd.replace('\\', '/') assert exitcode == 0, stdout if stdout else stderr lines = stdout.splitlines() assert lines == [ - "looking for platform 'avr8.xml' relative to '{}'".format(exepath_bin), - "try to load platform file 'avr8.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=avr8.xml", - "try to load platform file 'platforms/avr8.xml' ... Success", + "looking for platform 'avr8.xml'", + "try to load platform file '{}/avr8.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/avr8.xml".format(cwd, cwd), + "try to load platform file '{}/platforms/avr8.xml' ... Success".format(cwd), 'Checking {} ...'.format(test_file) ] @@ -389,48 +387,45 @@ def test_platform_lookup_notfound(tmpdir): pass exitcode, stdout, _, exe = cppcheck_ex(['--debug-lookup=platform', '--platform=none', test_file]) + cwd = os.getcwd() exepath = os.path.dirname(exe) - exepath_bin = os.path.join(exepath, 'cppcheck') if sys.platform == 'win32': + cwd = cwd.replace('\\', '/') exepath = exepath.replace('\\', '/') - exepath_bin += '.exe' assert exitcode == 1, stdout lines = stdout.splitlines() assert lines == [ - "looking for platform 'none' relative to '{}'".format(exepath_bin), - "try to load platform file 'none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=none.xml", - "try to load platform file 'platforms/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=platforms/none.xml", + "looking for platform 'none'", + "try to load platform file '{}/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/none.xml".format(cwd, cwd), + "try to load platform file '{}/platforms/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platforms/none.xml".format(cwd, cwd), "try to load platform file '{}/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/none.xml".format(exepath, exepath), "try to load platform file '{}/platforms/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platforms/none.xml".format(exepath, exepath), "cppcheck: error: unrecognized platform: 'none'." ] +# TODO: test with invalid file in project path +# TODO: test with non-file in project path def test_platform_lookup_notfound_project(tmpdir): # #13939 project_file, _ = __create_gui_project(tmpdir) project_path = os.path.dirname(project_file) exitcode, stdout, _, exe = cppcheck_ex(['--debug-lookup=platform', '--platform=none', '--project={}'.format(project_file)]) + cwd = os.getcwd() exepath = os.path.dirname(exe) - exepath_bin = os.path.join(exepath, 'cppcheck') if sys.platform == 'win32': + cwd = cwd.replace('\\', '/') exepath = exepath.replace('\\', '/') - exepath_bin += '.exe' project_path = project_path.replace('\\', '/') assert exitcode == 1, stdout lines = stdout.splitlines() assert lines == [ - # TODO: the CWD lookups are duplicated - # TODO: needs to do the relative project lookup first - "looking for platform 'none' relative to '{}'".format(project_file), - "try to load platform file 'none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=none.xml", - "try to load platform file 'platforms/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=platforms/none.xml", + "looking for platform 'none'", "try to load platform file '{}/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/none.xml".format(project_path, project_path), "try to load platform file '{}/platforms/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platforms/none.xml".format(project_path, project_path), - "looking for platform 'none' relative to '{}'".format(exepath_bin), - # TODO: should we really check CWD before relative to executable? should we check CWD at all? - "try to load platform file 'none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=none.xml", - "try to load platform file 'platforms/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=platforms/none.xml", + # TODO: the following lookups are in CWD - is this intended? + "try to load platform file '{}/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/none.xml".format(cwd, cwd), + "try to load platform file '{}/platforms/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platforms/none.xml".format(cwd, cwd), "try to load platform file '{}/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/none.xml".format(exepath, exepath), "try to load platform file '{}/platforms/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platforms/none.xml".format(exepath, exepath), "cppcheck: error: unrecognized platform: 'none'." @@ -441,17 +436,17 @@ def test_platform_lookup_notfound_compdb(tmpdir): compdb_file, _ = __create_compdb(tmpdir) exitcode, stdout, _, exe = cppcheck_ex(['--debug-lookup=platform', '--platform=none', '--project={}'.format(compdb_file)]) + cwd = os.getcwd() exepath = os.path.dirname(exe) - exepath_bin = os.path.join(exepath, 'cppcheck') if sys.platform == 'win32': + cwd = cwd.replace('\\', '/') exepath = exepath.replace('\\', '/') - exepath_bin += '.exe' assert exitcode == 1, stdout lines = stdout.splitlines() assert lines == [ - "looking for platform 'none' relative to '{}'".format(exepath_bin), - "try to load platform file 'none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=none.xml", - "try to load platform file 'platforms/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=platforms/none.xml", + "looking for platform 'none'", + "try to load platform file '{}/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/none.xml".format(cwd, cwd), + "try to load platform file '{}/platforms/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platforms/none.xml".format(cwd, cwd), "try to load platform file '{}/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/none.xml".format(exepath, exepath), "try to load platform file '{}/platforms/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platforms/none.xml".format(exepath, exepath), "cppcheck: error: unrecognized platform: 'none'." @@ -464,17 +459,17 @@ def test_platform_lookup_ext_notfound(tmpdir): pass exitcode, stdout, stderr, exe = cppcheck_ex(['--debug-lookup=platform', '--platform=none.xml', test_file]) + cwd = os.getcwd() exepath = os.path.dirname(exe) - exepath_bin = os.path.join(exepath, 'cppcheck') if sys.platform == 'win32': + cwd = cwd.replace('\\', '/') exepath = exepath.replace('\\', '/') - exepath_bin += '.exe' assert exitcode == 1, stdout if stdout else stderr lines = stdout.splitlines() assert lines == [ - "looking for platform 'none.xml' relative to '{}'".format(exepath_bin), - "try to load platform file 'none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=none.xml", - "try to load platform file 'platforms/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=platforms/none.xml", + "looking for platform 'none.xml'", + "try to load platform file '{}/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/none.xml".format(cwd, cwd), + "try to load platform file '{}/platforms/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platforms/none.xml".format(cwd, cwd), "try to load platform file '{}/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/none.xml".format(exepath, exepath), "try to load platform file '{}/platforms/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platforms/none.xml".format(exepath, exepath), "cppcheck: error: unrecognized platform: 'none.xml'." @@ -487,17 +482,17 @@ def test_platform_lookup_relative_notfound(tmpdir): pass exitcode, stdout, stderr, exe = cppcheck_ex(['--debug-lookup=platform', '--platform=platform/none.xml', test_file]) + cwd = os.getcwd() exepath = os.path.dirname(exe) - exepath_bin = os.path.join(exepath, 'cppcheck') if sys.platform == 'win32': + cwd = cwd.replace('\\', '/') exepath = exepath.replace('\\', '/') - exepath_bin += '.exe' assert exitcode == 1, stdout if stdout else stderr lines = stdout.splitlines() assert lines == [ - "looking for platform 'platform/none.xml' relative to '{}'".format(exepath_bin), - "try to load platform file 'platform/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=platform/none.xml", - "try to load platform file 'platforms/platform/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=platforms/platform/none.xml", + "looking for platform 'platform/none.xml'", + "try to load platform file '{}/platform/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platform/none.xml".format(cwd, cwd), + "try to load platform file '{}/platforms/platform/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platforms/platform/none.xml".format(cwd, cwd), "try to load platform file '{}/platform/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platform/none.xml".format(exepath, exepath), "try to load platform file '{}/platforms/platform/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platforms/platform/none.xml".format(exepath, exepath), "cppcheck: error: unrecognized platform: 'platform/none.xml'." @@ -510,17 +505,17 @@ def test_platform_lookup_relative_noext_notfound(tmpdir): pass exitcode, stdout, stderr, exe = cppcheck_ex(['--debug-lookup=platform', '--platform=platform/none', test_file]) + cwd = os.getcwd() exepath = os.path.dirname(exe) - exepath_bin = os.path.join(exepath, 'cppcheck') if sys.platform == 'win32': + cwd = cwd.replace('\\', '/') exepath = exepath.replace('\\', '/') - exepath_bin += '.exe' assert exitcode == 1, stdout if stdout else stderr lines = stdout.splitlines() assert lines == [ - "looking for platform 'platform/none' relative to '{}'".format(exepath_bin), - "try to load platform file 'platform/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=platform/none.xml", - "try to load platform file 'platforms/platform/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=platforms/platform/none.xml", + "looking for platform 'platform/none'", + "try to load platform file '{}/platform/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platform/none.xml".format(cwd, cwd), + "try to load platform file '{}/platforms/platform/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platforms/platform/none.xml".format(cwd, cwd), "try to load platform file '{}/platform/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platform/none.xml".format(exepath, exepath), "try to load platform file '{}/platforms/platform/none.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/platforms/platform/none.xml".format(exepath, exepath), "cppcheck: error: unrecognized platform: 'platform/none'." @@ -538,15 +533,11 @@ def test_platform_lookup_absolute(tmpdir): ''') - exitcode, stdout, stderr, exe = cppcheck_ex(['--debug-lookup=platform', '--platform={}'.format(platform_file), test_file]) - exepath = os.path.dirname(exe) - exepath_bin = os.path.join(exepath, 'cppcheck') - if sys.platform == 'win32': - exepath_bin += '.exe' + exitcode, stdout, stderr = cppcheck(['--debug-lookup=platform', '--platform={}'.format(platform_file), test_file]) assert exitcode == 0, stdout if stdout else stderr lines = stdout.splitlines() assert lines == [ - "looking for platform '{}' relative to '{}'".format(platform_file, exepath_bin), + "looking for platform '{}'".format(platform_file), "try to load platform file '{}' ... Success".format(platform_file), 'Checking {} ...'.format(test_file) ] @@ -559,21 +550,17 @@ def test_platform_lookup_absolute_notfound(tmpdir): platform_file = os.path.join(tmpdir, 'test.xml') - exitcode, stdout, stderr, exe = cppcheck_ex(['--debug-lookup=platform', '--platform={}'.format(platform_file), test_file]) - exepath = os.path.dirname(exe) - exepath_bin = os.path.join(exepath, 'cppcheck') - if sys.platform == 'win32': - exepath_bin += '.exe' + exitcode, stdout, stderr = cppcheck(['--debug-lookup=platform', '--platform={}'.format(platform_file), test_file]) assert exitcode == 1, stdout if stdout else stderr lines = stdout.splitlines() assert lines == [ - "looking for platform '{}' relative to '{}'".format(platform_file, exepath_bin), + "looking for platform '{}'".format(platform_file), "try to load platform file '{}' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}".format(platform_file, platform_file), "cppcheck: error: unrecognized platform: '{}'.".format(platform_file) ] -@pytest.mark.skip # TODO: performs additional lookups when run via symlink in CI +@pytest.mark.skip # TODO: fails when not run from the root folder def test_platform_lookup_nofile(tmpdir): test_file = os.path.join(tmpdir, 'test.c') with open(test_file, 'wt'): @@ -583,18 +570,17 @@ def test_platform_lookup_nofile(tmpdir): avr8_cfg_dir = os.path.join(tmpdir, 'avr8.xml') os.mkdir(avr8_cfg_dir) - exitcode, stdout, stderr, exe = cppcheck_ex(['--debug-lookup=platform', '--platform=avr8', test_file]) - exepath = os.path.dirname(exe) - exepath_bin = os.path.join(exepath, 'cppcheck') + exitcode, stdout, stderr = cppcheck(['--debug-lookup=platform', '--platform=avr8', test_file]) + cwd = os.getcwd() if sys.platform == 'win32': - exepath_bin += '.exe' + cwd = cwd.replace('\\', '/') assert exitcode == 0, stdout if stdout else stderr lines = stdout.splitlines() assert lines == [ - "looking for platform 'avr8' relative to '{}'".format(exepath_bin), - "try to load platform file 'avr8.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename=avr8.xml", - "try to load platform file 'platforms/avr8.xml' ... Success", - 'Checking {} ...'.format(test_file) + "looking for platform 'avr8'", + "try to load platform file '{}/avr8.xml' ... Error=XML_ERROR_FILE_NOT_FOUND ErrorID=3 (0x3) Line number=0: filename={}/avr8.xml".format(cwd, cwd), + "try to load platform file '{}/platforms/avr8.xml' ... Success".format(cwd), + 'Checking {}1 ...'.format(test_file) ] @@ -607,16 +593,15 @@ def test_platform_lookup_invalid(tmpdir): with open(avr8_file, 'wt') as f: f.write('''{}''') - exitcode, stdout, stderr, exe = cppcheck_ex(['--debug-lookup=platform', '--platform=avr8', test_file], cwd=tmpdir) - exepath = os.path.dirname(exe) - exepath_bin = os.path.join(exepath, 'cppcheck') + exitcode, stdout, stderr = cppcheck(['--debug-lookup=platform', '--platform=avr8', test_file], cwd=tmpdir) + cwd = str(tmpdir) if sys.platform == 'win32': - exepath_bin += '.exe' + cwd = cwd.replace('\\', '/') assert exitcode == 1, stdout if stdout else stderr lines = stdout.splitlines() assert lines == [ - "looking for platform 'avr8' relative to '{}'".format(exepath_bin), - "try to load platform file 'avr8.xml' ... Error=XML_ERROR_PARSING_TEXT ErrorID=8 (0x8) Line number=1", + "looking for platform 'avr8'", + "try to load platform file '{}/avr8.xml' ... Error=XML_ERROR_PARSING_TEXT ErrorID=8 (0x8) Line number=1".format(cwd), "cppcheck: error: unrecognized platform: 'avr8'." ]