From 3744160c3bc0925ee820ebbd70386efc7b51a488 Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Tue, 29 Oct 2024 13:41:48 +0100 Subject: [PATCH] SquishTests: Fix test for running qml checks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- tests/system/shared/suites_qtta.py | 16 ++++++++++++---- tests/system/suite_QMLS/tst_QMLS02/test.py | 17 ++++++++++++++--- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/tests/system/shared/suites_qtta.py b/tests/system/shared/suites_qtta.py index 97032ae0638..140fdb05290 100644 --- a/tests/system/shared/suites_qtta.py +++ b/tests/system/shared/suites_qtta.py @@ -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 diff --git a/tests/system/suite_QMLS/tst_QMLS02/test.py b/tests/system/suite_QMLS/tst_QMLS02/test.py index 1340db315ff..a9251afc57b 100644 --- a/tests/system/suite_QMLS/tst_QMLS02/test.py +++ b/tests/system/suite_QMLS/tst_QMLS02/test.py @@ -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, "") 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")