aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml
diff options
context:
space:
mode:
authorLuca Di Sera <luca.disera@qt.io>2024-04-17 12:28:48 +0200
committerLuca Di Sera <luca.disera@qt.io>2024-04-23 09:47:01 +0200
commitb6b934f830bd355359accaafef4f7e4ca0b8d4bd (patch)
treeb5950212cf0a7d206dd34b4de1cc370a7cfc81f2 /tests/auto/qml
parentc5b6beeff2e1ae2e18546f6bb39ebbed2e972b23 (diff)
qmltc: Test failure for unbound required property in inline component
`qmltc` should fail when it processes a QML file that instances an inline component that has some top-level required properties without setting them when creating the instance. For example: ``` import QtQuick Item { component IC: Item { required property int i } IC { // i needs to be set here as it cannot be set later } } ``` To parse a QML file, `qmltc` uses `QQmlJSImportVisitor`, which will produce an error on encountering such a case. `qmltc` will in turn propagate the error and fail itself, thus acting properly. A new test was added to keep track of the behavior and ensure that `qmltc` rejects a file when this erroneous form is encountered. Task-number: QTBUG-120698 Change-Id: I1a1b7a3d55f3ba5dde7d04b014b7d6a9b53a546d Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests/auto/qml')
-rw-r--r--tests/auto/qml/qmltc_qprocess/CMakeLists.txt1
-rw-r--r--tests/auto/qml/qmltc_qprocess/data/unboundRequiredPropertyInInlineComponent.qml10
-rw-r--r--tests/auto/qml/qmltc_qprocess/tst_qmltc_qprocess.cpp11
3 files changed, 22 insertions, 0 deletions
diff --git a/tests/auto/qml/qmltc_qprocess/CMakeLists.txt b/tests/auto/qml/qmltc_qprocess/CMakeLists.txt
index 55266c80d9..23f2d202b2 100644
--- a/tests/auto/qml/qmltc_qprocess/CMakeLists.txt
+++ b/tests/auto/qml/qmltc_qprocess/CMakeLists.txt
@@ -43,6 +43,7 @@ qt6_add_qml_module(tst_qmltc_qprocess
data/QmlBaseFromAnotherModule.qml
data/invalidTypeAnnotation.qml
data/constructFromString.qml
+ data/unboundRequiredPropertyInInlineComponent.qml
)
set(common_libraries
diff --git a/tests/auto/qml/qmltc_qprocess/data/unboundRequiredPropertyInInlineComponent.qml b/tests/auto/qml/qmltc_qprocess/data/unboundRequiredPropertyInInlineComponent.qml
new file mode 100644
index 0000000000..3955a228d8
--- /dev/null
+++ b/tests/auto/qml/qmltc_qprocess/data/unboundRequiredPropertyInInlineComponent.qml
@@ -0,0 +1,10 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+import QtQuick
+
+Item {
+ component InlineComponent: Item { required property int foo }
+
+ InlineComponent {}
+}
diff --git a/tests/auto/qml/qmltc_qprocess/tst_qmltc_qprocess.cpp b/tests/auto/qml/qmltc_qprocess/tst_qmltc_qprocess.cpp
index fdb64f4a29..6028aaff0c 100644
--- a/tests/auto/qml/qmltc_qprocess/tst_qmltc_qprocess.cpp
+++ b/tests/auto/qml/qmltc_qprocess/tst_qmltc_qprocess.cpp
@@ -55,6 +55,7 @@ private slots:
void qmlBaseFromAnotherModule();
void invalidTypeAnnotation();
void constructFromString();
+ void unboundRequiredPropertyInInlineComponent();
};
#ifndef TST_QMLTC_QPROCESS_RESOURCES
@@ -340,5 +341,15 @@ void tst_qmltc_qprocess::constructFromString()
QVERIFY(errors.contains(warningMessage.arg(6).arg(23).arg(u"QSizeF")));
}
+void tst_qmltc_qprocess::unboundRequiredPropertyInInlineComponent()
+{
+ {
+ const auto errors = runQmltc(u"unboundRequiredPropertyInInlineComponent.qml"_s, false);
+ QVERIFY(errors.contains(
+ u"unboundRequiredPropertyInInlineComponent.qml:9:5: Component is missing required property foo from InlineComponent [required]"_s
+ ));
+ }
+}
+
QTEST_MAIN(tst_qmltc_qprocess)
#include "tst_qmltc_qprocess.moc"