Skip to content

Commit

Permalink
more testing and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
danmar committed Apr 8, 2024
1 parent 57d5d1a commit cf2f7bb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
6 changes: 3 additions & 3 deletions gui/projectfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -759,12 +759,12 @@ void ProjectFile::setPlatform(const QString &platform)

QList<SuppressionList::Suppression> ProjectFile::getCheckingSuppressions() const
{
QRegularExpression re("^[^:]+/.*");
const QRegularExpression re1("^[a-zA-Z0-9_\\-]+/.*");
const QRegularExpression re2("^[^/]+$");
QList<SuppressionList::Suppression> result;
for (SuppressionList::Suppression suppression : mSuppressions) {
if (re.match(suppression.fileName.c_str()).hasMatch()) {
if (re1.match(suppression.fileName.c_str()).hasMatch() || re2.match(suppression.fileName.c_str()).hasMatch())
suppression.fileName = QFileInfo(mFilename).absolutePath().toStdString() + "/" + suppression.fileName;
}
result << suppression;
}
return result;
Expand Down
22 changes: 21 additions & 1 deletion gui/test/projectfile/testprojectfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void TestProjectFile::getAddonFilePath() const
QCOMPARE(ProjectFile::getAddonFilePath(tempdir.path(), filepath), filepath);
}

void TestProjectFile::getCheckingSuppressions() const
void TestProjectFile::getCheckingSuppressionsRelative() const
{
const SuppressionList::Suppression suppression("*", "externals/*");
const QList<SuppressionList::Suppression> suppressions{suppression};
Expand All @@ -149,5 +149,25 @@ void TestProjectFile::getCheckingSuppressions() const
QCOMPARE(projectFile.getCheckingSuppressions()[0].fileName, "/some/path/externals/*");
}

void TestProjectFile::getCheckingSuppressionsAbsolute() const
{
const SuppressionList::Suppression suppression("*", "/some/path/1.h");
const QList<SuppressionList::Suppression> suppressions{suppression};
ProjectFile projectFile;
projectFile.setFilename("/other/123.cppcheck");
projectFile.setSuppressions(suppressions);
QCOMPARE(projectFile.getCheckingSuppressions()[0].fileName, "/some/path/1.h");
}

void TestProjectFile::getCheckingSuppressionsStar() const
{
const SuppressionList::Suppression suppression("*", "*.cpp");
const QList<SuppressionList::Suppression> suppressions{suppression};
ProjectFile projectFile;
projectFile.setFilename("/some/path/123.cppcheck");
projectFile.setSuppressions(suppressions);
QCOMPARE(projectFile.getCheckingSuppressions()[0].fileName, "/some/path/*.cpp");
}

QTEST_MAIN(TestProjectFile)

4 changes: 3 additions & 1 deletion gui/test/projectfile/testprojectfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ private slots:

void getAddonFilePath() const;

void getCheckingSuppressions() const;
void getCheckingSuppressionsRelative() const;
void getCheckingSuppressionsAbsolute() const;
void getCheckingSuppressionsStar() const;
};

0 comments on commit cf2f7bb

Please sign in to comment.