qmltc: Test failure on presence of non-top level required property

`qmltc` should fail when it processes a QML file that has a required
property that is not top-level, as it is invalid QML.

For example:

```
import QtQuick

Item {
  Item {
    required property int foo
  }
}
```

To parse a QML file, `qmltc` uses `QQmlJSImportVisitor`, which will
produce an error on encountering such a property.

`qmltc` will in turn propagate the error and fail itself, thus acting
properly when a non-top level required property is encountered in a QML
file.

A new test, `qmltc_build_failures`, is added to keep track of the
behavior and ensure that `qmltc` fails at the build-level when this form
of error is encountered.

Task-number: QTBUG-120698
Change-Id: I45f975f1258a42fd2eb66283c1d3611152278fcc
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Luca Di Sera 2024-03-21 15:38:21 +01:00
parent 036137238a
commit 18acf564fa
5 changed files with 48 additions and 0 deletions

View File

@ -155,5 +155,7 @@ if(TARGET Qt::Quick)
)
endif()
endif()
add_subdirectory(qmltc_build_failures)
endif()

View File

@ -0,0 +1,7 @@
# Copyright (C) 2024 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(qmltc_build_failures)
_qt_internal_test_expect_build_fail(nontoplevelrequiredproperty)

View File

@ -0,0 +1,26 @@
# Copyright (C) 2024 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(nontoplevelrequiredproperty)
find_package(Qt6 REQUIRED Quick REQUIRED ${Qt6Tests_PREFIX_PATH})
qt_standard_project_setup()
qt_add_executable(executable
main.cpp
)
qt6_add_qml_module(executable
VERSION 1.0
URI QmltcBuildFailures
QML_FILES
Main.qml
DEPENDENCIES
QtQuick
ENABLE_TYPE_COMPILER
)
target_link_libraries(executable PRIVATE Qt6::Quick)

View File

@ -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 {
Item {
required property int foo
}
}

View File

@ -0,0 +1,3 @@
#include "main.h"
int main() { }