diff options
author | Luca Di Sera <luca.disera@qt.io> | 2024-04-17 13:10:20 +0200 |
---|---|---|
committer | Luca Di Sera <luca.disera@qt.io> | 2024-04-23 09:47:01 +0200 |
commit | 618b9af677cee142ab0b51265d40e77abb5b55b6 (patch) | |
tree | 717af8379dc71dfde6e5ca0a6b9a16fea7384c6d | |
parent | b6b934f830bd355359accaafef4f7e4ca0b8d4bd (diff) |
qmltc: Test failure for unbound required properties in component
`qmltc` should fail when it processes a QML file that defines a
component that has unbound inner-level required properties, similarly to
how it should generally fail when an unbound inner-level required
property is present, as those are not settable at a later phase.
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: Iadb9648ea09951a1741679c9c27abe014876656b
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
3 files changed, 30 insertions, 0 deletions
diff --git a/tests/auto/qml/qmltc_qprocess/CMakeLists.txt b/tests/auto/qml/qmltc_qprocess/CMakeLists.txt index 23f2d202b2..5cb4a933bb 100644 --- a/tests/auto/qml/qmltc_qprocess/CMakeLists.txt +++ b/tests/auto/qml/qmltc_qprocess/CMakeLists.txt @@ -44,6 +44,7 @@ qt6_add_qml_module(tst_qmltc_qprocess data/invalidTypeAnnotation.qml data/constructFromString.qml data/unboundRequiredPropertyInInlineComponent.qml + data/componentDefinitionInnerRequiredProperty.qml ) set(common_libraries diff --git a/tests/auto/qml/qmltc_qprocess/data/componentDefinitionInnerRequiredProperty.qml b/tests/auto/qml/qmltc_qprocess/data/componentDefinitionInnerRequiredProperty.qml new file mode 100644 index 0000000000..638cf9fa1e --- /dev/null +++ b/tests/auto/qml/qmltc_qprocess/data/componentDefinitionInnerRequiredProperty.qml @@ -0,0 +1,18 @@ +// Copyright (C) 2024 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +import QtQuick + +Item { + Component { + id: mycomp + + Item { + Rectangle { + // Inner required properties cannot be set so this + // should produce an error + required property bool bar + } + } + } +} diff --git a/tests/auto/qml/qmltc_qprocess/tst_qmltc_qprocess.cpp b/tests/auto/qml/qmltc_qprocess/tst_qmltc_qprocess.cpp index 6028aaff0c..01dedaaa01 100644 --- a/tests/auto/qml/qmltc_qprocess/tst_qmltc_qprocess.cpp +++ b/tests/auto/qml/qmltc_qprocess/tst_qmltc_qprocess.cpp @@ -56,6 +56,7 @@ private slots: void invalidTypeAnnotation(); void constructFromString(); void unboundRequiredPropertyInInlineComponent(); + void componentDefinitionInnerRequiredProperty(); }; #ifndef TST_QMLTC_QPROCESS_RESOURCES @@ -351,5 +352,15 @@ void tst_qmltc_qprocess::unboundRequiredPropertyInInlineComponent() } } +void tst_qmltc_qprocess::componentDefinitionInnerRequiredProperty() +{ + { + const auto errors = runQmltc(u"componentDefinitionInnerRequiredProperty.qml"_s, false); + QVERIFY(errors.contains( + u"componentDefinitionInnerRequiredProperty.qml:11:13: Component is missing required property bar from here [required]" + )); + } +} + QTEST_MAIN(tst_qmltc_qprocess) #include "tst_qmltc_qprocess.moc" |