diff --git a/src/plugins/clangtools/clangtoolsunittests.cpp b/src/plugins/clangtools/clangtoolsunittests.cpp index c8a50ff2bbf..b98f9ff8feb 100644 --- a/src/plugins/clangtools/clangtoolsunittests.cpp +++ b/src/plugins/clangtools/clangtoolsunittests.cpp @@ -30,12 +30,16 @@ #include "clangtidyclazytool.h" #include "clangtoolsutils.h" +#include #include #include +#include #include #include #include #include + +#include #include #include @@ -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(ClangTidyClazyTool::instance()); + + ExecuteOnDestruction executeOnDestruction; + if (clangtool == Tool::ClangTidyAndClazy) { + // Change configs + QSharedPointer 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 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, diff --git a/src/plugins/clangtools/clangtoolsunittests.qrc b/src/plugins/clangtools/clangtoolsunittests.qrc index a9764bfa309..def5ee3437e 100644 --- a/src/plugins/clangtools/clangtoolsunittests.qrc +++ b/src/plugins/clangtools/clangtoolsunittests.qrc @@ -19,5 +19,8 @@ unit-tests/stdc++11-includes/main.cpp unit-tests/stdc++11-includes/stdc++11-includes.pro unit-tests/stdc++11-includes/stdc++11-includes.qbs + unit-tests/clangtidy_clazy/clangtidy_clazy.pro + unit-tests/clangtidy_clazy/clazy_example.cpp + unit-tests/clangtidy_clazy/tidy_example.cpp diff --git a/src/plugins/clangtools/unit-tests/clangtidy_clazy/clangtidy_clazy.pro b/src/plugins/clangtools/unit-tests/clangtidy_clazy/clangtidy_clazy.pro new file mode 100644 index 00000000000..4a68e9c5722 --- /dev/null +++ b/src/plugins/clangtools/unit-tests/clangtidy_clazy/clangtidy_clazy.pro @@ -0,0 +1,7 @@ +QT += core + +CONFIG+= c++1z + +TARGET = examples + +SOURCES += clazy_example.cpp tidy_example.cpp diff --git a/src/plugins/clangtools/unit-tests/clangtidy_clazy/clazy_example.cpp b/src/plugins/clangtools/unit-tests/clangtidy_clazy/clazy_example.cpp new file mode 100644 index 00000000000..5cd980d24c4 --- /dev/null +++ b/src/plugins/clangtools/unit-tests/clangtidy_clazy/clazy_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 + +// -Wclazy-ctor-missing-parent-argument +class TestObject : public QObject +{ + Q_OBJECT + +public: + TestObject(); + + bool event(QEvent *) override + { + // -Wclazy-base-class-event + return false; + } +}; diff --git a/src/plugins/clangtools/unit-tests/clangtidy_clazy/tidy_example.cpp b/src/plugins/clangtools/unit-tests/clangtidy_clazy/tidy_example.cpp new file mode 100644 index 00000000000..12045d82438 --- /dev/null +++ b/src/plugins/clangtools/unit-tests/clangtidy_clazy/tidy_example.cpp @@ -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; + } +};