From 8aa33a3d134c97d27f1d5466f55f1cef7ffc8013 Mon Sep 17 00:00:00 2001 From: Kurt Hindenburg Date: Mon, 1 Jul 2019 19:00:33 -0400 Subject: [PATCH] Try to use the build konsolepart for tests. Move the build directory to the beginning of libraryPaths() so that the build konsolepart is used. The CI installs and then runs tests, so leave other paths as-is. Also, fail instead of skipping if konsolepart is not found. --- src/autotests/PartTest.cpp | 28 ++++++++++++++++++++++++---- src/autotests/PartTest.h | 1 + 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/autotests/PartTest.cpp b/src/autotests/PartTest.cpp index 2aa77161..2c84c86c 100644 --- a/src/autotests/PartTest.cpp +++ b/src/autotests/PartTest.cpp @@ -40,6 +40,24 @@ using namespace Konsole; +void PartTest::initTestCase() +{ + /* Try to test against build konsolepart, so move directory containing + executable to front of libraryPaths. KPluginLoader should find the + part first in the build dir over the system installed ones. + I believe the CI installs first and then runs the test so the other + paths can not be removed. + */ + const auto libraryPaths = QCoreApplication::libraryPaths(); + auto buildPath = libraryPaths.last(); + QCoreApplication::removeLibraryPath(buildPath); + // konsolepart.so is in ../autotests/ + if (buildPath.endsWith(QStringLiteral("/autotests"))) { + buildPath.chop(10); + } + QCoreApplication::addLibraryPath(buildPath); +} + void PartTest::testFd() { // find ping @@ -62,7 +80,7 @@ void PartTest::testFd() // create a Konsole part and attempt to connect to it KParts::Part *terminalPart = createPart(); if (terminalPart == nullptr) { // not found - QSKIP("konsolepart not found."); + QFAIL("konsolepart not found."); return; } @@ -97,13 +115,15 @@ void PartTest::testFd() ptyProcess.waitForFinished(1000); } + KParts::Part *PartTest::createPart() { - KService::Ptr service = KService::serviceByDesktopName(QStringLiteral("konsolepart")); - if (!service) { // not found + auto konsolePartPlugin = KPluginLoader::findPlugin(QStringLiteral("konsolepart")); + if (konsolePartPlugin.isNull()) { return nullptr; } - KPluginFactory *factory = KPluginLoader(service->library()).factory(); + + KPluginFactory *factory = KPluginLoader(konsolePartPlugin).factory(); if (factory == nullptr) { // not found return nullptr; } diff --git a/src/autotests/PartTest.h b/src/autotests/PartTest.h index acd1a02b..fc3808a8 100644 --- a/src/autotests/PartTest.h +++ b/src/autotests/PartTest.h @@ -33,6 +33,7 @@ class PartTest : public QObject Q_OBJECT private Q_SLOTS: + void initTestCase(); void testFd(); private: