forked from qt-creator/qt-creator
CMake: Split big plugin tests into smaller pieces
... which can then live closer to the tested code. Change-Id: Icd975a76424ea2258c1bb93afdbaabdf1959340a Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
@@ -29,7 +29,7 @@ add_qtc_plugin(CMakeProjectManager
|
||||
cmakeprojectmanager.cpp cmakeprojectmanager.h
|
||||
cmakeprojectmanagertr.h
|
||||
cmakeprojectnodes.cpp cmakeprojectnodes.h
|
||||
cmakeprojectplugin.cpp cmakeprojectplugin.h
|
||||
cmakeprojectplugin.cpp
|
||||
cmakesettingspage.cpp cmakesettingspage.h
|
||||
cmakespecificsettings.cpp cmakespecificsettings.h
|
||||
cmaketool.cpp cmaketool.h
|
||||
|
@@ -472,18 +472,24 @@ size_t qHash(const CMakeConfigItem &it)
|
||||
return ::qHash(it.key) ^ ::qHash(it.value) ^ ::qHash(it.isUnset) ^ ::qHash(it.isInitial);
|
||||
}
|
||||
|
||||
#if WITH_TESTS
|
||||
|
||||
} // namespace CMakeProjectManager
|
||||
|
||||
#include "cmakeprojectplugin.h"
|
||||
#if WITH_TESTS
|
||||
|
||||
#include <QTest>
|
||||
|
||||
namespace CMakeProjectManager {
|
||||
namespace Internal {
|
||||
namespace CMakeProjectManager::Internal {
|
||||
|
||||
void CMakeProjectPlugin::testCMakeSplitValue_data()
|
||||
class CMakeConfigTest final : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void testCMakeSplitValue_data();
|
||||
void testCMakeSplitValue();
|
||||
};
|
||||
|
||||
void CMakeConfigTest::testCMakeSplitValue_data()
|
||||
{
|
||||
QTest::addColumn<QString>("input");
|
||||
QTest::addColumn<bool>("keepEmpty");
|
||||
@@ -526,7 +532,7 @@ void CMakeProjectPlugin::testCMakeSplitValue_data()
|
||||
<< "C:/something;;/second/path" << true << QStringList({"C:/something", "", "/second/path"});
|
||||
}
|
||||
|
||||
void CMakeProjectPlugin::testCMakeSplitValue()
|
||||
void CMakeConfigTest::testCMakeSplitValue()
|
||||
{
|
||||
QFETCH(QString, input);
|
||||
QFETCH(bool, keepEmpty);
|
||||
@@ -537,7 +543,13 @@ void CMakeProjectPlugin::testCMakeSplitValue()
|
||||
QCOMPARE(expectedOutput, realOutput);
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
QObject *createCMakeConfigTest()
|
||||
{
|
||||
return new CMakeConfigTest();
|
||||
}
|
||||
|
||||
} // CMakeProjectManager::Internal
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace CMakeProjectManager
|
||||
#include "cmakeconfigitem.moc"
|
||||
|
@@ -6,6 +6,7 @@
|
||||
#include "cmake_global.h"
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QObject>
|
||||
#include <QStringList>
|
||||
|
||||
#include <optional>
|
||||
@@ -78,4 +79,8 @@ public:
|
||||
QString expandedValueOf(const ProjectExplorer::Kit *k, const QByteArray &key) const;
|
||||
};
|
||||
|
||||
#ifdef WITH_TESTS
|
||||
namespace Internal { QObject *createCMakeConfigTest(); }
|
||||
#endif
|
||||
|
||||
} // namespace CMakeProjectManager
|
||||
|
@@ -248,15 +248,23 @@ void CMakeParser::flush()
|
||||
} // CMakeProjectManager
|
||||
|
||||
#ifdef WITH_TESTS
|
||||
#include "cmakeprojectplugin.h"
|
||||
|
||||
#include <projectexplorer/outputparser_test.h>
|
||||
|
||||
#include <QTest>
|
||||
|
||||
namespace CMakeProjectManager {
|
||||
namespace CMakeProjectManager::Internal {
|
||||
|
||||
void Internal::CMakeProjectPlugin::testCMakeParser_data()
|
||||
class CMakeParserTest final : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void testCMakeParser_data();
|
||||
void testCMakeParser();
|
||||
};
|
||||
|
||||
void CMakeParserTest::testCMakeParser_data()
|
||||
{
|
||||
QTest::addColumn<QString>("input");
|
||||
QTest::addColumn<OutputParserTester::Channel>("inputChannel");
|
||||
@@ -462,7 +470,7 @@ void Internal::CMakeProjectPlugin::testCMakeParser_data()
|
||||
<< QString();
|
||||
}
|
||||
|
||||
void Internal::CMakeProjectPlugin::testCMakeParser()
|
||||
void CMakeParserTest::testCMakeParser()
|
||||
{
|
||||
OutputParserTester testbench;
|
||||
testbench.addLineParser(new CMakeParser);
|
||||
@@ -478,6 +486,13 @@ void Internal::CMakeProjectPlugin::testCMakeParser()
|
||||
outputLines);
|
||||
}
|
||||
|
||||
} // CMakeProjectManager
|
||||
QObject *createCMakeParserTest()
|
||||
{
|
||||
return new CMakeParserTest;
|
||||
}
|
||||
|
||||
} // CMakeProjectManager::Internal
|
||||
|
||||
#endif
|
||||
|
||||
#include "cmakeparser.moc"
|
||||
|
@@ -53,4 +53,8 @@ private:
|
||||
CallStackLine m_errorOrWarningLine;
|
||||
};
|
||||
|
||||
#ifdef WITH_TESTS
|
||||
namespace Internal { QObject *createCMakeParserTest(); }
|
||||
#endif
|
||||
|
||||
} // CMakeProjectManager
|
||||
|
@@ -1103,14 +1103,23 @@ void CMakeProjectImporter::persistTemporaryCMake(Kit *k, const QVariantList &vl)
|
||||
|
||||
#ifdef WITH_TESTS
|
||||
|
||||
#include "cmakeprojectplugin.h"
|
||||
|
||||
#include <QTest>
|
||||
|
||||
namespace CMakeProjectManager {
|
||||
namespace Internal {
|
||||
namespace CMakeProjectManager::Internal {
|
||||
|
||||
void CMakeProjectPlugin::testCMakeProjectImporterQt_data()
|
||||
class CMakeProjectImporterTest final : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void testCMakeProjectImporterQt_data();
|
||||
void testCMakeProjectImporterQt();
|
||||
|
||||
void testCMakeProjectImporterToolchain_data();
|
||||
void testCMakeProjectImporterToolchain();
|
||||
};
|
||||
|
||||
void CMakeProjectImporterTest::testCMakeProjectImporterQt_data()
|
||||
{
|
||||
QTest::addColumn<QStringList>("cache");
|
||||
QTest::addColumn<QString>("expectedQmake");
|
||||
@@ -1125,7 +1134,7 @@ void CMakeProjectPlugin::testCMakeProjectImporterQt_data()
|
||||
// Everything else will require Qt installations!
|
||||
}
|
||||
|
||||
void CMakeProjectPlugin::testCMakeProjectImporterQt()
|
||||
void CMakeProjectImporterTest::testCMakeProjectImporterQt()
|
||||
{
|
||||
QFETCH(QStringList, cache);
|
||||
QFETCH(QString, expectedQmake);
|
||||
@@ -1143,7 +1152,7 @@ void CMakeProjectPlugin::testCMakeProjectImporterQt()
|
||||
Environment::systemEnvironment());
|
||||
QCOMPARE(realQmake.path(), expectedQmake);
|
||||
}
|
||||
void CMakeProjectPlugin::testCMakeProjectImporterToolchain_data()
|
||||
void CMakeProjectImporterTest::testCMakeProjectImporterToolchain_data()
|
||||
{
|
||||
QTest::addColumn<QStringList>("cache");
|
||||
QTest::addColumn<QByteArrayList>("expectedLanguages");
|
||||
@@ -1180,7 +1189,7 @@ void CMakeProjectPlugin::testCMakeProjectImporterToolchain_data()
|
||||
<< QStringList({"/usr/bin/g++", "/usr/bin/clang", "/tmp/strange/compiler"});
|
||||
}
|
||||
|
||||
void CMakeProjectPlugin::testCMakeProjectImporterToolchain()
|
||||
void CMakeProjectImporterTest::testCMakeProjectImporterToolchain()
|
||||
{
|
||||
QFETCH(QStringList, cache);
|
||||
QFETCH(QByteArrayList, expectedLanguages);
|
||||
@@ -1205,7 +1214,13 @@ void CMakeProjectPlugin::testCMakeProjectImporterToolchain()
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace CMakeProjectManager
|
||||
QObject *createCMakeProjectImporterTest()
|
||||
{
|
||||
return new CMakeProjectImporterTest;
|
||||
}
|
||||
|
||||
} // CMakeProjectManager::Internal
|
||||
|
||||
#endif
|
||||
|
||||
#include "cmakeprojectimporter.moc"
|
||||
|
@@ -3,8 +3,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "presetsparser.h"
|
||||
|
||||
#include <qtsupport/qtprojectimporter.h>
|
||||
|
||||
#include <utils/temporarydirectory.h>
|
||||
@@ -51,5 +49,9 @@ private:
|
||||
Utils::TemporaryDirectory m_presetsTempDir;
|
||||
};
|
||||
|
||||
#ifdef WITH_TESTS
|
||||
QObject *createCMakeProjectImporterTest();
|
||||
#endif
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace CMakeProjectManager
|
||||
|
@@ -56,7 +56,6 @@ QtcPlugin {
|
||||
"cmakeprojectnodes.cpp",
|
||||
"cmakeprojectnodes.h",
|
||||
"cmakeprojectplugin.cpp",
|
||||
"cmakeprojectplugin.h",
|
||||
"cmaketool.cpp",
|
||||
"cmaketool.h",
|
||||
"cmaketoolmanager.cpp",
|
||||
|
@@ -1,8 +1,6 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include "cmakeprojectplugin.h"
|
||||
|
||||
#include "cmakebuildconfiguration.h"
|
||||
#include "cmakebuildstep.h"
|
||||
#include "cmakebuildsystem.h"
|
||||
@@ -10,8 +8,10 @@
|
||||
#include "cmakeformatter.h"
|
||||
#include "cmakeinstallstep.h"
|
||||
#include "cmakelocatorfilter.h"
|
||||
#include "cmakeparser.h"
|
||||
#include "cmakeproject.h"
|
||||
#include "cmakeprojectconstants.h"
|
||||
#include "cmakeprojectimporter.h"
|
||||
#include "cmakeprojectmanager.h"
|
||||
#include "cmakeprojectmanagertr.h"
|
||||
#include "cmakeprojectnodes.h"
|
||||
@@ -21,6 +21,8 @@
|
||||
#include <coreplugin/actionmanager/actioncontainer.h>
|
||||
#include <coreplugin/actionmanager/actionmanager.h>
|
||||
|
||||
#include <extensionsystem/iplugin.h>
|
||||
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
#include <projectexplorer/projectmanager.h>
|
||||
#include <projectexplorer/projecttree.h>
|
||||
@@ -66,64 +68,79 @@ public:
|
||||
CMakeFormatter cmakeFormatter;
|
||||
};
|
||||
|
||||
CMakeProjectPlugin::~CMakeProjectPlugin()
|
||||
class CMakeProjectPlugin final : public ExtensionSystem::IPlugin
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
Q_OBJECT
|
||||
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "CMakeProjectManager.json")
|
||||
|
||||
void CMakeProjectPlugin::initialize()
|
||||
{
|
||||
d = new CMakeProjectPluginPrivate;
|
||||
~CMakeProjectPlugin()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
const Context projectContext{CMakeProjectManager::Constants::CMAKE_PROJECT_ID};
|
||||
void initialize() final
|
||||
{
|
||||
d = new CMakeProjectPluginPrivate;
|
||||
|
||||
FileIconProvider::registerIconOverlayForSuffix(Constants::Icons::FILE_OVERLAY, "cmake");
|
||||
FileIconProvider::registerIconOverlayForFilename(Constants::Icons::FILE_OVERLAY,
|
||||
"CMakeLists.txt");
|
||||
#ifdef WITH_TESTS
|
||||
addTestCreator(createCMakeConfigTest);
|
||||
addTestCreator(createCMakeParserTest);
|
||||
addTestCreator(createCMakeProjectImporterTest);
|
||||
#endif
|
||||
|
||||
TextEditor::SnippetProvider::registerGroup(Constants::CMAKE_SNIPPETS_GROUP_ID,
|
||||
Tr::tr("CMake", "SnippetProvider"));
|
||||
ProjectManager::registerProjectType<CMakeProject>(Utils::Constants::CMAKE_PROJECT_MIMETYPE);
|
||||
const Context projectContext{CMakeProjectManager::Constants::CMAKE_PROJECT_ID};
|
||||
|
||||
//register actions
|
||||
Command *command = ActionManager::registerAction(&d->buildTargetContextAction,
|
||||
Constants::BUILD_TARGET_CONTEXT_MENU,
|
||||
projectContext);
|
||||
command->setAttribute(Command::CA_Hide);
|
||||
command->setAttribute(Command::CA_UpdateText);
|
||||
command->setDescription(d->buildTargetContextAction.text());
|
||||
FileIconProvider::registerIconOverlayForSuffix(Constants::Icons::FILE_OVERLAY, "cmake");
|
||||
FileIconProvider::registerIconOverlayForFilename(Constants::Icons::FILE_OVERLAY,
|
||||
"CMakeLists.txt");
|
||||
|
||||
ActionManager::actionContainer(ProjectExplorer::Constants::M_SUBPROJECTCONTEXT)
|
||||
TextEditor::SnippetProvider::registerGroup(Constants::CMAKE_SNIPPETS_GROUP_ID,
|
||||
Tr::tr("CMake", "SnippetProvider"));
|
||||
ProjectManager::registerProjectType<CMakeProject>(Utils::Constants::CMAKE_PROJECT_MIMETYPE);
|
||||
|
||||
//register actions
|
||||
Command *command = ActionManager::registerAction(&d->buildTargetContextAction,
|
||||
Constants::BUILD_TARGET_CONTEXT_MENU,
|
||||
projectContext);
|
||||
command->setAttribute(Command::CA_Hide);
|
||||
command->setAttribute(Command::CA_UpdateText);
|
||||
command->setDescription(d->buildTargetContextAction.text());
|
||||
|
||||
ActionManager::actionContainer(ProjectExplorer::Constants::M_SUBPROJECTCONTEXT)
|
||||
->addAction(command, ProjectExplorer::Constants::G_PROJECT_BUILD);
|
||||
|
||||
// Wire up context menu updates:
|
||||
connect(ProjectTree::instance(), &ProjectTree::currentNodeChanged,
|
||||
this, &CMakeProjectPlugin::updateContextActions);
|
||||
// Wire up context menu updates:
|
||||
connect(ProjectTree::instance(), &ProjectTree::currentNodeChanged,
|
||||
this, &CMakeProjectPlugin::updateContextActions);
|
||||
|
||||
connect(&d->buildTargetContextAction, &ParameterAction::triggered, this, [] {
|
||||
if (auto bs = qobject_cast<CMakeBuildSystem *>(ProjectTree::currentBuildSystem())) {
|
||||
auto targetNode = dynamic_cast<const CMakeTargetNode *>(ProjectTree::currentNode());
|
||||
bs->buildCMakeTarget(targetNode ? targetNode->displayName() : QString());
|
||||
}
|
||||
});
|
||||
}
|
||||
connect(&d->buildTargetContextAction, &ParameterAction::triggered, this, [] {
|
||||
if (auto bs = qobject_cast<CMakeBuildSystem *>(ProjectTree::currentBuildSystem())) {
|
||||
auto targetNode = dynamic_cast<const CMakeTargetNode *>(ProjectTree::currentNode());
|
||||
bs->buildCMakeTarget(targetNode ? targetNode->displayName() : QString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void CMakeProjectPlugin::extensionsInitialized()
|
||||
{
|
||||
// Delay the restoration to allow the devices to load first.
|
||||
QTimer::singleShot(0, this, [] { CMakeToolManager::restoreCMakeTools(); });
|
||||
}
|
||||
void extensionsInitialized() final
|
||||
{
|
||||
// Delay the restoration to allow the devices to load first.
|
||||
QTimer::singleShot(0, this, [] { CMakeToolManager::restoreCMakeTools(); });
|
||||
}
|
||||
|
||||
void CMakeProjectPlugin::updateContextActions(Node *node)
|
||||
{
|
||||
auto targetNode = dynamic_cast<const CMakeTargetNode *>(node);
|
||||
const QString targetDisplayName = targetNode ? targetNode->displayName() : QString();
|
||||
void updateContextActions(ProjectExplorer::Node *node)
|
||||
{
|
||||
auto targetNode = dynamic_cast<const CMakeTargetNode *>(node);
|
||||
const QString targetDisplayName = targetNode ? targetNode->displayName() : QString();
|
||||
|
||||
// Build Target:
|
||||
d->buildTargetContextAction.setParameter(targetDisplayName);
|
||||
d->buildTargetContextAction.setEnabled(targetNode);
|
||||
d->buildTargetContextAction.setVisible(targetNode);
|
||||
}
|
||||
// Build Target:
|
||||
d->buildTargetContextAction.setParameter(targetDisplayName);
|
||||
d->buildTargetContextAction.setEnabled(targetNode);
|
||||
d->buildTargetContextAction.setVisible(targetNode);
|
||||
}
|
||||
|
||||
class CMakeProjectPluginPrivate *d = nullptr;
|
||||
};
|
||||
|
||||
} // CMakeProjectManager::Internal
|
||||
|
||||
#include "cmakeprojectplugin.moc"
|
||||
|
@@ -1,44 +0,0 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <extensionsystem/iplugin.h>
|
||||
|
||||
namespace ProjectExplorer { class Node; }
|
||||
|
||||
namespace CMakeProjectManager::Internal {
|
||||
|
||||
class CMakeProjectPlugin final : public ExtensionSystem::IPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "CMakeProjectManager.json")
|
||||
|
||||
public:
|
||||
~CMakeProjectPlugin();
|
||||
|
||||
#ifdef WITH_TESTS
|
||||
private slots:
|
||||
void testCMakeParser_data();
|
||||
void testCMakeParser();
|
||||
|
||||
void testCMakeSplitValue_data();
|
||||
void testCMakeSplitValue();
|
||||
|
||||
void testCMakeProjectImporterQt_data();
|
||||
void testCMakeProjectImporterQt();
|
||||
|
||||
void testCMakeProjectImporterToolchain_data();
|
||||
void testCMakeProjectImporterToolchain();
|
||||
#endif
|
||||
|
||||
private:
|
||||
void initialize() final;
|
||||
void extensionsInitialized() final;
|
||||
|
||||
void updateContextActions(ProjectExplorer::Node *node);
|
||||
|
||||
class CMakeProjectPluginPrivate *d = nullptr;
|
||||
};
|
||||
|
||||
} // CMakeProjectManager::Internal
|
Reference in New Issue
Block a user