forked from qt-creator/qt-creator
ClangTools: Add unit-test for standalone ClangTidy+Clazy tool
Use simple project with only few ClangTidy and Clazy warnings. Change-Id: Idfbbeb653c5f610bda502c3ec23e7497f503f8a9 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
@@ -30,12 +30,16 @@
|
||||
#include "clangtidyclazytool.h"
|
||||
#include "clangtoolsutils.h"
|
||||
|
||||
#include <cpptools/cppcodemodelsettings.h>
|
||||
#include <cpptools/cppmodelmanager.h>
|
||||
#include <cpptools/cpptoolstestcase.h>
|
||||
#include <cpptools/cpptoolsreuse.h>
|
||||
#include <projectexplorer/kitinformation.h>
|
||||
#include <projectexplorer/kitmanager.h>
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
#include <projectexplorer/toolchain.h>
|
||||
|
||||
#include <utils/executeondestruction.h>
|
||||
#include <utils/fileutils.h>
|
||||
|
||||
#include <QEventLoop>
|
||||
@@ -72,6 +76,19 @@ void ClangToolsUnitTests::cleanupTestCase()
|
||||
delete m_tmpDir;
|
||||
}
|
||||
|
||||
static CppTools::ClangDiagnosticConfig createTidyClazyConfig()
|
||||
{
|
||||
CppTools::ClangDiagnosticConfig config;
|
||||
config.setId("Test.ClangTidy");
|
||||
config.setDisplayName("Test");
|
||||
config.setIsReadOnly(true);
|
||||
config.setClangOptions(QStringList{QStringLiteral("-Wno-everything")});
|
||||
config.setClangTidyMode(CppTools::ClangDiagnosticConfig::TidyMode::ChecksString);
|
||||
config.setClangTidyChecksString("-*,modernize-*, misc-*");
|
||||
config.setClazyChecks("level2");
|
||||
return config;
|
||||
}
|
||||
|
||||
void ClangToolsUnitTests::testProject()
|
||||
{
|
||||
QFETCH(Tool, clangtool);
|
||||
@@ -91,9 +108,34 @@ void ClangToolsUnitTests::testProject()
|
||||
ClangTool *tool = (clangtool == Tool::ClangStaticAnalyzer)
|
||||
? ClangStaticAnalyzerTool::instance()
|
||||
: static_cast<ClangTool *>(ClangTidyClazyTool::instance());
|
||||
|
||||
ExecuteOnDestruction executeOnDestruction;
|
||||
if (clangtool == Tool::ClangTidyAndClazy) {
|
||||
// Change configs
|
||||
QSharedPointer<CppTools::CppCodeModelSettings> settings = CppTools::codeModelSettings();
|
||||
const CppTools::ClangDiagnosticConfigs originalConfigs
|
||||
= settings->clangCustomDiagnosticConfigs();
|
||||
const Core::Id originalId = settings->clangDiagnosticConfigId();
|
||||
|
||||
CppTools::ClangDiagnosticConfigs modifiedConfigs = originalConfigs;
|
||||
|
||||
const CppTools::ClangDiagnosticConfig clangTidyConfig = createTidyClazyConfig();
|
||||
modifiedConfigs.push_back(clangTidyConfig);
|
||||
|
||||
executeOnDestruction.reset([=]() {
|
||||
// Restore configs
|
||||
settings->setClangCustomDiagnosticConfigs(originalConfigs);
|
||||
settings->setClangDiagnosticConfigId(originalId);
|
||||
});
|
||||
|
||||
settings->setClangCustomDiagnosticConfigs(modifiedConfigs);
|
||||
settings->setClangDiagnosticConfigId(clangTidyConfig.id());
|
||||
}
|
||||
|
||||
tool->startTool();
|
||||
QSignalSpy waiter(tool, SIGNAL(finished(bool)));
|
||||
QVERIFY(waiter.wait(30000));
|
||||
|
||||
const QList<QVariant> arguments = waiter.takeFirst();
|
||||
QVERIFY(arguments.first().toBool());
|
||||
QCOMPARE(tool->diagnostics().count(), expectedDiagCount);
|
||||
@@ -122,6 +164,10 @@ void ClangToolsUnitTests::testProject_data()
|
||||
|
||||
addTestRow(Tool::ClangStaticAnalyzer, "mingw-includes/mingw-includes.qbs", 0);
|
||||
addTestRow(Tool::ClangStaticAnalyzer, "mingw-includes/mingw-includes.pro", 0);
|
||||
|
||||
addTestRow(Tool::ClangTidyAndClazy, "clangtidy_clazy/clangtidy_clazy.pro",
|
||||
4 /* ClangTidy: modernize-*,misc-* */
|
||||
+ 2 /* Clazy: level1 */);
|
||||
}
|
||||
|
||||
void ClangToolsUnitTests::addTestRow(Tool tool, const QByteArray &relativeFilePath,
|
||||
|
||||
@@ -19,5 +19,8 @@
|
||||
<file>unit-tests/stdc++11-includes/main.cpp</file>
|
||||
<file>unit-tests/stdc++11-includes/stdc++11-includes.pro</file>
|
||||
<file>unit-tests/stdc++11-includes/stdc++11-includes.qbs</file>
|
||||
<file>unit-tests/clangtidy_clazy/clangtidy_clazy.pro</file>
|
||||
<file>unit-tests/clangtidy_clazy/clazy_example.cpp</file>
|
||||
<file>unit-tests/clangtidy_clazy/tidy_example.cpp</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
QT += core
|
||||
|
||||
CONFIG+= c++1z
|
||||
|
||||
TARGET = examples
|
||||
|
||||
SOURCES += clazy_example.cpp tidy_example.cpp
|
||||
@@ -0,0 +1,41 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2018 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QCoreApplication>
|
||||
|
||||
// -Wclazy-ctor-missing-parent-argument
|
||||
class TestObject : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TestObject();
|
||||
|
||||
bool event(QEvent *) override
|
||||
{
|
||||
// -Wclazy-base-class-event
|
||||
return false;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,39 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2018 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
class Base
|
||||
{
|
||||
public:
|
||||
// misc-noexcept-move-constructor
|
||||
// misc-unconventional-assign-operator
|
||||
// misc-unused-parameters
|
||||
Base operator=(Base &¶m) { return {}; }
|
||||
virtual int function()
|
||||
{
|
||||
// modernize-use-nullptr
|
||||
int *a = 0;
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user