diff options
author | Mitch Curtis <[email protected]> | 2019-03-08 10:51:57 +0100 |
---|---|---|
committer | Mitch Curtis <[email protected]> | 2019-03-21 09:07:14 +0000 |
commit | 52ac0ea8cbdc9a2b8e895ceee09994fba229ee12 (patch) | |
tree | d279d868eb4d610138300a54b227559b9b29f3b3 /src/qmltest/quicktest.cpp | |
parent | c091f3f4b4889ac6be26e018c5e8b673adee7c47 (diff) |
QUICK_TEST_MAIN_WITH_SETUP: fix qmlEngineAvailable() being called too late
When I added the macro, I wasn't aware that TestCaseCollector was a
thing. TestCaseCollector loads each QML file without running the tests
(i.e. creates a QQmlComponent from the file without creating an object
from that component). Since it still executes imports, the test can
fail if types are registered or import paths added in
qmlEngineAvailable(), since it's called too late.
So, call it earlier. This should have no adverse effect on user code,
as nothing of importance to the user will be skipped, and the
documentation already details what can be expected by the time
qmlEngineAvailable() is called.
Change-Id: Ibd3a4b728bc87b90f89cc310fddf668c5879ad83
Fixes: QTBUG-74160
Reviewed-by: Ulf Hermann <[email protected]>
Diffstat (limited to 'src/qmltest/quicktest.cpp')
-rw-r--r-- | src/qmltest/quicktest.cpp | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/qmltest/quicktest.cpp b/src/qmltest/quicktest.cpp index 1a5cad5d5a..5288bb34f1 100644 --- a/src/qmltest/quicktest.cpp +++ b/src/qmltest/quicktest.cpp @@ -503,6 +503,13 @@ int quick_test_main_with_setup(int argc, char **argv, const char *name, const ch qmlFileSelector->setExtraSelectors(fileSelectors); } + // Do this down here so that import paths, plugin paths, file selectors, etc. are available + // in case the user needs access to them. Do it _before_ the TestCaseCollector parses the + // QML files though, because it attempts to import modules, which might not be available + // if qmlRegisterType()/QQmlEngine::addImportPath() are called in qmlEngineAvailable(). + if (setup) + QMetaObject::invokeMethod(setup, "qmlEngineAvailable", Q_ARG(QQmlEngine*, &engine)); + TestCaseCollector testCaseCollector(fi, &engine); if (!testCaseCollector.errors().isEmpty()) { for (const QQmlError &error : testCaseCollector.errors()) @@ -534,14 +541,6 @@ int quick_test_main_with_setup(int argc, char **argv, const char *name, const ch view.rootContext()->setContextProperty (QLatin1String("qtest"), QTestRootObject::instance()); // Deprecated. Use QTestRootObject from Qt.test.qtestroot instead - // Do this down here so that import paths, plugin paths, - // file selectors, etc. are available in case the user needs access to them. - if (setup) { - // Don't check the return value; it's OK if it doesn't exist. - // If we add more callbacks in the future, it makes sense if the user only implements one of them. - QMetaObject::invokeMethod(setup, "qmlEngineAvailable", Q_ARG(QQmlEngine*, view.engine())); - } - view.setObjectName(fi.baseName()); view.setTitle(view.objectName()); QTestRootObject::instance()->init(); |