forked from qt-creator/qt-creator
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:
@@ -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
|
# 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
|
# 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).
|
# 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()
|
issuesModel = issuesView.model()
|
||||||
# wait for issues
|
# wait for issues
|
||||||
waitFor("issuesModel.rowCount() > 0", 5000)
|
waitFor("issuesModel.rowCount() > 0", 5000)
|
||||||
# warn if more issues reported
|
# warn if more issues reported
|
||||||
if(warnIfMoreIssues and issuesModel.rowCount() > 1):
|
if(warnIfMoreIssues and issuesModel.rowCount() > 1):
|
||||||
test.warning("More than one expected issues reported")
|
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
|
# iterate issues and check if there exists "Unexpected token" message
|
||||||
for description, type in zip(dumpItems(issuesModel, role=Qt.UserRole),
|
for description, type in zip(dumpItems(issuesModel, role=Qt.UserRole),
|
||||||
dumpItems(issuesModel, role=Qt.UserRole + 1)):
|
dumpItems(issuesModel, role=Qt.UserRole + 1)):
|
||||||
@@ -27,11 +34,12 @@ def checkSyntaxError(issuesView, expectedTextsArray, warnIfMoreIssues = True):
|
|||||||
for expectedText in expectedTextsArray:
|
for expectedText in expectedTextsArray:
|
||||||
if expectedText in description:
|
if expectedText in description:
|
||||||
# check if it is error and warn if not - returns False which leads to fail
|
# check if it is error and warn if not - returns False which leads to fail
|
||||||
if type is not "1":
|
if type not in expectedTypes:
|
||||||
test.warning("Expected error text found, but is not of type: 'error'")
|
test.warning("Expected error text found, but is not of type: %s" % typeText)
|
||||||
|
test.log("Found type: %s" % type)
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
test.log("Found expected error (%s)" % expectedText)
|
test.log("Found expected %s (%s)" % (typeText, expectedText))
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@@ -23,17 +23,28 @@ def main():
|
|||||||
issuesView = waitForObject(":Qt Creator.Issues_QListView")
|
issuesView = waitForObject(":Qt Creator.Issues_QListView")
|
||||||
clickButton(waitForObject(":*Qt Creator.Clear_QToolButton"))
|
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
|
# invoke QML parsing
|
||||||
invokeMenuItem("Tools", "QML/JS", "Run Checks")
|
invokeMenuItem("Tools", "QML/JS", "Run Checks")
|
||||||
# verify that error properly reported
|
# verify that error properly reported
|
||||||
test.verify(checkSyntaxError(issuesView, ['Invalid property name "Color". (M16)'], True),
|
# internal check returns e.g.'Invalid property name "Color". (M16)'
|
||||||
"Verifying if error is properly reported")
|
# 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
|
# repair error - go to written line
|
||||||
placeCursorToLine(editorArea, testingCodeLine)
|
placeCursorToLine(editorArea, testingCodeLine)
|
||||||
for _ in range(14):
|
for _ in range(14):
|
||||||
type(editorArea, "<Left>")
|
type(editorArea, "<Left>")
|
||||||
markText(editorArea, "Right")
|
markText(editorArea, "Right")
|
||||||
type(editorArea, "c")
|
type(editorArea, "c")
|
||||||
|
|
||||||
|
waitFor(lambda: docIsMarkedAsModified(), 2000)
|
||||||
|
invokeMenuItem('File', 'Save "Main.qml"')
|
||||||
# invoke QML parsing
|
# invoke QML parsing
|
||||||
invokeMenuItem("Tools", "QML/JS", "Run Checks")
|
invokeMenuItem("Tools", "QML/JS", "Run Checks")
|
||||||
# verify that there is no error/errors cleared
|
# verify that there is no error/errors cleared
|
||||||
@@ -42,5 +53,5 @@ def main():
|
|||||||
# wait for issues
|
# wait for issues
|
||||||
test.verify(waitFor("issuesModel.rowCount() == 0", 3000),
|
test.verify(waitFor("issuesModel.rowCount() == 0", 3000),
|
||||||
"Verifying if error was properly cleared after code fix")
|
"Verifying if error was properly cleared after code fix")
|
||||||
saveAndExit()
|
invokeMenuItem("File", "Exit")
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user