aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAssam Boudjelthia <assam.boudjelthia@qt.io>2024-10-30 16:32:44 +0200
committerAssam Boudjelthia <assam.boudjelthia@qt.io>2024-10-30 18:30:39 +0200
commit116ec82af038185dec1e769d68ceccd382dbb5d5 (patch)
tree4a045933a87c396e9a8a8425f7cbd421ee2d340a /src
parenta4bbadcc8b4c2d24b79536df615aa511e2d8ee6c (diff)
QuickTest: write test exit code for androidtestrunner
Write the exit code for quick tests at the end of the test run where it would be available to androidtestrunner to find out the exact number of failed tests. Complements 8d4022187b660de6c81c09ea7a4864048aa94978. Fixes: QTBUG-129976 Pick-to: 6.8 Change-Id: I6315c24897632421dbbc2a0250c77782f13c406d Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/qmltest/quicktest.cpp30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/qmltest/quicktest.cpp b/src/qmltest/quicktest.cpp
index 1a580f8c69..8557288aed 100644
--- a/src/qmltest/quicktest.cpp
+++ b/src/qmltest/quicktest.cpp
@@ -38,6 +38,10 @@
#include <QtTest/QSignalSpy>
#include <QtQml/QQmlFileSelector>
+#ifdef Q_OS_ANDROID
+#include <QtCore/QStandardPaths>
+#endif
+
#include <private/qqmlcomponent_p.h>
#include <private/qv4resolvedtypereference_p.h>
@@ -429,12 +433,24 @@ int quick_test_main(int argc, char **argv, const char *name, const char *sourceD
return quick_test_main_with_setup(argc, argv, name, sourceDir, nullptr);
}
+#ifdef Q_OS_ANDROID
+static QFile androidExitCodeFile()
+{
+ const QString testHome = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
+ return QFile(testHome + "/qtest_last_exit_code");
+}
+#endif
+
int quick_test_main_with_setup(int argc, char **argv, const char *name, const char *sourceDir, QObject *setup)
{
QScopedPointer<QCoreApplication> app;
if (!QCoreApplication::instance())
app.reset(new QGuiApplication(argc, argv));
+#ifdef Q_OS_ANDROID
+ androidExitCodeFile().remove();
+#endif
+
if (setup)
maybeInvokeSetupMethod(setup, "applicationAvailable()");
@@ -696,8 +712,20 @@ int quick_test_main_with_setup(int argc, char **argv, const char *name, const ch
return commandLineTestFunctions.size();
}
+ const int exitCode = QuickTestResult::exitCode();
+
+#ifdef Q_OS_ANDROID
+ QFile exitCodeFile = androidExitCodeFile();
+ if (exitCodeFile.open(QIODevice::WriteOnly)) {
+ exitCodeFile.write(qPrintable(QString::number(exitCode)));
+ } else {
+ qWarning("Failed to open %s for writing test exit code: %s",
+ qPrintable(exitCodeFile.fileName()), qPrintable(exitCodeFile.errorString()));
+ }
+#endif
+
// Return the number of failures as the exit code.
- return QuickTestResult::exitCode();
+ return exitCode;
}
QT_END_NAMESPACE