GUI: Test ProjectFile::getCheckSuppressions()
This commit is contained in:
parent
5a14473963
commit
3327102aa4
|
@ -30,7 +30,6 @@
|
|||
#include "mainwindow.h"
|
||||
|
||||
#include "cppcheck.h"
|
||||
#include "path.h"
|
||||
|
||||
#include "applicationlist.h"
|
||||
#include "aboutdialog.h"
|
||||
|
@ -59,19 +58,6 @@ static QString getDataDir(const QSettings *settings)
|
|||
return dataDir.isEmpty() ? appPath : dataDir;
|
||||
}
|
||||
|
||||
static QList<Suppressions::Suppression> getCheckSuppressions(const ProjectFile &project)
|
||||
{
|
||||
QList<Suppressions::Suppression> ret;
|
||||
const std::string projectFilePath = Path::getPathFromFilename(project.getFilename().toStdString());
|
||||
foreach (Suppressions::Suppression suppression, project.getSuppressions()) {
|
||||
if (!suppression.fileName.empty() && suppression.fileName[0]!='*' && !Path::isAbsolute(suppression.fileName))
|
||||
suppression.fileName = Path::simplifyPath(projectFilePath) + suppression.fileName;
|
||||
|
||||
ret.append(suppression);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) :
|
||||
mSettings(settings),
|
||||
mApplications(new ApplicationList(this)),
|
||||
|
@ -458,7 +444,7 @@ void MainWindow::doAnalyzeProject(ImportProject p, const bool checkLibrary, cons
|
|||
mThread->setAddonsAndTools(mProjectFile->getAddonsAndTools(), mSettings->value(SETTINGS_MISRA_FILE).toString());
|
||||
QString clangHeaders = mSettings->value(SETTINGS_VS_INCLUDE_PATHS).toString();
|
||||
mThread->setClangIncludePaths(clangHeaders.split(";"));
|
||||
mThread->setSuppressions(getCheckSuppressions(*mProjectFile));
|
||||
mThread->setSuppressions(mProjectFile->getCheckSuppressions());
|
||||
}
|
||||
mThread->setProject(p);
|
||||
mThread->check(checkSettings);
|
||||
|
@ -857,8 +843,7 @@ Settings MainWindow::getCppcheckSettings()
|
|||
tryLoadLibrary(&result.library, filename);
|
||||
}
|
||||
|
||||
|
||||
foreach (const Suppressions::Suppression &suppression, getCheckSuppressions(*mProjectFile)) {
|
||||
foreach (const Suppressions::Suppression &suppression, mProjectFile->getCheckSuppressions()) {
|
||||
result.nomsg.addSuppression(suppression);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
#include "projectfile.h"
|
||||
#include "common.h"
|
||||
|
||||
#include "path.h"
|
||||
|
||||
static const char ProjectElementName[] = "project";
|
||||
static const char ProjectVersionAttrib[] = "version";
|
||||
static const char ProjectFileVersion[] = "1";
|
||||
|
@ -596,6 +598,19 @@ void ProjectFile::readStringList(QStringList &stringlist, QXmlStreamReader &read
|
|||
} while (!allRead);
|
||||
}
|
||||
|
||||
QList<Suppressions::Suppression> ProjectFile::getCheckSuppressions() const
|
||||
{
|
||||
QList<Suppressions::Suppression> ret;
|
||||
const std::string projectFilePath = Path::getPathFromFilename(mFilename.toStdString());
|
||||
foreach (Suppressions::Suppression suppression, getSuppressions()) {
|
||||
if (!suppression.fileName.empty() && suppression.fileName[0]!='*' && !Path::isAbsolute(suppression.fileName))
|
||||
suppression.fileName = Path::simplifyPath(projectFilePath) + suppression.fileName;
|
||||
|
||||
ret.append(suppression);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ProjectFile::setIncludes(const QStringList &includes)
|
||||
{
|
||||
mIncludeDirs = includes;
|
||||
|
|
|
@ -141,13 +141,19 @@ public:
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief Get list suppressions.
|
||||
* @brief Get "raw" suppressions.
|
||||
* @return list of suppressions.
|
||||
*/
|
||||
QList<Suppressions::Suppression> getSuppressions() const {
|
||||
return mSuppressions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get "check" suppressions.
|
||||
* @return list of suppressions.
|
||||
*/
|
||||
QList<Suppressions::Suppression> getCheckSuppressions() const;
|
||||
|
||||
/**
|
||||
* @brief Get list addons.
|
||||
* @return list of addons.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
TEMPLATE = app
|
||||
TARGET = test-projectfile
|
||||
DEPENDPATH += .
|
||||
INCLUDEPATH += .
|
||||
INCLUDEPATH += . ../../../externals/simplecpp
|
||||
OBJECTS_DIR = ../build
|
||||
MOC_DIR = ../build
|
||||
|
||||
|
@ -11,7 +11,11 @@ DEFINES += SRCDIR=\\\"$$PWD\\\"
|
|||
|
||||
# tests
|
||||
SOURCES += testprojectfile.cpp \
|
||||
../../projectfile.cpp
|
||||
../../projectfile.cpp \
|
||||
../../../lib/path.cpp \
|
||||
../../../externals/simplecpp/simplecpp.cpp
|
||||
|
||||
HEADERS += testprojectfile.h \
|
||||
../../projectfile.h
|
||||
../../projectfile.h \
|
||||
../../../lib/path.h \
|
||||
../../../externals/simplecpp/simplecpp.h
|
||||
|
|
|
@ -94,4 +94,18 @@ void TestProjectFile::loadSimpleNoroot()
|
|||
QCOMPARE(defines[0], QString("FOO"));
|
||||
}
|
||||
|
||||
void TestProjectFile::checkSuppressions()
|
||||
{
|
||||
ProjectFile projectFile("/foo/bar/test.cppcheck");
|
||||
QList<Suppressions::Suppression> suppressions;
|
||||
suppressions.append(Suppressions::Suppression("id", "file.c"));
|
||||
suppressions.append(Suppressions::Suppression("id", "/abc/file.c"));
|
||||
projectFile.setSuppressions(suppressions);
|
||||
|
||||
const QList<Suppressions::Suppression> s = projectFile.getCheckSuppressions();
|
||||
QCOMPARE(s.size(), 2);
|
||||
QCOMPARE(s[0].fileName, std::string("/foo/bar/file.c"));
|
||||
QCOMPARE(s[1].fileName, std::string("/abc/file.c"));
|
||||
}
|
||||
|
||||
QTEST_MAIN(TestProjectFile)
|
||||
|
|
|
@ -27,4 +27,5 @@ private slots:
|
|||
void loadSimple();
|
||||
void loadSimpleWithIgnore();
|
||||
void loadSimpleNoroot();
|
||||
void checkSuppressions();
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue