SquishTests: Fix test for running qml checks

For CMake based projects this nowadays invokes a build
of the special cmake target qmllint and does not perform
the internal run check at all.
Therefore the expected messages and issue types may vary.
Adapt the test to pass at least for the current setup of
using CMake.

Change-Id: I849650b5a8bf59b84d667419ed49b2929466a328
Reviewed-by: Robert Löhning <robert.loehning@qt.io>
This commit is contained in:
Christian Stenger
2024-10-29 13:41:48 +01:00
parent 6451d42ed3
commit 3744160c3b
2 changed files with 26 additions and 7 deletions

View File

@@ -12,13 +12,20 @@ def appendToLine(codeArea, insertAfterLine, typeWhat):
# Current implementation is focused on allowing different compilers, and it is enough if one of the expected messages
# is found in issues view. warnIfMoreIssues should warn if there are more than one issue, no matter how many
# expected texts are in array (because they are alternatives).
def checkSyntaxError(issuesView, expectedTextsArray, warnIfMoreIssues = True):
# set canBeWarning to True if the issue can be listed as warning (e.g. qmllint)
def checkSyntaxError(issuesView, expectedTextsArray, warnIfMoreIssues = True, canBeWarning=False):
issuesModel = issuesView.model()
# wait for issues
waitFor("issuesModel.rowCount() > 0", 5000)
# warn if more issues reported
if(warnIfMoreIssues and issuesModel.rowCount() > 1):
test.warning("More than one expected issues reported")
expectedTypes = ["1"] # Error
typeText = "'error'"
if canBeWarning:
expectedTypes.append("2") # Warning
typeText = "'error' or 'warning'"
# iterate issues and check if there exists "Unexpected token" message
for description, type in zip(dumpItems(issuesModel, role=Qt.UserRole),
dumpItems(issuesModel, role=Qt.UserRole + 1)):
@@ -27,11 +34,12 @@ def checkSyntaxError(issuesView, expectedTextsArray, warnIfMoreIssues = True):
for expectedText in expectedTextsArray:
if expectedText in description:
# check if it is error and warn if not - returns False which leads to fail
if type is not "1":
test.warning("Expected error text found, but is not of type: 'error'")
if type not in expectedTypes:
test.warning("Expected error text found, but is not of type: %s" % typeText)
test.log("Found type: %s" % type)
return False
else:
test.log("Found expected error (%s)" % expectedText)
test.log("Found expected %s (%s)" % (typeText, expectedText))
return True
return False

View File

@@ -23,17 +23,28 @@ def main():
issuesView = waitForObject(":Qt Creator.Issues_QListView")
clickButton(waitForObject(":*Qt Creator.Clear_QToolButton"))
fileNameCombo = waitForObject(":Qt Creator_FilenameQComboBox")
docIsMarkedAsModified = lambda: str(fileNameCombo.currentText).endswith('*')
if test.verify(waitFor(lambda: docIsMarkedAsModified(), 2000), "File is marked modified."):
invokeMenuItem('File', 'Save "Main.qml"')
# invoke QML parsing
invokeMenuItem("Tools", "QML/JS", "Run Checks")
# verify that error properly reported
test.verify(checkSyntaxError(issuesView, ['Invalid property name "Color". (M16)'], True),
"Verifying if error is properly reported")
# internal check returns e.g.'Invalid property name "Color". (M16)'
# but if project is CMake based the messages are generated by qmllint
test.verify(checkSyntaxError(issuesView,
['Binding assigned to "Color", but no property "Color" exists in '
'the current element.'], False, True),
"Verifying if error or warning is properly reported")
# repair error - go to written line
placeCursorToLine(editorArea, testingCodeLine)
for _ in range(14):
type(editorArea, "<Left>")
markText(editorArea, "Right")
type(editorArea, "c")
waitFor(lambda: docIsMarkedAsModified(), 2000)
invokeMenuItem('File', 'Save "Main.qml"')
# invoke QML parsing
invokeMenuItem("Tools", "QML/JS", "Run Checks")
# verify that there is no error/errors cleared
@@ -42,5 +53,5 @@ def main():
# wait for issues
test.verify(waitFor("issuesModel.rowCount() == 0", 3000),
"Verifying if error was properly cleared after code fix")
saveAndExit()
invokeMenuItem("File", "Exit")