diff options
| -rw-r--r-- | tests/auto/qml/debugger/qmlpreviewtool/tst_qmlpreviewtool.cpp | 46 | ||||
| -rw-r--r-- | tools/qmlpreview/qmlpreviewapplication.cpp | 7 |
2 files changed, 50 insertions, 3 deletions
diff --git a/tests/auto/qml/debugger/qmlpreviewtool/tst_qmlpreviewtool.cpp b/tests/auto/qml/debugger/qmlpreviewtool/tst_qmlpreviewtool.cpp index 1de1271fe0..d1a4416b2e 100644 --- a/tests/auto/qml/debugger/qmlpreviewtool/tst_qmlpreviewtool.cpp +++ b/tests/auto/qml/debugger/qmlpreviewtool/tst_qmlpreviewtool.cpp @@ -35,6 +35,7 @@ private slots: void inputNotReplayedOnHotReload(); void hotReloadFailure(); void interactiveCommands(); + void restartKeepsArguments(); void saveAndReplayRoundTrip(); void classicModeReplaysRecordedInput(); @@ -584,6 +585,51 @@ void tst_QmlPreviewTool::interactiveCommands() QCOMPARE(m_process.exitCode(), 0); } +// Restarting the target must launch it with the same arguments as the first +// time. Before the fix, every (re)start appended another -qmljsdebugger option +// to the stored arguments, so they piled up with each restart. +void tst_QmlPreviewTool::restartKeepsArguments() +{ + m_tempDir = std::make_unique<QTemporaryDir>(); + QVERIFY(m_tempDir->isValid()); + + const QString qmlFile = m_tempDir->filePath(QLatin1String("test.qml")); + QVERIFY(writeFile(qmlFile, makeQmlContent(QLatin1String("RESTART_OK")))); + + startPreview({ QLatin1String("--interactive"), QLatin1String("--verbose"), m_qmlRuntimePath, + qmlFile }); + QVERIFY2(waitForOutput(QLatin1String("RESTART_OK")), + qPrintable(QLatin1String("Initial load failed. Output:\n") + m_output)); + + const QLatin1String starting("Starting '"); + for (int restarts = 1; restarts <= 2; ++restarts) { + sendCommand(QLatin1String("restart")); + + // Wait for the restarted target to be up, so that the next restart + // doesn't overtake this one. + const bool restarted = QTest::qWaitFor([this, &starting, restarts]() { + readProcessOutput(); + if (m_output.count(starting) != restarts + 1) + return false; + return m_output.indexOf(QLatin1String("RESTART_OK"), m_output.lastIndexOf(starting)) + != -1; + }, 30000); + QVERIFY2(restarted, + qPrintable(QLatin1String("Target was not restarted. Output:\n") + m_output)); + } + + const QStringList lines = m_output.split(QLatin1Char('\n')); + qsizetype launches = 0; + for (const QString &line : lines) { + if (!line.startsWith(starting)) + continue; + ++launches; + QVERIFY2(line.contains(qmlFile), qPrintable(line)); + QCOMPARE(line.count(QLatin1String("-qmljsdebugger=")), 1); + } + QCOMPARE(launches, 3); +} + // End-to-end round trip: record the input event stream of one session to a .qtd // file, then load it in the next session and replay it to restore the UI state. void tst_QmlPreviewTool::saveAndReplayRoundTrip() diff --git a/tools/qmlpreview/qmlpreviewapplication.cpp b/tools/qmlpreview/qmlpreviewapplication.cpp index de21066a9e..6e327dc589 100644 --- a/tools/qmlpreview/qmlpreviewapplication.cpp +++ b/tools/qmlpreview/qmlpreviewapplication.cpp @@ -401,10 +401,11 @@ void QmlPreviewApplication::startProcess() this, &QmlPreviewApplication::processHasOutput); connect(m_process.data(), QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), this, [this](int){ processFinished(); }); - m_arguments.append(makeQmlPreviewArgument(m_socketFile)); + QStringList arguments = m_arguments; + arguments.append(makeQmlPreviewArgument(m_socketFile)); logStatus(QString("Starting '%1 %2' ...") - .arg(m_executablePath, m_arguments.join(QLatin1Char(' ')))); - m_process->start(m_executablePath, m_arguments); + .arg(m_executablePath, arguments.join(QLatin1Char(' ')))); + m_process->start(m_executablePath, arguments); if (!m_process->waitForStarted()) { logError(QString("Could not run '%1': %2").arg(m_executablePath, m_process->errorString())); exit(1); |
