Commit c7488f8a authored by Ralf Habacker's avatar Ralf Habacker
Browse files

Embed KDev::Tests library to not depend on kdevplatform for KF5 builds

The KDevelopUtils::DebugLanguageParserHelper class provided by kdevplatform
depends on KDev::Tests, which is not exported by default (it requires the
BUILDING_TESTS setting), which means we must provide KDev::Tests locally.

CCBUG:415849
parent 57df796d
......@@ -67,7 +67,7 @@ else()
set(QT_MIN_VERSION "5.2.0")
set(KDEV_MIN_VERSION 5.1.2)
set(KDEV_SOURCE_DIR lib/kdev5-php)
set(KDEV_COMPONENTS KDev::Interfaces KDev::Language KDev::Tests)
set(KDEV_COMPONENTS KDev::Interfaces KDev::Language KDev::Shell)
endif()
# search packages used by Qt
......@@ -103,11 +103,9 @@ find_package(KF5 REQUIRED COMPONENTS
if(BUILD_PHP_IMPORT)
find_package(KDevelop-PG-Qt)
find_package(KDevPlatform ${KDEV_MIN_VERSION} COMPONENTS ${KDEV_COMPONENTS})
endif()
if(BUILD_KF5 AND NOT TARGET KDev::Tests)
message(STATUS "Could not find required KDevPlatform component KDev::Tests - disabling php import support")
set(KDEVPLATFORM_FOUND 0)
set(BUILD_PHP_IMPORT 0)
if(BUILD_KF5)
add_subdirectory(lib/kdevplatform)
endif()
endif()
if(KDEVPGQT_FOUND AND KDEVPLATFORM_FOUND)
message(STATUS "requirements available - enable building php code import")
......
......@@ -60,6 +60,7 @@ kdevplatform_add_plugin(kdevphplanguagesupport JSON kdevphpsupport.json
target_link_libraries(kdevphplanguagesupport
KDev::Interfaces
KDev::Language
KDev::Tests
kdevphpduchain
kdevphpparser
kdevphpcompletion
......
add_library(KDevTests STATIC tests/testcore.cpp tests/autotestshell.cpp)
target_include_directories(KDevTests PUBLIC tests)
target_link_libraries(KDevTests
PUBLIC
KDev::Shell
#KDev::Language
#KDev::Project
#KDev::Debugger
PRIVATE
Qt5::Test
)
add_library(KDev::Tests ALIAS KDevTests)
/***************************************************************************
* Copyright 2008 Andreas Pakulat <apaku@gmx.de> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Library General Public License as *
* published by the Free Software Foundation; either version 2 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#ifndef KDEVPLATFORM_PLATFORM_CORE_P_H
#define KDEVPLATFORM_PLATFORM_CORE_P_H
#include <shell/core.h>
#include <KAboutData>
#include <QPointer>
namespace KDevelop
{
class RunController;
class PartController;
class LanguageController;
class DocumentController;
class ProjectController;
class PluginController;
class UiController;
class SessionController;
class SourceFormatterController;
class ProgressManager;
class SelectionController;
class DocumentationController;
class DebugController;
class WorkingSetController;
class TestController;
class RuntimeController;
class KDEVPLATFORMSHELL_EXPORT CorePrivate {
public:
explicit CorePrivate(Core *core);
~CorePrivate();
bool initialize( Core::Setup mode, const QString& session );
QPointer<PluginController> pluginController;
QPointer<UiController> uiController;
QPointer<ProjectController> projectController;
QPointer<LanguageController> languageController;
QPointer<PartController> partController;
QPointer<DocumentController> documentController;
QPointer<RunController> runController;
QPointer<SessionController> sessionController;
QPointer<SourceFormatterController> sourceFormatterController;
QPointer<ProgressManager> progressController;
QPointer<SelectionController> selectionController;
QPointer<DocumentationController> documentationController;
QPointer<DebugController> debugController;
QPointer<WorkingSetController> workingSetController;
QPointer<TestController> testController;
QPointer<RuntimeController> runtimeController;
const KAboutData m_aboutData;
Core* const m_core;
bool m_cleanedUp;
bool m_shuttingDown;
Core::Setup m_mode;
};
}
#endif
/***************************************************************************
* Copyright 2013 Kevin Funk <kfunk@kde.org *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Library General Public License as *
* published by the Free Software Foundation; either version 2 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#include "autotestshell.h"
KDevelop::AutoTestShell::AutoTestShell(const QStringList& plugins)
: m_plugins(plugins)
{
}
void KDevelop::AutoTestShell::init(const QStringList& plugins)
{
// TODO: Maybe generalize, add KDEVELOP_STANDALONE build option
#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
qputenv("KDE_FORK_SLAVES", "1"); // KIO slaves will be forked off instead of being started via DBus
#endif
qputenv("CLEAR_DUCHAIN_DIR", "1"); // Always clear duchain dir (also to avoid popups asking the user to clear it)
s_instance = new AutoTestShell(plugins);
}
/***************************************************************************
* Copyright 2008 Harald Fernengel <harry@kdevelop.org> *
* Copyright 2013 Milian Wolff <mail@milianw.de> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Library General Public License as *
* published by the Free Software Foundation; either version 2 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#ifndef KDEVPLATFORM_AUTOTESTSHELL_H
#define KDEVPLATFORM_AUTOTESTSHELL_H
#include <QStringList>
#include "testsexport.h"
#include <shell/shellextension.h>
#include <shell/core.h>
/* This is a dummy shell for unit tests. It basically does nothing :)
You can initialize it in initTestCase() to get a minimal shell to run
your autotests.
Example of a minimal KDevPlatform unit test:
void Mytest::initTestCase()
{
AutoTestShell::init();
TestCore::initialize();
}
*/
namespace KDevelop {
class KDEVPLATFORMTESTS_EXPORT AutoTestShell
: public KDevelop::ShellExtension
{
public:
explicit AutoTestShell(const QStringList& plugins);
QString xmlFile() override { return QString(); }
QString executableFilePath() override { return QString(); };
QString defaultProfile() { return QStringLiteral("kdevtest"); }
KDevelop::AreaParams defaultArea() override
{
KDevelop::AreaParams params;
params.name = QStringLiteral("test");
params.title = QStringLiteral("Test");
return params;
}
QString projectFileExtension() override { return QString(); }
QString projectFileDescription() override { return QString(); }
QStringList defaultPlugins() override { return m_plugins; }
/**
* Initialize the AutoTestShell and set the global instance.
*
* @p plugins A list of default global plugins which should be loaded.
* By default, all global plugins are loaded.
*/
static void init(const QStringList& plugins = QStringList());
private:
QStringList m_plugins;
};
}
#endif
/***************************************************************************
* Copyright 2008 Andreas Pakulat <apaku@gmx.de> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Library General Public License as *
* published by the Free Software Foundation; either version 2 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#include "testcore.h"
#include <shell/uicontroller.h>
#include <shell/sessioncontroller.h>
#include <shell/languagecontroller.h>
#include <shell/runcontroller.h>
#include <shell/documentcontroller.h>
#include <shell/plugincontroller.h>
#include <shell/partcontroller.h>
#include <shell/projectcontroller.h>
#include <language/backgroundparser/backgroundparser.h>
#include <interfaces/isession.h>
#include "../shell/core_p.h"
#include <QCoreApplication>
#include <QTest>
#include <KParts/MainWindow>
namespace KDevelop {
TestCore::TestCore()
: Core(new CorePrivate(this))
{
Core::m_self = this;
}
TestCore* TestCore::initialize(Core::Setup mode, const QString& session)
{
qRegisterMetaType<QList<QUrl>>("QList<QUrl>");
if (!Core::m_self) {
new TestCore;
}
auto* core = qobject_cast<TestCore*>(Core::m_self);
Q_ASSERT(core);
core->initializeNonStatic(mode, session);
if (mode == Default) {
// we don't want the window to be visible, hide it
// the unit tests should work anyways
core->uiController()->activeMainWindow()->hide();
}
// resume the background parser when a unit test replaces the project controller
QObject::connect(core->d->projectController.data(), &ProjectController::destroyed,
core, [core]() {
core->d->languageController->backgroundParser()->resume();
});
return core;
}
void TestCore::initializeNonStatic(Core::Setup mode, const QString& _session)
{
QString session = _session;
if (_session.isEmpty()) {
// use a distinct session name for unit test sessions
// they are temporary (see below) but still - we want to make sure
session = QLatin1String("test-") + qApp->applicationName();
}
d->initialize(mode, session);
if (_session.isEmpty()) {
activeSession()->setTemporary(true);
}
}
void TestCore::shutdown()
{
if (self()) {
// trigger eventloop to handle Queued connections
// before entering cleanup
// this can fix random crashes under certain conditions
QTest::qWait(1);
self()->shutdown();
// wait until Core is deleted via event loop
QTest::qWait(1);
}
}
void TestCore::setShuttingDown(bool shuttingDown)
{
d->m_shuttingDown = shuttingDown;
}
void TestCore::setSessionController(SessionController* ctrl)
{
d->sessionController = ctrl;
}
void TestCore::setPluginController(PluginController* ctrl)
{
d->pluginController = ctrl;
}
void TestCore::setRunController(RunController* ctrl)
{
d->runController = ctrl;
}
void TestCore::setDocumentController(DocumentController* ctrl)
{
d->documentController = ctrl;
}
void TestCore::setPartController(PartController* ctrl)
{
d->partController = ctrl;
}
void TestCore::setProjectController(ProjectController* ctrl)
{
d->projectController = ctrl;
}
void TestCore::setLanguageController(LanguageController* ctrl)
{
d->languageController = ctrl;
}
void TestCore::setUiController(UiController* ctrl)
{
d->uiController = ctrl;
}
}
/***************************************************************************
* Copyright 2008 Andreas Pakulat <apaku@gmx.de> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Library General Public License as *
* published by the Free Software Foundation; either version 2 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#ifndef KDEVPLATFORM_KDEVPLATFORMTESTCORE_H
#define KDEVPLATFORM_KDEVPLATFORMTESTCORE_H
#include "testsexport.h"
#include <shell/core.h>
namespace KDevelop {
class SessionController;
class RunController;
class PluginController;
class DocumentController;
class PartController;
class ProjectController;
class UiController;
/**
* \class TestCore testcore.h
*
* This is an ICore implementation which should be used inside unit tests.
* By default a temporary session named after currently running application
* will be instantiated. Furthermore the mainwindow - if created - will be
* hidden as no user interaction should take place in a unit test.
*
* The simplest code which should suffice for most use cases is:
*
* \code
* MyUnitTest::initTestCase() {
* AutoTestShell::init()
* TestCore::initialize();
* }
* MyUnitTest::cleanupTestCase() {
* TestCore::shutdown();
* }
* \endcode
*
* This class also allows one to replace certain or all parts of the
* shell library with custom implementation to make it possible
* to write plugin tests more easily.
*
* The usage is then as follows:
* \code
* TestCore* core = new TestCore();
* //replace plugin controller or similar
* core->setPluginController( new MyCustomPluginController( core ) );
* //initialize
* core->initialize(Core::Default);
* ... //test code
* // if you want to cleanup manually:
* core->cleanup();
* delete core;
* \endcode
*
* @note It is important to call initialize and cleanup, else the controllers
* won't work properly.
*/
class KDEVPLATFORMTESTS_EXPORT TestCore
: public Core
{
Q_OBJECT
public:
TestCore();
/**
* Initialize the test core with the given setup @p mode.
* Optionally launch with a user given session.
*
* @p mode Use @c Core::NoUi when your unit test does not require any UI
* NOTE: Even in @c Default mode the mainwindow will be hidden,
* as unit tests should not depend on user interaction.
* @p session By default a temporary session will be created called "test-%appname".
* If @p session is not empty, a non-temporary session with the given name
* will be opened.
* @return the initialized test core
*/
static TestCore* initialize(Core::Setup mode = Core::Default, const QString& session = {});
/**
* Calls @c cleanup() on the current TestCore instance,
* then deletes the core.
*
* @NOTE: It is important to call this in e.g. @c cleanupTestSuite()
* otherwise the core will be leaked, no proper cleanup will take place
* and e.g. temporary sessions not properly deleted.
*/
static void shutdown();
/**
* Fakes a shutdown without actually doing the shutdown.
*/
void setShuttingDown(bool shuttingDown);
void setSessionController(SessionController*);
void setPluginController(PluginController*);
void setRunController(RunController*);
void setDocumentController(DocumentController*);
void setPartController(PartController*);
void setProjectController(ProjectController*);
void setLanguageController(LanguageController*);
void setUiController(UiController*);
private:
void initializeNonStatic(Core::Setup mode, const QString& session);
};
}
#endif
#ifndef TESTSEXPORT_H
#define TESTSEXPORT_H
#define KDEVPLATFORMTESTS_EXPORT
#endif // TESTSEXPORT_H
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment