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:
hjk
2024-01-12 12:52:29 +01:00
parent e0dae4d0b3
commit 446d79ad67
10 changed files with 144 additions and 119 deletions

View File

@@ -29,7 +29,7 @@ add_qtc_plugin(CMakeProjectManager
cmakeprojectmanager.cpp cmakeprojectmanager.h cmakeprojectmanager.cpp cmakeprojectmanager.h
cmakeprojectmanagertr.h cmakeprojectmanagertr.h
cmakeprojectnodes.cpp cmakeprojectnodes.h cmakeprojectnodes.cpp cmakeprojectnodes.h
cmakeprojectplugin.cpp cmakeprojectplugin.h cmakeprojectplugin.cpp
cmakesettingspage.cpp cmakesettingspage.h cmakesettingspage.cpp cmakesettingspage.h
cmakespecificsettings.cpp cmakespecificsettings.h cmakespecificsettings.cpp cmakespecificsettings.h
cmaketool.cpp cmaketool.h cmaketool.cpp cmaketool.h

View File

@@ -472,18 +472,24 @@ size_t qHash(const CMakeConfigItem &it)
return ::qHash(it.key) ^ ::qHash(it.value) ^ ::qHash(it.isUnset) ^ ::qHash(it.isInitial); return ::qHash(it.key) ^ ::qHash(it.value) ^ ::qHash(it.isUnset) ^ ::qHash(it.isInitial);
} }
#if WITH_TESTS
} // namespace CMakeProjectManager } // namespace CMakeProjectManager
#include "cmakeprojectplugin.h" #if WITH_TESTS
#include <QTest> #include <QTest>
namespace CMakeProjectManager { namespace CMakeProjectManager::Internal {
namespace 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<QString>("input");
QTest::addColumn<bool>("keepEmpty"); QTest::addColumn<bool>("keepEmpty");
@@ -526,7 +532,7 @@ void CMakeProjectPlugin::testCMakeSplitValue_data()
<< "C:/something;;/second/path" << true << QStringList({"C:/something", "", "/second/path"}); << "C:/something;;/second/path" << true << QStringList({"C:/something", "", "/second/path"});
} }
void CMakeProjectPlugin::testCMakeSplitValue() void CMakeConfigTest::testCMakeSplitValue()
{ {
QFETCH(QString, input); QFETCH(QString, input);
QFETCH(bool, keepEmpty); QFETCH(bool, keepEmpty);
@@ -537,7 +543,13 @@ void CMakeProjectPlugin::testCMakeSplitValue()
QCOMPARE(expectedOutput, realOutput); QCOMPARE(expectedOutput, realOutput);
} }
} // namespace Internal QObject *createCMakeConfigTest()
{
return new CMakeConfigTest();
}
} // CMakeProjectManager::Internal
#endif #endif
} // namespace CMakeProjectManager #include "cmakeconfigitem.moc"

View File

@@ -6,6 +6,7 @@
#include "cmake_global.h" #include "cmake_global.h"
#include <QByteArray> #include <QByteArray>
#include <QObject>
#include <QStringList> #include <QStringList>
#include <optional> #include <optional>
@@ -78,4 +79,8 @@ public:
QString expandedValueOf(const ProjectExplorer::Kit *k, const QByteArray &key) const; QString expandedValueOf(const ProjectExplorer::Kit *k, const QByteArray &key) const;
}; };
#ifdef WITH_TESTS
namespace Internal { QObject *createCMakeConfigTest(); }
#endif
} // namespace CMakeProjectManager } // namespace CMakeProjectManager

View File

@@ -248,15 +248,23 @@ void CMakeParser::flush()
} // CMakeProjectManager } // CMakeProjectManager
#ifdef WITH_TESTS #ifdef WITH_TESTS
#include "cmakeprojectplugin.h"
#include <projectexplorer/outputparser_test.h> #include <projectexplorer/outputparser_test.h>
#include <QTest> #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<QString>("input");
QTest::addColumn<OutputParserTester::Channel>("inputChannel"); QTest::addColumn<OutputParserTester::Channel>("inputChannel");
@@ -462,7 +470,7 @@ void Internal::CMakeProjectPlugin::testCMakeParser_data()
<< QString(); << QString();
} }
void Internal::CMakeProjectPlugin::testCMakeParser() void CMakeParserTest::testCMakeParser()
{ {
OutputParserTester testbench; OutputParserTester testbench;
testbench.addLineParser(new CMakeParser); testbench.addLineParser(new CMakeParser);
@@ -478,6 +486,13 @@ void Internal::CMakeProjectPlugin::testCMakeParser()
outputLines); outputLines);
} }
} // CMakeProjectManager QObject *createCMakeParserTest()
{
return new CMakeParserTest;
}
} // CMakeProjectManager::Internal
#endif #endif
#include "cmakeparser.moc"

View File

@@ -53,4 +53,8 @@ private:
CallStackLine m_errorOrWarningLine; CallStackLine m_errorOrWarningLine;
}; };
#ifdef WITH_TESTS
namespace Internal { QObject *createCMakeParserTest(); }
#endif
} // CMakeProjectManager } // CMakeProjectManager

View File

@@ -1103,14 +1103,23 @@ void CMakeProjectImporter::persistTemporaryCMake(Kit *k, const QVariantList &vl)
#ifdef WITH_TESTS #ifdef WITH_TESTS
#include "cmakeprojectplugin.h"
#include <QTest> #include <QTest>
namespace CMakeProjectManager { namespace CMakeProjectManager::Internal {
namespace 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<QStringList>("cache");
QTest::addColumn<QString>("expectedQmake"); QTest::addColumn<QString>("expectedQmake");
@@ -1125,7 +1134,7 @@ void CMakeProjectPlugin::testCMakeProjectImporterQt_data()
// Everything else will require Qt installations! // Everything else will require Qt installations!
} }
void CMakeProjectPlugin::testCMakeProjectImporterQt() void CMakeProjectImporterTest::testCMakeProjectImporterQt()
{ {
QFETCH(QStringList, cache); QFETCH(QStringList, cache);
QFETCH(QString, expectedQmake); QFETCH(QString, expectedQmake);
@@ -1143,7 +1152,7 @@ void CMakeProjectPlugin::testCMakeProjectImporterQt()
Environment::systemEnvironment()); Environment::systemEnvironment());
QCOMPARE(realQmake.path(), expectedQmake); QCOMPARE(realQmake.path(), expectedQmake);
} }
void CMakeProjectPlugin::testCMakeProjectImporterToolchain_data() void CMakeProjectImporterTest::testCMakeProjectImporterToolchain_data()
{ {
QTest::addColumn<QStringList>("cache"); QTest::addColumn<QStringList>("cache");
QTest::addColumn<QByteArrayList>("expectedLanguages"); QTest::addColumn<QByteArrayList>("expectedLanguages");
@@ -1180,7 +1189,7 @@ void CMakeProjectPlugin::testCMakeProjectImporterToolchain_data()
<< QStringList({"/usr/bin/g++", "/usr/bin/clang", "/tmp/strange/compiler"}); << QStringList({"/usr/bin/g++", "/usr/bin/clang", "/tmp/strange/compiler"});
} }
void CMakeProjectPlugin::testCMakeProjectImporterToolchain() void CMakeProjectImporterTest::testCMakeProjectImporterToolchain()
{ {
QFETCH(QStringList, cache); QFETCH(QStringList, cache);
QFETCH(QByteArrayList, expectedLanguages); QFETCH(QByteArrayList, expectedLanguages);
@@ -1205,7 +1214,13 @@ void CMakeProjectPlugin::testCMakeProjectImporterToolchain()
} }
} }
} // namespace Internal QObject *createCMakeProjectImporterTest()
} // namespace CMakeProjectManager {
return new CMakeProjectImporterTest;
}
} // CMakeProjectManager::Internal
#endif #endif
#include "cmakeprojectimporter.moc"

View File

@@ -3,8 +3,6 @@
#pragma once #pragma once
#include "presetsparser.h"
#include <qtsupport/qtprojectimporter.h> #include <qtsupport/qtprojectimporter.h>
#include <utils/temporarydirectory.h> #include <utils/temporarydirectory.h>
@@ -51,5 +49,9 @@ private:
Utils::TemporaryDirectory m_presetsTempDir; Utils::TemporaryDirectory m_presetsTempDir;
}; };
#ifdef WITH_TESTS
QObject *createCMakeProjectImporterTest();
#endif
} // namespace Internal } // namespace Internal
} // namespace CMakeProjectManager } // namespace CMakeProjectManager

View File

@@ -56,7 +56,6 @@ QtcPlugin {
"cmakeprojectnodes.cpp", "cmakeprojectnodes.cpp",
"cmakeprojectnodes.h", "cmakeprojectnodes.h",
"cmakeprojectplugin.cpp", "cmakeprojectplugin.cpp",
"cmakeprojectplugin.h",
"cmaketool.cpp", "cmaketool.cpp",
"cmaketool.h", "cmaketool.h",
"cmaketoolmanager.cpp", "cmaketoolmanager.cpp",

View File

@@ -1,8 +1,6 @@
// Copyright (C) 2016 The Qt Company Ltd. // Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "cmakeprojectplugin.h"
#include "cmakebuildconfiguration.h" #include "cmakebuildconfiguration.h"
#include "cmakebuildstep.h" #include "cmakebuildstep.h"
#include "cmakebuildsystem.h" #include "cmakebuildsystem.h"
@@ -10,8 +8,10 @@
#include "cmakeformatter.h" #include "cmakeformatter.h"
#include "cmakeinstallstep.h" #include "cmakeinstallstep.h"
#include "cmakelocatorfilter.h" #include "cmakelocatorfilter.h"
#include "cmakeparser.h"
#include "cmakeproject.h" #include "cmakeproject.h"
#include "cmakeprojectconstants.h" #include "cmakeprojectconstants.h"
#include "cmakeprojectimporter.h"
#include "cmakeprojectmanager.h" #include "cmakeprojectmanager.h"
#include "cmakeprojectmanagertr.h" #include "cmakeprojectmanagertr.h"
#include "cmakeprojectnodes.h" #include "cmakeprojectnodes.h"
@@ -21,6 +21,8 @@
#include <coreplugin/actionmanager/actioncontainer.h> #include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/actionmanager.h> #include <coreplugin/actionmanager/actionmanager.h>
#include <extensionsystem/iplugin.h>
#include <projectexplorer/projectexplorerconstants.h> #include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/projectmanager.h> #include <projectexplorer/projectmanager.h>
#include <projectexplorer/projecttree.h> #include <projectexplorer/projecttree.h>
@@ -66,15 +68,26 @@ public:
CMakeFormatter cmakeFormatter; CMakeFormatter cmakeFormatter;
}; };
CMakeProjectPlugin::~CMakeProjectPlugin() class CMakeProjectPlugin final : public ExtensionSystem::IPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "CMakeProjectManager.json")
~CMakeProjectPlugin()
{ {
delete d; delete d;
} }
void CMakeProjectPlugin::initialize() void initialize() final
{ {
d = new CMakeProjectPluginPrivate; d = new CMakeProjectPluginPrivate;
#ifdef WITH_TESTS
addTestCreator(createCMakeConfigTest);
addTestCreator(createCMakeParserTest);
addTestCreator(createCMakeProjectImporterTest);
#endif
const Context projectContext{CMakeProjectManager::Constants::CMAKE_PROJECT_ID}; const Context projectContext{CMakeProjectManager::Constants::CMAKE_PROJECT_ID};
FileIconProvider::registerIconOverlayForSuffix(Constants::Icons::FILE_OVERLAY, "cmake"); FileIconProvider::registerIconOverlayForSuffix(Constants::Icons::FILE_OVERLAY, "cmake");
@@ -108,13 +121,13 @@ void CMakeProjectPlugin::initialize()
}); });
} }
void CMakeProjectPlugin::extensionsInitialized() void extensionsInitialized() final
{ {
// Delay the restoration to allow the devices to load first. // Delay the restoration to allow the devices to load first.
QTimer::singleShot(0, this, [] { CMakeToolManager::restoreCMakeTools(); }); QTimer::singleShot(0, this, [] { CMakeToolManager::restoreCMakeTools(); });
} }
void CMakeProjectPlugin::updateContextActions(Node *node) void updateContextActions(ProjectExplorer::Node *node)
{ {
auto targetNode = dynamic_cast<const CMakeTargetNode *>(node); auto targetNode = dynamic_cast<const CMakeTargetNode *>(node);
const QString targetDisplayName = targetNode ? targetNode->displayName() : QString(); const QString targetDisplayName = targetNode ? targetNode->displayName() : QString();
@@ -125,5 +138,9 @@ void CMakeProjectPlugin::updateContextActions(Node *node)
d->buildTargetContextAction.setVisible(targetNode); d->buildTargetContextAction.setVisible(targetNode);
} }
class CMakeProjectPluginPrivate *d = nullptr;
};
} // CMakeProjectManager::Internal } // CMakeProjectManager::Internal
#include "cmakeprojectplugin.moc"

View File

@@ -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