aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmltest
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2021-11-08 13:53:11 +0100
committerUlf Hermann <ulf.hermann@qt.io>2021-11-09 00:03:09 +0100
commitc84c7a31a5228385e35be807d0ebb030a74ed779 (patch)
treec59318a19f24eab5d7358fa4f0177b491ff93083 /src/qmltest
parentb99ae85206291861980199b63f219e754543b11e (diff)
QuickTest: Do not leak when returning an error
Avoid exit(), and wrap the application into a QScopedPointer. Also, handle errors while enumerating test cases the same way as errors while creating the QQuickView. Change-Id: I0dd147a16d3ea60147e15627295d7eb82630e59d Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/qmltest')
-rw-r--r--src/qmltest/quicktest.cpp25
1 files changed, 14 insertions, 11 deletions
diff --git a/src/qmltest/quicktest.cpp b/src/qmltest/quicktest.cpp
index 276463c7c5..aa81b0e180 100644
--- a/src/qmltest/quicktest.cpp
+++ b/src/qmltest/quicktest.cpp
@@ -137,10 +137,11 @@ static inline QString stripQuotes(const QString &s)
return s;
}
-void handleCompileErrors(const QFileInfo &fi, QQuickView *view)
+static void handleCompileErrors(
+ const QFileInfo &fi, const QList<QQmlError> &errors, QQmlEngine *engine,
+ QQuickView *view = nullptr)
{
// Error compiling the test - flag failure in the log and continue.
- const QList<QQmlError> errors = view->errors();
QuickTestResult results;
results.setTestCaseName(fi.baseName());
results.startLogging();
@@ -162,8 +163,11 @@ void handleCompileErrors(const QFileInfo &fi, QQuickView *view)
str << ": " << e.description() << '\n';
}
str << " Working directory: " << QDir::toNativeSeparators(QDir::current().absolutePath()) << '\n';
- if (QQmlEngine *engine = view->engine()) {
- str << " View: " << view->metaObject()->className() << ", import paths:\n";
+ if (engine) {
+ str << " ";
+ if (view)
+ str << "View: " << view->metaObject()->className() << ", ";
+ str << "Import paths:\n";
const auto importPaths = engine->importPathList();
for (const QString &i : importPaths)
str << " '" << QDir::toNativeSeparators(i) << "'\n";
@@ -361,9 +365,9 @@ int quick_test_main(int argc, char **argv, const char *name, const char *sourceD
int quick_test_main_with_setup(int argc, char **argv, const char *name, const char *sourceDir, QObject *setup)
{
- QCoreApplication *app = nullptr;
+ QScopedPointer<QCoreApplication> app;
if (!QCoreApplication::instance())
- app = new QGuiApplication(argc, argv);
+ app.reset(new QGuiApplication(argc, argv));
if (setup)
maybeInvokeSetupMethod(setup, "applicationAvailable()");
@@ -532,9 +536,8 @@ int quick_test_main_with_setup(int argc, char **argv, const char *name, const ch
TestCaseCollector testCaseCollector(fi, &engine);
if (!testCaseCollector.errors().isEmpty()) {
- for (const QQmlError &error : testCaseCollector.errors())
- qWarning() << error;
- exit(1);
+ handleCompileErrors(fi, testCaseCollector.errors(), &engine);
+ continue;
}
TestCaseCollector::TestCaseList availableTestFunctions = testCaseCollector.testCases();
@@ -573,7 +576,7 @@ int quick_test_main_with_setup(int argc, char **argv, const char *name, const ch
while (view.status() == QQuickView::Loading)
QTest::qWait(10);
if (view.status() == QQuickView::Error) {
- handleCompileErrors(fi, &view);
+ handleCompileErrors(fi, view.errors(), view.engine(), &view);
continue;
}
if (!QTestRootObject::instance()->hasQuit) {
@@ -616,7 +619,7 @@ int quick_test_main_with_setup(int argc, char **argv, const char *name, const ch
// Flush the current logging stream.
QuickTestResult::setProgramName(nullptr);
- delete app;
+ app.reset();
// Check that all test functions passed on the command line were found
if (!commandLineTestFunctions.isEmpty()) {