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