Exemplo n.º 1
0
void ClangToolsUnitTests::testProject()
{
    QFETCH(QString, projectFilePath);
    QFETCH(int, expectedDiagCount);
    if (projectFilePath.contains("mingw")) {
        const ToolChain * const toolchain
                = ToolChainKitAspect::toolChain(KitManager::kits().constFirst(),
                                                Constants::CXX_LANGUAGE_ID);
        if (toolchain->typeId() != ProjectExplorer::Constants::MINGW_TOOLCHAIN_TYPEID)
            QSKIP("This test is mingw specific, does not run for other toolchains");
    }

    CppTools::Tests::ProjectOpenerAndCloser projectManager;
    const CppTools::ProjectInfo projectInfo = projectManager.open(projectFilePath, true);
    QVERIFY(projectInfo.isValid());
    ClangTool *tool = ClangTidyClazyTool::instance();

    // 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 executeOnDestruction([=]() {
        // Restore configs
        settings->setClangCustomDiagnosticConfigs(originalConfigs);
        settings->setClangDiagnosticConfigId(originalId);
    });

    settings->setClangCustomDiagnosticConfigs(modifiedConfigs);
    settings->setClangDiagnosticConfigId(clangTidyConfig.id());

    tool->startTool(false);
    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);
}
Exemplo n.º 2
0
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::ChecksPrefixList);
    config.setClangTidyChecks("modernize-*, misc-*");
    config.setClazyChecks("level2");
    return config;
}
static CppTools::ClangDiagnosticConfig
createConfigRepresentingGlobalSetting(const CppTools::ClangDiagnosticConfig &baseConfig)
{
    CppTools::ClangDiagnosticConfig config = baseConfig;
    config.setId(GLOBAL_PROXY_CONFIG_ID);

    QString displayName = config.displayName();
    if (config.isReadOnly())
        displayName = CppTools::ClangDiagnosticConfigsModel::displayNameWithBuiltinIndication(config);
    displayName = ClangProjectSettingsWidget::tr("Global setting (%1)").arg(displayName);

    config.setDisplayName(displayName);
    config.setIsReadOnly(true);

    return config;
}