diff options
author | Maximilian Goldstein <max.goldstein@qt.io> | 2021-06-11 14:32:31 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-06-17 12:35:02 +0000 |
commit | 0700f03e0163fe2e86c02fda3a7c173cb88faa0e (patch) | |
tree | 5dc94a7d7777f18515b4e11192262bef9514fdee /tests | |
parent | 94063d0c01b1471554773c00c2f6dd4a916fe0ac (diff) |
qmlcompiler: Fully support required properties
Previously support of required properties was limited to detecting whether a property that was required actually exists. Now it also enables us to determine whether or not the required property was ever bound to.
Still limited by the fact we do not fully support script bindings yet.
Fixes: QTBUG-86755
Change-Id: I1abb921d3b4f86a7929f0f829b541088e0c2bf60
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 803a5fda05832b139cc1d76b666777491c708a96)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
5 files changed, 85 insertions, 2 deletions
diff --git a/tests/auto/qml/qmllint/data/requiredProperty.qml b/tests/auto/qml/qmllint/data/requiredProperty.qml index b10f0f67cd..6e0eec54e7 100644 --- a/tests/auto/qml/qmllint/data/requiredProperty.qml +++ b/tests/auto/qml/qmllint/data/requiredProperty.qml @@ -3,4 +3,5 @@ import QtQml 2.15 QtObject { property int x required x + x: 5 } diff --git a/tests/auto/qml/qmllint/data/requiredPropertyBindings.qml b/tests/auto/qml/qmllint/data/requiredPropertyBindings.qml new file mode 100644 index 0000000000..3bba84f412 --- /dev/null +++ b/tests/auto/qml/qmllint/data/requiredPropertyBindings.qml @@ -0,0 +1,24 @@ +import QtQuick 2.0 + +Item { + component Base : Item { + required property string required_now_string + property string required_later_string + + required property QtObject required_now_object + property QtObject required_later_object + } + + component Derived : Base { + required required_later_string + required required_later_object + } + + Derived { + required_now_string: "" + required_later_string: "" + + required_now_object: QtObject {} + required_later_object: QtObject {} + } +} diff --git a/tests/auto/qml/qmllint/data/requiredPropertyBindingsLater.qml b/tests/auto/qml/qmllint/data/requiredPropertyBindingsLater.qml new file mode 100644 index 0000000000..65c59d7161 --- /dev/null +++ b/tests/auto/qml/qmllint/data/requiredPropertyBindingsLater.qml @@ -0,0 +1,18 @@ +import QtQuick 2.0 + +Item { + component Base : Item { + required property string required_now_string + property string required_later_string + property string required_even_later_string + } + + component Derived : Base { + required required_later_string + } + + Derived { + required required_even_later_string + required_now_string: "" + } +} diff --git a/tests/auto/qml/qmllint/data/requiredPropertyBindingsNow.qml b/tests/auto/qml/qmllint/data/requiredPropertyBindingsNow.qml new file mode 100644 index 0000000000..701760b4e7 --- /dev/null +++ b/tests/auto/qml/qmllint/data/requiredPropertyBindingsNow.qml @@ -0,0 +1,17 @@ +import QtQuick 2.0 + +Item { + component Base : Item { + required property string required_now_string + property string required_later_string + } + + component Derived : Base { + required required_later_string + } + + Derived { + required property string required_defined_here_string + required_later_string: "" + } +} diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp index 5c307d9fb8..4c40062252 100644 --- a/tests/auto/qml/qmllint/tst_qmllint.cpp +++ b/tests/auto/qml/qmllint/tst_qmllint.cpp @@ -828,8 +828,31 @@ void TestQmllint::requiredProperty() { QVERIFY(runQmllint("requiredProperty.qml", true).isEmpty()); - const QString errors = runQmllint("requiredMissingProperty.qml", false); - QVERIFY(errors.contains(QStringLiteral("Property \"foo\" was marked as required but does not exist."))); + { + const QString errors = runQmllint("requiredMissingProperty.qml", false); + QVERIFY(errors.contains( + QStringLiteral("Property \"foo\" was marked as required but does not exist."))); + } + + QVERIFY(runQmllint("requiredPropertyBindings.qml", true).isEmpty()); + + { + const QString errors = runQmllint("requiredPropertyBindingsNow.qml", false); + QVERIFY(errors.contains(QStringLiteral( + "Component is missing required property required_now_string from Base"))); + QVERIFY(errors.contains(QStringLiteral( + "Component is missing required property required_defined_here_string from here"))); + } + + { + const QString errors = runQmllint("requiredPropertyBindingsLater.qml", false); + QVERIFY(errors.contains( + QStringLiteral("Component is missing required property required_later_string from " + "Base (marked as required by Derived)"))); + QVERIFY(errors.contains( + QStringLiteral("Component is missing required property required_even_later_string " + "from Base (marked as required by here)"))); + } } void TestQmllint::settingsFile() |