forked from qt-creator/qt-creator
Squish: Fix generic highlighter test
This is now using KSyntaxHighlighter, adapt accordingly. Change-Id: Ie5dac469d326c5165f5f8513bc3adc5f6be5e48b Reviewed-by: Robert Loehning <robert.loehning@qt.io>
This commit is contained in:
@@ -25,6 +25,15 @@
|
|||||||
|
|
||||||
source("../../shared/qtcreator.py")
|
source("../../shared/qtcreator.py")
|
||||||
|
|
||||||
|
def __highlighterDefinitionsDirectory__():
|
||||||
|
if platform.system() in ('Microsoft', 'Windows'):
|
||||||
|
basePath = os.path.expandvars("%LOCALAPPDATA%")
|
||||||
|
elif platform.system() == 'Linux':
|
||||||
|
basePath = os.path.expanduser("~/.local/share")
|
||||||
|
else: # macOS
|
||||||
|
basePath = os.path.expanduser("~/Library/Application Support")
|
||||||
|
return os.path.join(basePath, "org.kde.syntax-highlighting", "syntax")
|
||||||
|
|
||||||
def createFile(folder, filename):
|
def createFile(folder, filename):
|
||||||
__createProjectOrFileSelectType__(" General", "Empty File", isProject = False)
|
__createProjectOrFileSelectType__(" General", "Empty File", isProject = False)
|
||||||
replaceEditorContent(waitForObject("{name='nameLineEdit' visible='1' "
|
replaceEditorContent(waitForObject("{name='nameLineEdit' visible='1' "
|
||||||
@@ -103,56 +112,34 @@ def getOrModifyFilePatternsFor(mimeType, filter='', toBePresent=None):
|
|||||||
clickButton(":Options.Cancel_QPushButton")
|
clickButton(":Options.Cancel_QPushButton")
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def uncheckGenericHighlighterFallback():
|
def addHighlighterDefinition(*languages):
|
||||||
|
syntaxDirectory = __highlighterDefinitionsDirectory__()
|
||||||
|
toBeChecked = (os.path.join(syntaxDirectory, x + ".xml") for x in languages)
|
||||||
|
test.log("Updating highlighter definitions...")
|
||||||
invokeMenuItem("Tools", "Options...")
|
invokeMenuItem("Tools", "Options...")
|
||||||
waitForObjectItem(":Options_QListView", "Text Editor")
|
waitForObjectItem(":Options_QListView", "Text Editor")
|
||||||
clickItem(":Options_QListView", "Text Editor", 14, 15, 0, Qt.LeftButton)
|
clickItem(":Options_QListView", "Text Editor", 14, 15, 0, Qt.LeftButton)
|
||||||
waitForObject("{container=':Options.qt_tabwidget_tabbar_QTabBar' type='TabItem' "
|
waitForObject("{container=':Options.qt_tabwidget_tabbar_QTabBar' type='TabItem' "
|
||||||
"text='Generic Highlighter'}")
|
"text='Generic Highlighter'}")
|
||||||
clickOnTab(":Options.qt_tabwidget_tabbar_QTabBar", "Generic Highlighter")
|
clickOnTab(":Options.qt_tabwidget_tabbar_QTabBar", "Generic Highlighter")
|
||||||
ensureChecked("{name='useFallbackLocation' text='Use fallback location' type='QCheckBox' "
|
|
||||||
"visible='1'}", False)
|
|
||||||
clickButton(":Options.OK_QPushButton")
|
|
||||||
|
|
||||||
def addHighlighterDefinition(language):
|
clickButton("{text='Update Definitions' type='QPushButton' name='updateDefinitions' visible='1'}")
|
||||||
global tmpSettingsDir
|
updateStatus = "{name='updateStatus' type='QLabel' visible='1'}"
|
||||||
test.log("Adding highlighter definitions for '%s'." % language)
|
waitFor("object.exists(updateStatus)", 5000)
|
||||||
invokeMenuItem("Tools", "Options...")
|
if waitFor('str(findObject(updateStatus).text) == "Update finished"', 5000):
|
||||||
waitForObjectItem(":Options_QListView", "Text Editor")
|
test.verify(os.path.exists(syntaxDirectory),
|
||||||
clickItem(":Options_QListView", "Text Editor", 14, 15, 0, Qt.LeftButton)
|
"Directory for syntax highlighter files exists.")
|
||||||
waitForObject("{container=':Options.qt_tabwidget_tabbar_QTabBar' type='TabItem' "
|
xmlFiles = glob.glob(os.path.join(syntaxDirectory, "*.xml"))
|
||||||
"text='Generic Highlighter'}")
|
test.verify(len(xmlFiles) > 0, "Verified presence of syntax highlighter files. "
|
||||||
clickOnTab(":Options.qt_tabwidget_tabbar_QTabBar", "Generic Highlighter")
|
"(Found %d)" % len(xmlFiles))
|
||||||
clickButton("{text='Download Definitions...' type='QPushButton' unnamed='1' visible='1'}")
|
# should we check output (General Messages) as well?
|
||||||
table = waitForObject("{name='definitionsTable' type='QTableWidget' visible='1'}")
|
test.passes("Updated definitions")
|
||||||
model = table.model()
|
clickButton(":Options.OK_QPushButton")
|
||||||
for row in range(model.rowCount()):
|
return map(os.path.exists, toBeChecked)
|
||||||
if str(model.data(model.index(row, 0)).toString()) == language:
|
else:
|
||||||
clickItem(table, "%d/0" % row, 5, 5, 0, Qt.LeftButton)
|
test.fail("Could not update highlighter definitions")
|
||||||
clickButton("{name='downloadButton' text='Download Selected Definitions' "
|
clickButton(":Options.Cancel_QPushButton")
|
||||||
"type='QPushButton' visible='1'}")
|
return map(os.path.exists, toBeChecked)
|
||||||
# downloading happens asynchronously but may take a little time
|
|
||||||
progressBarWait(10000)
|
|
||||||
languageFile = os.path.join(tmpSettingsDir, "QtProject", "qtcreator",
|
|
||||||
"generic-highlighter", "%s.xml"
|
|
||||||
% language.lower().replace(" ", "-"))
|
|
||||||
test.verify(waitFor("os.path.exists(languageFile)", 10000),
|
|
||||||
"Verifying whether highlight definition file for '%s' has been downloaded "
|
|
||||||
"and placed to settings." % language)
|
|
||||||
clickButton("{text='Download Definitions...' type='QPushButton' unnamed='1' "
|
|
||||||
"visible='1'}")
|
|
||||||
table = waitForObject("{name='definitionsTable' type='QTableWidget' visible='1'}")
|
|
||||||
model = table.model()
|
|
||||||
test.verify(str(model.data(model.index(row, 1))) != "",
|
|
||||||
"Verifying a definition has been downloaded.")
|
|
||||||
clickButton("{text='Close' type='QPushButton' unnamed='1' visible='1'}")
|
|
||||||
clickButton(":Options.OK_QPushButton")
|
|
||||||
return True
|
|
||||||
test.fail("Could not find the specified language (%s) to download a highlighter definition"
|
|
||||||
% language)
|
|
||||||
clickButton("{text='Close' type='QPushButton' unnamed='1' visible='1'}")
|
|
||||||
clickButton(":Options.OK_QPushButton")
|
|
||||||
return False
|
|
||||||
|
|
||||||
def hasSuffix(fileName, suffixPatterns):
|
def hasSuffix(fileName, suffixPatterns):
|
||||||
for suffix in suffixPatterns:
|
for suffix in suffixPatterns:
|
||||||
@@ -170,11 +157,12 @@ def displayHintForHighlighterDefinition(fileName, patterns, lPatterns, added, ad
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
miss = "A highlight definition was not found for this file. Would you like to try to find one?"
|
miss = ("A highlight definition was not found for this file. Would you like to update "
|
||||||
|
"highlight definition files?")
|
||||||
startQC()
|
startQC()
|
||||||
if not startedWithoutPluginError():
|
if not startedWithoutPluginError():
|
||||||
return
|
return
|
||||||
uncheckGenericHighlighterFallback()
|
|
||||||
patterns = getOrModifyFilePatternsFor("text/x-haskell", "x-haskell")
|
patterns = getOrModifyFilePatternsFor("text/x-haskell", "x-haskell")
|
||||||
lPatterns = getOrModifyFilePatternsFor("text/x-literate-haskell", "literate-haskell")
|
lPatterns = getOrModifyFilePatternsFor("text/x-literate-haskell", "literate-haskell")
|
||||||
|
|
||||||
@@ -204,8 +192,7 @@ def main():
|
|||||||
|
|
||||||
invokeMenuItem("File", "Save All")
|
invokeMenuItem("File", "Save All")
|
||||||
invokeMenuItem("File", "Close All")
|
invokeMenuItem("File", "Close All")
|
||||||
addedHighlighterDefinition = addHighlighterDefinition("Haskell")
|
addedHaskell, addedLiterateHaskell = addHighlighterDefinition("haskell", "literate-haskell")
|
||||||
addedLiterateHighlighterDefinition = addHighlighterDefinition("Literate Haskell")
|
|
||||||
patterns = getOrModifyFilePatternsFor('text/x-haskell', 'x-haskell', ['.hs'])
|
patterns = getOrModifyFilePatternsFor('text/x-haskell', 'x-haskell', ['.hs'])
|
||||||
lPatterns = getOrModifyFilePatternsFor('text/x-literate-haskell', 'literate-haskell', ['.lhs'])
|
lPatterns = getOrModifyFilePatternsFor('text/x-literate-haskell', 'literate-haskell', ['.lhs'])
|
||||||
|
|
||||||
@@ -217,8 +204,7 @@ def main():
|
|||||||
invokeMenuItem("File", "Recent Files", "(&\\d \| )?%s" % recentFile)
|
invokeMenuItem("File", "Recent Files", "(&\\d \| )?%s" % recentFile)
|
||||||
editor = getEditorForFileSuffix(current)
|
editor = getEditorForFileSuffix(current)
|
||||||
display = displayHintForHighlighterDefinition(current, patterns, lPatterns,
|
display = displayHintForHighlighterDefinition(current, patterns, lPatterns,
|
||||||
addedHighlighterDefinition,
|
addedHaskell, addedLiterateHaskell)
|
||||||
addedLiterateHighlighterDefinition)
|
|
||||||
try:
|
try:
|
||||||
waitForObject("{text='%s' type='QLabel' unnamed='1' visible='1' "
|
waitForObject("{text='%s' type='QLabel' unnamed='1' visible='1' "
|
||||||
"window=':Qt Creator_Core::Internal::MainWindow'}" % miss, 2000)
|
"window=':Qt Creator_Core::Internal::MainWindow'}" % miss, 2000)
|
||||||
@@ -237,3 +223,10 @@ def main():
|
|||||||
|
|
||||||
invokeMenuItem("File", "Save All")
|
invokeMenuItem("File", "Save All")
|
||||||
invokeMenuItem("File", "Exit")
|
invokeMenuItem("File", "Exit")
|
||||||
|
|
||||||
|
def init():
|
||||||
|
syntaxDirectory = __highlighterDefinitionsDirectory__()
|
||||||
|
if not os.path.exists(syntaxDirectory):
|
||||||
|
return
|
||||||
|
test.log("Removing existing highlighter definitions folder")
|
||||||
|
deleteDirIfExists(syntaxDirectory)
|
||||||
|
Reference in New Issue
Block a user