Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Plasma
Plasma Workspace
Commits
3b93044b
Commit
3b93044b
authored
Nov 07, 2020
by
Alexander Lohnau
💬
Browse files
Add tests for all shellrunner features
parent
2452e658
Changes
3
Hide whitespace changes
Inline
Side-by-side
runners/shell/CMakeLists.txt
View file @
3b93044b
...
...
@@ -16,3 +16,7 @@ target_link_libraries(krunner_shell
install
(
TARGETS krunner_shell DESTINATION
"
${
KDE_INSTALL_PLUGINDIR
}
/kf5/krunner"
)
if
(
BUILD_TESTING
)
add_subdirectory
(
autotests
)
endif
()
runners/shell/autotests/CMakeLists.txt
0 → 100644
View file @
3b93044b
include
(
ECMAddTests
)
ecm_add_test
(
shellrunnertest.cpp TEST_NAME shellrunnertest LINK_LIBRARIES Qt5::Test KF5::Runner
)
target_compile_definitions
(
shellrunnertest PUBLIC -DPLUGIN_BUILD_DIR=
"
${
CMAKE_BINARY_DIR
}
/bin"
-DRUNNER_NAME=
"shell"
)
add_dependencies
(
shellrunnertest krunner_shell
)
# Test depends on the plugin being build
runners/shell/autotests/shellrunnertest.cpp
0 → 100644
View file @
3b93044b
#include
<QStandardPaths>
#include
<QTemporaryFile>
#include
<QTest>
#include
<KShell>
#include
<KPluginLoader>
#include
<KPluginMetaData>
#include
<KRunner/RunnerManager>
#include
<QSignalSpy>
using
namespace
Plasma
;
class
ShellRunnerTest
:
public
QObject
{
Q_OBJECT
private:
RunnerManager
*
manager
=
nullptr
;
private
Q_SLOTS
:
void
initTestCase
();
void
testShellrunnerQueries_data
();
void
testShellrunnerQueries
();
};
void
ShellRunnerTest
::
initTestCase
()
{
QStandardPaths
::
setTestModeEnabled
(
true
);
setlocale
(
LC_ALL
,
"C.utf8"
);
auto
pluginMetaDatas
=
KPluginLoader
::
findPluginsById
(
QStringLiteral
(
PLUGIN_BUILD_DIR
),
QStringLiteral
(
RUNNER_NAME
));
QCOMPARE
(
pluginMetaDatas
.
count
(),
1
);
KPluginMetaData
runnerMetadata
=
pluginMetaDatas
.
first
();
delete
manager
;
manager
=
new
RunnerManager
();
manager
->
setAllowedRunners
({
QStringLiteral
(
RUNNER_NAME
)});
manager
->
loadRunner
(
runnerMetadata
);
QCOMPARE
(
manager
->
runners
().
count
(),
1
);
}
void
ShellRunnerTest
::
testShellrunnerQueries
()
{
QFETCH
(
int
,
matchCount
);
QFETCH
(
QString
,
query
);
QFETCH
(
QString
,
expectedCommand
);
QFETCH
(
QStringList
,
expectedENVs
);
QSignalSpy
spy
(
manager
,
&
RunnerManager
::
queryFinished
);
manager
->
launchQuery
(
query
);
QVERIFY
(
spy
.
wait
());
QCOMPARE
(
manager
->
matches
().
count
(),
matchCount
);
if
(
matchCount
==
1
)
{
const
QVariantList
matchData
=
manager
->
matches
().
constFirst
().
data
().
toList
();
QCOMPARE
(
matchData
.
first
().
toString
(),
expectedCommand
);
QCOMPARE
(
matchData
.
at
(
1
).
toStringList
(),
expectedENVs
);
}
}
void
ShellRunnerTest
::
testShellrunnerQueries_data
()
{
QTest
::
addColumn
<
int
>
(
"matchCount"
);
QTest
::
addColumn
<
QString
>
(
"query"
);
QTest
::
addColumn
<
QString
>
(
"expectedCommand"
);
QTest
::
addColumn
<
QStringList
>
(
"expectedENVs"
);
QTest
::
newRow
(
"Should show result with full executable path"
)
<<
1
<<
"/bin/true"
<<
"/bin/true"
<<
QStringList
{};
QTest
::
newRow
(
"Should show result with full executable path and args"
)
<<
1
<<
"/bin/true --help"
<<
"/bin/true --help"
<<
QStringList
{};
QTest
::
newRow
(
"Should bot show result for non-existent path"
)
<<
0
<<
"/bin/trueeeeeee"
<<
QString
()
<<
QStringList
{};
QTest
::
newRow
(
"Should show result for executable name"
)
<<
1
<<
"true"
<<
"true"
<<
QStringList
{};
QTest
::
newRow
(
"Should show result for executable name and args"
)
<<
1
<<
"true --help"
<<
"true --help"
<<
QStringList
{};
QTest
::
newRow
(
"Should show result for executable and ENV variables"
)
<<
1
<<
"LC_ALL=C true"
<<
"true"
<<
QStringList
{
"LC_ALL=C"
};
QTest
::
newRow
(
"Should show result for executable + args and ENV variables"
)
<<
1
<<
"LC_ALL=C true --help"
<<
"true --help"
<<
QStringList
{
"LC_ALL=C"
};
QTest
::
newRow
(
"Should show result for executable and multiple ENV variables"
)
<<
1
<<
"LC_ALL=C TEST=1 true"
<<
"true"
<<
QStringList
{
"LC_ALL=C"
,
"TEST=1"
};
QTest
::
newRow
(
"Should show no result for non-existent executable path and ENV variable"
)
<<
0
<<
"LC_ALL=C /bin/trueeeeeeeeeeee"
<<
""
<<
QStringList
{};
// Some file we can access with a ~
const
QString
tmpPath
=
QStandardPaths
::
writableLocation
(
QStandardPaths
::
AppDataLocation
);
QDir
(
tmpPath
).
mkpath
(
"."
);
QFile
testFile
(
tmpPath
+
"/test.sh"
);
testFile
.
open
(
QIODevice
::
WriteOnly
);
testFile
.
setPermissions
(
QFile
::
ExeOwner
);
const
QString
absoluteFilePath
=
testFile
.
fileName
();
const
QString
tildePath
=
KShell
::
tildeCollapse
(
absoluteFilePath
);
QTest
::
newRow
(
"Should show result for full path with tilde"
)
<<
1
<<
tildePath
<<
tildePath
<<
QStringList
{};
QTest
::
newRow
(
"Should show result for full path with tilde and envs"
)
<<
1
<<
"LC_ALL=C "
+
tildePath
<<
KShell
::
quoteArg
(
tildePath
)
<<
QStringList
{
"LC_ALL=C"
};
QTest
::
newRow
(
"Should show result for full path with tilde + args and envs"
)
<<
1
<<
"LC_ALL=C "
+
tildePath
+
" --help"
<<
KShell
::
quoteArg
(
tildePath
)
+
" --help"
<<
QStringList
{
"LC_ALL=C"
};
}
QTEST_MAIN
(
ShellRunnerTest
)
#include
"shellrunnertest.moc"
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment