aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qmltc_qprocess
diff options
context:
space:
mode:
authorSami Shalayel <sami.shalayel@qt.io>2022-09-28 20:04:44 +0200
committerSami Shalayel <sami.shalayel@qt.io>2022-11-23 10:29:25 +0100
commit3103bf5a4267cef2c402649cade0a18024a9130b (patch)
tree9d8d0b45394260e7c1f133673dee00d7cc0b833d /tests/auto/qml/qmltc_qprocess
parented47bff4118f677e135f3b7c113b035ac991c5ca (diff)
QQmlJSImportVisitor: warn when uncreatables are created
isCreatable in qqmljsscope just returns the value of the flag as it was read from the qmltypes, which is slightly confusing as isCreatable is an opt-out option. Instead, isCreatable should reflect whether the type is creatable or not. A type is uncreatable if and only if it is a singleton, an attached type, a c++ type with QML_UNCREATABLE and types without default constructor. This uncreatibility can also be inherited to composite types. Types without default constructor require QML_UNCREATABLE or QML_ANONYMOUS, and will be handled in another commit. Now that uncreatable types can be detected, emit a warning when a singleton or an uncreatable type is created: up to now no such warning was emitted. This warning can be seen when using qmllint or qmltc. By the way, also fix qmltc to not assert when something goes wrong (e.g. because an uncreatable or singleton type was created). Change-Id: I9a82106a801d14063407eb4e54858b1ca9fd578b Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests/auto/qml/qmltc_qprocess')
-rw-r--r--tests/auto/qml/qmltc_qprocess/CMakeLists.txt10
-rw-r--r--tests/auto/qml/qmltc_qprocess/cpptypes/testtype.h52
-rw-r--r--tests/auto/qml/qmltc_qprocess/data/singletonUncreatable.qml5
-rw-r--r--tests/auto/qml/qmltc_qprocess/data/uncreatable.qml23
-rw-r--r--tests/auto/qml/qmltc_qprocess/tst_qmltc_qprocess.cpp22
5 files changed, 106 insertions, 6 deletions
diff --git a/tests/auto/qml/qmltc_qprocess/CMakeLists.txt b/tests/auto/qml/qmltc_qprocess/CMakeLists.txt
index 5644a622a2..04d2084d4f 100644
--- a/tests/auto/qml/qmltc_qprocess/CMakeLists.txt
+++ b/tests/auto/qml/qmltc_qprocess/CMakeLists.txt
@@ -9,6 +9,11 @@ qt_internal_add_test(tst_qmltc_qprocess
Qt::Qml
Qt::QuickTestUtilsPrivate
)
+
+# special setup for singleton files:
+set_source_files_properties(data/SingletonThing.qml data/singletonUncreatable.qml
+ PROPERTIES QT_QML_SINGLETON_TYPE true)
+
qt6_add_qml_module(tst_qmltc_qprocess
VERSION 1.0
URI QmltcQProcessTests
@@ -23,6 +28,8 @@ qt6_add_qml_module(tst_qmltc_qprocess
data/invalidAliasRevision.qml
data/ComponentType.qml
data/inlineComponentWithEnum.qml
+ data/singletonUncreatable.qml
+ data/uncreatable.qml
)
set(common_libraries
@@ -37,9 +44,6 @@ set(common_libraries
target_include_directories(tst_qmltc_qprocess PUBLIC cpptypes/)
target_link_libraries(tst_qmltc_qprocess PUBLIC ${common_libraries})
-# special setup for singleton files:
-set_source_files_properties(SingletonThing.qml PROPERTIES QT_QML_SINGLETON_TYPE true)
-
add_dependencies(tst_qmltc_qprocess Qt::qmltc)
# fetch --resource arguments manually (mimics the logic of qmltc compilation
diff --git a/tests/auto/qml/qmltc_qprocess/cpptypes/testtype.h b/tests/auto/qml/qmltc_qprocess/cpptypes/testtype.h
index a6fdb4a51a..6082870c76 100644
--- a/tests/auto/qml/qmltc_qprocess/cpptypes/testtype.h
+++ b/tests/auto/qml/qmltc_qprocess/cpptypes/testtype.h
@@ -3,12 +3,15 @@
#ifndef TESTTYPE_H
#define TESTTYPE_H
+
+#include <QtQmlIntegration/qqmlintegration.h>
#include <QtCore/qobject.h>
#include <QtQml/qqmlregistration.h>
class TypeWithVersionedAlias : public QObject
{
Q_OBJECT
+ QML_UNCREATABLE("")
QML_ELEMENT
QString m_readAndWrite;
@@ -17,4 +20,53 @@ public:
Q_PROPERTY(QString notExisting MEMBER m_readAndWrite REVISION(6, 0));
Q_PROPERTY(QString existing MEMBER m_readAndWrite REVISION(1, 0));
};
+
+class UncreatableType : public QObject
+{
+ Q_OBJECT
+ QML_ELEMENT
+ QML_UNCREATABLE("")
+};
+
+class NoDefaultConstructorType : public QObject
+{
+ Q_OBJECT
+ QML_ELEMENT
+ NoDefaultConstructorType() = delete;
+};
+
+class SingletonType : public QObject
+{
+ Q_OBJECT
+ QML_ELEMENT
+ QML_SINGLETON
+};
+
+class NotSingletonType : public SingletonType
+{
+ Q_OBJECT
+ QML_ELEMENT
+};
+
+class NormalTypeAttached : public QObject
+{
+ Q_OBJECT
+ QML_ANONYMOUS
+public:
+ NormalTypeAttached(QObject* parent): QObject(parent) {}
+};
+
+class NormalType : public QObject
+{
+ Q_OBJECT
+ QML_ELEMENT
+ QML_ATTACHED(NormalTypeAttached)
+
+ static NormalTypeAttached *qmlAttachedProperties(QObject *object) {
+ return new NormalTypeAttached(object);
+ }
+};
+
+
+
#endif // TESTTYPE_H
diff --git a/tests/auto/qml/qmltc_qprocess/data/singletonUncreatable.qml b/tests/auto/qml/qmltc_qprocess/data/singletonUncreatable.qml
new file mode 100644
index 0000000000..d48a4ee186
--- /dev/null
+++ b/tests/auto/qml/qmltc_qprocess/data/singletonUncreatable.qml
@@ -0,0 +1,5 @@
+pragma Singleton
+
+UncreatableType {
+
+}
diff --git a/tests/auto/qml/qmltc_qprocess/data/uncreatable.qml b/tests/auto/qml/qmltc_qprocess/data/uncreatable.qml
new file mode 100644
index 0000000000..aad6ef3421
--- /dev/null
+++ b/tests/auto/qml/qmltc_qprocess/data/uncreatable.qml
@@ -0,0 +1,23 @@
+import QtQuick
+
+Item {
+ // Illegal cases:
+ UncreatableType {}
+ SingletonThing {}
+ SingletonType {}
+
+ component A: SingletonThing {}
+ component AA: A {}
+ component AAA: AA {}
+ AAA {}
+
+ component B: SingletonType {}
+ component BB: B {}
+ component BBB: BB {}
+ BBB {}
+
+ // Legal cases, where qmltc should not crash
+ property SingletonThing myQmlSingleton
+ property SingletonType myCppSingleton
+ NotSingletonType {} // ok because a non composite type inheriting from a singleton does not become a singleton!
+}
diff --git a/tests/auto/qml/qmltc_qprocess/tst_qmltc_qprocess.cpp b/tests/auto/qml/qmltc_qprocess/tst_qmltc_qprocess.cpp
index ae01f4697f..ea30e3c83f 100644
--- a/tests/auto/qml/qmltc_qprocess/tst_qmltc_qprocess.cpp
+++ b/tests/auto/qml/qmltc_qprocess/tst_qmltc_qprocess.cpp
@@ -189,9 +189,25 @@ void tst_qmltc_qprocess::inlineComponent()
void tst_qmltc_qprocess::singleton()
{
- const auto errors = runQmltc(u"SingletonThing.qml"_s, false);
- QEXPECT_FAIL("", "qmltc does not support singletons at the moment", Continue);
- QVERIFY(!errors.contains(u"Singleton types are not supported"_s));
+ {
+ const auto errors = runQmltc(u"singletonUncreatable.qml"_s, false);
+ QVERIFY(errors.contains("singletonUncreatable.qml:3:1: Type UncreatableType is not "
+ "creatable. [uncreatable-type]"));
+ }
+ {
+ const auto errors = runQmltc(u"uncreatable.qml"_s, false);
+ QVERIFY(errors.contains(
+ "uncreatable.qml:5:5: Type UncreatableType is not creatable. [uncreatable-type]"));
+ QVERIFY(errors.contains("uncreatable.qml:6:5: Singleton Type SingletonThing is not "
+ "creatable. [uncreatable-type]"));
+ QVERIFY(errors.contains("uncreatable.qml:7:5: Singleton Type SingletonType is not "
+ "creatable. [uncreatable-type]"));
+ QVERIFY(errors.contains("uncreatable.qml:9:18: Singleton Type SingletonThing is not "
+ "creatable. [uncreatable-type]"));
+ QVERIFY(errors.contains("uncreatable.qml:14:18: Singleton Type SingletonType is not "
+ "creatable. [uncreatable-type]"));
+ QVERIFY(!errors.contains("NotSingletonType"));
+ }
}
void tst_qmltc_qprocess::warningsAsErrors()