diff --git a/src/libs/utils/deviceshell.cpp b/src/libs/utils/deviceshell.cpp index bfa33418a3d..8daf147ea54 100644 --- a/src/libs/utils/deviceshell.cpp +++ b/src/libs/utils/deviceshell.cpp @@ -151,7 +151,8 @@ done) > $FINAL_OUT } // namespace -DeviceShell::DeviceShell() +DeviceShell::DeviceShell(bool forceFailScriptInstallation) +: m_forceFailScriptInstallation(forceFailScriptInstallation) { m_thread.setObjectName("DeviceShell"); m_thread.start(); @@ -389,6 +390,11 @@ bool DeviceShell::checkCommand(const QByteArray &command) bool DeviceShell::installShellScript() { + if (m_forceFailScriptInstallation) { + m_shellScriptState = State::NoScript; + return false; + } + if (!checkCommand("base64")) { m_shellScriptState = State::NoScript; return false; diff --git a/src/libs/utils/deviceshell.h b/src/libs/utils/deviceshell.h index 1c780997706..e9382bc885b 100644 --- a/src/libs/utils/deviceshell.h +++ b/src/libs/utils/deviceshell.h @@ -41,7 +41,7 @@ public: ExitCode, }; - DeviceShell(); + DeviceShell(bool forceFailScriptInstallation = false); virtual ~DeviceShell(); bool start(); @@ -90,6 +90,9 @@ private: State m_shellScriptState = State::Unknown; QStringList m_missingFeatures; + + // Only used for tests + bool m_forceFailScriptInstallation = false; }; } // namespace Utils diff --git a/tests/auto/utils/deviceshell/tst_deviceshell.cpp b/tests/auto/utils/deviceshell/tst_deviceshell.cpp index 13ae1d13557..5d550b2afa0 100644 --- a/tests/auto/utils/deviceshell/tst_deviceshell.cpp +++ b/tests/auto/utils/deviceshell/tst_deviceshell.cpp @@ -20,8 +20,9 @@ using namespace Utils; class TestShell : public DeviceShell { public: - TestShell(CommandLine cmdLine) - : m_cmdLine(std::move(cmdLine)) + TestShell(CommandLine cmdLine, bool failScript = false) + : DeviceShell(failScript) + , m_cmdLine(std::move(cmdLine)) { start(); } @@ -340,6 +341,25 @@ private slots: QVERIFY (!Utils::anyOf(results, [&results](const QByteArray r){ return r != results[0]; })); } + + void testNoScript_data() + { + QTest::addColumn("cmdLine"); + for (const auto &cmdLine : m_availableShells) { + QTest::newRow(cmdLine.executable().baseName().toUtf8()) << cmdLine; + } + } + + void testNoScript() + { + QFETCH(CommandLine, cmdLine); + + TestShell shell(cmdLine, true); + QCOMPARE(shell.state(), DeviceShell::State::NoScript); + + const bool result = shell.runInShell({"echo", {"Hello"}}); + QCOMPARE(result, true); + } }; QTEST_GUILESS_MAIN(tst_DeviceShell)