From 809b37110893bc88c229cd57108ad2db819154af Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Fri, 4 Mar 2022 17:25:51 +0100 Subject: [PATCH] Fix tst_qtcprocess when Qt is showing warnings on startup In my case Qt is persistently showing the following warning at startup of every application: Warning: Ignoring WAYLAND_DISPLAY on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway. There is no easy solution here, as even when I run this test with -platform xcb option, then this test is running another instance of Creator that doesn't have this option passed. Since QTest's internal main function parses the argv options and filters out those recognized by Qt itself, calling QCoreApplication::arguments() doesn't return the originally passed -platform xcb option. The solution here is simple - we ignore initial lines in callback (so we filter out the initial warnings generated by Qt) and wait for first expected line. The final check of parsed line numbers should prevent the case when we have filtered out all the lines. Change-Id: Ideff0dc7c409b6e3ad81ec13577cb67e5211d5df Reviewed-by: Reviewed-by: Alessandro Portale --- tests/auto/utils/qtcprocess/tst_qtcprocess.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/auto/utils/qtcprocess/tst_qtcprocess.cpp b/tests/auto/utils/qtcprocess/tst_qtcprocess.cpp index 2fbdedb1122..f8422c053d4 100644 --- a/tests/auto/utils/qtcprocess/tst_qtcprocess.cpp +++ b/tests/auto/utils/qtcprocess/tst_qtcprocess.cpp @@ -1011,8 +1011,13 @@ void tst_QtcProcess::lineCallback() QStringList lines = QString(lineCallbackData).split('|'); int lineNumber = 0; process.setStdErrLineCallback([lines, &lineNumber](const QString &actual) { - QString expected = lines.at(lineNumber++); + QString expected = lines.at(lineNumber); expected.replace("\r\n", "\n"); + // Omit some initial lines generated by Qt, e.g. + // Warning: Ignoring WAYLAND_DISPLAY on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway. + if (lineNumber == 0 && actual != expected) + return; + ++lineNumber; QCOMPARE(actual, expected); }); process.start(); @@ -1026,8 +1031,13 @@ void tst_QtcProcess::lineCallbackIntern() QStringList lines = QString(lineCallbackData).split('|'); int lineNumber = 0; process.setStdOutLineCallback([lines, &lineNumber](const QString &actual) { - QString expected = lines.at(lineNumber++); + QString expected = lines.at(lineNumber); expected.replace("\r\n", "\n"); + // Omit some initial lines generated by Qt, e.g. + // Warning: Ignoring WAYLAND_DISPLAY on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway. + if (lineNumber == 0 && actual != expected) + return; + ++lineNumber; QCOMPARE(actual, expected); }); process.beginFeed();