From 14afd237f083257997ad7412307413a1243b821c Mon Sep 17 00:00:00 2001 From: Alexander Lohnau Date: Fri, 24 Dec 2021 13:37:08 +0100 Subject: [PATCH] shellrunner: Port to KRunner test utils This fixes the unit test, because the file location is not hardcoded anymore. --- runners/shell/autotests/CMakeLists.txt | 3 +-- runners/shell/autotests/shellrunnertest.cpp | 27 ++++++--------------- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/runners/shell/autotests/CMakeLists.txt b/runners/shell/autotests/CMakeLists.txt index 7e4993e01..8385c18b6 100644 --- a/runners/shell/autotests/CMakeLists.txt +++ b/runners/shell/autotests/CMakeLists.txt @@ -3,5 +3,4 @@ include(ECMAddTests) ecm_add_test(shellrunnertest.cpp TEST_NAME shellrunnertest LINK_LIBRARIES Qt::Test KF5::Runner) -target_compile_definitions(shellrunnertest PUBLIC -DPLUGIN_BUILD_DIR="${CMAKE_BINARY_DIR}/bin/kf5/krunner/" -DRUNNER_NAME="shell") -add_dependencies(shellrunnertest krunner_shell) # Test depends on the plugin being build +configure_krunner_test(shellrunnertest krunner_shell) diff --git a/runners/shell/autotests/shellrunnertest.cpp b/runners/shell/autotests/shellrunnertest.cpp index a5a75e5d2..b550863c2 100644 --- a/runners/shell/autotests/shellrunnertest.cpp +++ b/runners/shell/autotests/shellrunnertest.cpp @@ -3,27 +3,27 @@ SPDX-FileCopyrightText: 2021 Alexander Lohnau */ +// See https://phabricator.kde.org/T14499, this plugin's id should be renamed +#undef KRUNNER_TEST_RUNNER_PLUGIN_NAME +#define KRUNNER_TEST_RUNNER_PLUGIN_NAME "shell" + #include #include #include #include -#include +#include #include #include #include #include -using namespace Plasma; - -class ShellRunnerTest : public QObject +class ShellRunnerTest : public AbstractRunnerTest { Q_OBJECT private: - RunnerManager *manager = nullptr; - QFileInfo createExecutableFile(const QString &fileName); private Q_SLOTS: @@ -34,16 +34,7 @@ private Q_SLOTS: void ShellRunnerTest::initTestCase() { - QStandardPaths::setTestModeEnabled(true); - setlocale(LC_ALL, "C.utf8"); - - const KPluginMetaData runnerMetadata = KPluginMetaData::findPluginById(QStringLiteral(PLUGIN_BUILD_DIR), QStringLiteral(RUNNER_NAME)); - QVERIFY(runnerMetadata.isValid()); - delete manager; - manager = new RunnerManager(); - manager->setAllowedRunners({QStringLiteral(RUNNER_NAME)}); - manager->loadRunner(runnerMetadata); - QCOMPARE(manager->runners().count(), 1); + initProperties(); } void ShellRunnerTest::testShellrunnerQueries() @@ -53,9 +44,7 @@ void ShellRunnerTest::testShellrunnerQueries() QFETCH(QString, expectedCommand); QFETCH(QStringList, expectedENVs); - QSignalSpy spy(manager, &RunnerManager::queryFinished); - manager->launchQuery(query); - QVERIFY(spy.wait()); + launchQuery(query); QCOMPARE(manager->matches().count(), matchCount); if (matchCount == 1) { const QVariantList matchData = manager->matches().constFirst().data().toList();