diff options
author | Maximilian Goldstein <max.goldstein@qt.io> | 2022-01-18 13:08:09 +0100 |
---|---|---|
committer | Maximilian Goldstein <max.goldstein@qt.io> | 2022-02-03 11:17:34 +0100 |
commit | dc9de38abe797e835480171a047bf96e98c84e1f (patch) | |
tree | 1ce1b77174fdc38c45a23555399a665591da2b80 /tests/auto/qml | |
parent | a0f5baad2a645bfaa65773451e9d76944ae9a951 (diff) |
qmllint: Warn about missing singleton pragmas/qmldir entries
This change adds a warning if we encounter a component marked as a
singleton in a qmldir file which does not contain a pragma
Singleton entry and vice versa.
Note that the warning only gets triggered if the singleton is
actually used.
Fixes: QTBUG-98558
Change-Id: Id7c63f48ba49759c15dffcaee0270c7caab2eb7d
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Diffstat (limited to 'tests/auto/qml')
-rw-r--r-- | tests/auto/qml/qmllint/data/Singletons/MissingPragma.qml | 2 | ||||
-rw-r--r-- | tests/auto/qml/qmllint/data/Singletons/MissingQmldirSingleton.qml | 3 | ||||
-rw-r--r-- | tests/auto/qml/qmllint/data/Singletons/qmldir | 3 | ||||
-rw-r--r-- | tests/auto/qml/qmllint/data/missingSingletonPragma.qml | 6 | ||||
-rw-r--r-- | tests/auto/qml/qmllint/data/missingSingletonQmldir.qml | 6 | ||||
-rw-r--r-- | tests/auto/qml/qmllint/tst_qmllint.cpp | 11 | ||||
-rw-r--r-- | tests/auto/qml/qmltc/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/auto/qml/qmltc/data/CMakeLists.txt | 5 | ||||
-rw-r--r-- | tests/auto/qml/qmltc/tst_qmltc.cpp | 2 |
9 files changed, 36 insertions, 3 deletions
diff --git a/tests/auto/qml/qmllint/data/Singletons/MissingPragma.qml b/tests/auto/qml/qmllint/data/Singletons/MissingPragma.qml new file mode 100644 index 0000000000..54531c4bdc --- /dev/null +++ b/tests/auto/qml/qmllint/data/Singletons/MissingPragma.qml @@ -0,0 +1,2 @@ +import QtQml +QtObject {} diff --git a/tests/auto/qml/qmllint/data/Singletons/MissingQmldirSingleton.qml b/tests/auto/qml/qmllint/data/Singletons/MissingQmldirSingleton.qml new file mode 100644 index 0000000000..923966c483 --- /dev/null +++ b/tests/auto/qml/qmllint/data/Singletons/MissingQmldirSingleton.qml @@ -0,0 +1,3 @@ +pragma Singleton +import QtQml +QtObject {} diff --git a/tests/auto/qml/qmllint/data/Singletons/qmldir b/tests/auto/qml/qmllint/data/Singletons/qmldir new file mode 100644 index 0000000000..84e9876b80 --- /dev/null +++ b/tests/auto/qml/qmllint/data/Singletons/qmldir @@ -0,0 +1,3 @@ +module Singletons +singleton MissingPragma 1.0 MissingPragma.qml +MissingQmldirSingleton 1.0 MissingQmldirSingleton.qml diff --git a/tests/auto/qml/qmllint/data/missingSingletonPragma.qml b/tests/auto/qml/qmllint/data/missingSingletonPragma.qml new file mode 100644 index 0000000000..0c691baa76 --- /dev/null +++ b/tests/auto/qml/qmllint/data/missingSingletonPragma.qml @@ -0,0 +1,6 @@ +import QtQml +import Singletons + +QtObject { + Component.onCompleted: console.log(MissingPragma) +} diff --git a/tests/auto/qml/qmllint/data/missingSingletonQmldir.qml b/tests/auto/qml/qmllint/data/missingSingletonQmldir.qml new file mode 100644 index 0000000000..6bbda963a8 --- /dev/null +++ b/tests/auto/qml/qmllint/data/missingSingletonQmldir.qml @@ -0,0 +1,6 @@ +import QtQml +import Singletons + +QtObject { + Component.onCompleted: console.log(MissingQmldirSingleton) +} diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp index 95c4e8d6e7..4801d4ccbc 100644 --- a/tests/auto/qml/qmllint/tst_qmllint.cpp +++ b/tests/auto/qml/qmllint/tst_qmllint.cpp @@ -842,6 +842,17 @@ void TestQmllint::dirtyQmlCode_data() << QStringLiteral("Component is missing required property requiredAlias from " "RequiredWithRootLevelAlias") << QString() << QString() << false; + QTest::newRow("missingSingletonPragma") + << QStringLiteral("missingSingletonPragma.qml") + << QStringLiteral("Type MissingPragma declared as singleton in qmldir but missing " + "pragma Singleton") + << QString() << QString() << false; + QTest::newRow("missingSingletonQmldir") + << QStringLiteral("missingSingletonQmldir.qml") + << QStringLiteral( + "Type MissingQmldirSingleton not declared as singleton in qmldir but using " + "pragma Singleton") + << QString() << QString() << false; } void TestQmllint::dirtyQmlCode() diff --git a/tests/auto/qml/qmltc/CMakeLists.txt b/tests/auto/qml/qmltc/CMakeLists.txt index 4f468c41e9..1c15d9b1fb 100644 --- a/tests/auto/qml/qmltc/CMakeLists.txt +++ b/tests/auto/qml/qmltc/CMakeLists.txt @@ -14,7 +14,6 @@ set(qmltc_module_libs # automatic type registration that comes from the plugin) qmltc_test_moduleplugin ) - qt_internal_add_test(tst_qmltc_diskcache SOURCES ${test_sources} LIBRARIES ${qmltc_module_libs} diff --git a/tests/auto/qml/qmltc/data/CMakeLists.txt b/tests/auto/qml/qmltc/data/CMakeLists.txt index 87c5759de1..59b302f241 100644 --- a/tests/auto/qml/qmltc/data/CMakeLists.txt +++ b/tests/auto/qml/qmltc/data/CMakeLists.txt @@ -72,7 +72,7 @@ set(qml_sources LocallyImported.qml LocalWithOnCompleted.qml LocallyImported_context.qml - SingletonThing.qml +# SingletonThing.qml ) set(js_sources @@ -90,6 +90,9 @@ set(common_libraries set_source_files_properties(NameConflict.qml PROPERTIES QT_QMLTC_FILE_BASENAME ResolvedNameConflict) +# set_source_files_properties(SingletonThing.qml PROPERTIES +# QT_QML_SINGLETON_TYPE true) + qt_add_library(qmltc_test_module STATIC) qt_autogen_tools_initial_setup(qmltc_test_module) diff --git a/tests/auto/qml/qmltc/tst_qmltc.cpp b/tests/auto/qml/qmltc/tst_qmltc.cpp index a956c857dd..e26aa06e78 100644 --- a/tests/auto/qml/qmltc/tst_qmltc.cpp +++ b/tests/auto/qml/qmltc/tst_qmltc.cpp @@ -1417,9 +1417,9 @@ void tst_qmltc::behaviorAndAnimationOnAlias() void tst_qmltc::singletonUser() { QQmlEngine e; + QSKIP("Singleton types are not supported yet"); PREPEND_NAMESPACE(singletonUser) created(&e); - QSKIP("Singleton types are not supported yet"); QCOMPARE(created.number(), 42); QCOMPARE(created.message(), "hello"); } |