From 692806bb8f1d21e4fd46b3addef51c99d07f04b9 Mon Sep 17 00:00:00 2001
From: Robert Loehning <robert.loehning@nokia.com>
Date: Tue, 27 Sep 2011 11:04:12 +0200
Subject: [PATCH] Squish: Starting test cases only if needed files are present

Change-Id: I41a73ce1a4f0d0578cf59af5c69fc19f9ec11dd9
Reviewed-on: http://codereview.qt-project.org/5555
Reviewed-by: Bill King <bill.king@nokia.com>
Reviewed-by: Christian Stenger <christian.stenger@nokia.com>
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
---
 tests/system/shared/utils.py                           |  6 ++++++
 .../system/suite_general/tst_basic_cpp_support/test.py |  3 ++-
 .../system/suite_general/tst_build_speedcrunch/test.py |  3 ++-
 .../system/suite_general/tst_cmake_speedcrunch/test.py |  4 ++--
 tests/system/suite_general/tst_openqt_creator/test.py  | 10 ++++++----
 tests/system/suite_qtquick/tst_qml_editor/test.py      |  8 +++++---
 .../system/suite_qtquick/tst_qtquick_creation2/test.py |  8 +++++---
 7 files changed, 28 insertions(+), 14 deletions(-)

diff --git a/tests/system/shared/utils.py b/tests/system/shared/utils.py
index 3a58cf0aa51..abcd0310d80 100644
--- a/tests/system/shared/utils.py
+++ b/tests/system/shared/utils.py
@@ -1,5 +1,11 @@
 import tempfile, shutil, os
 
+def neededFilePresent(path):
+    found = os.path.exists(path)
+    if not found:
+        test.fatal("Missing file or directory: " + path)
+    return found
+
 def tempDir():
     Result = os.path.abspath(os.getcwd()+"/../../testing")
     if not os.path.exists(Result):
diff --git a/tests/system/suite_general/tst_basic_cpp_support/test.py b/tests/system/suite_general/tst_basic_cpp_support/test.py
index 26061e05e4a..87116d6c2aa 100644
--- a/tests/system/suite_general/tst_basic_cpp_support/test.py
+++ b/tests/system/suite_general/tst_basic_cpp_support/test.py
@@ -1,7 +1,8 @@
 source("../../shared/qtcreator.py")
 
 def main():
-    test.verify(os.path.exists(srcPath + "/creator/tests/manual/cplusplus-tools/cplusplus-tools.pro"))
+    if not neededFilePresent(srcPath + "/creator/tests/manual/cplusplus-tools/cplusplus-tools.pro"):
+        return
 
     startApplication("qtcreator" + SettingsPath)
 
diff --git a/tests/system/suite_general/tst_build_speedcrunch/test.py b/tests/system/suite_general/tst_build_speedcrunch/test.py
index 1ee7e6c8be6..e57c6a124bf 100644
--- a/tests/system/suite_general/tst_build_speedcrunch/test.py
+++ b/tests/system/suite_general/tst_build_speedcrunch/test.py
@@ -4,7 +4,8 @@ import re;
 SpeedCrunchPath = ""
 
 def main():
-    test.verify(os.path.exists(SpeedCrunchPath))
+    if not neededFilePresent(SpeedCrunchPath):
+        return
     startApplication("qtcreator" + SettingsPath)
     openQmakeProject(SpeedCrunchPath)
     waitForSignal("{type='CppTools::Internal::CppModelManager' unnamed='1'}", "sourceFilesRefreshed(QStringList)", 30000)
diff --git a/tests/system/suite_general/tst_cmake_speedcrunch/test.py b/tests/system/suite_general/tst_cmake_speedcrunch/test.py
index 57c40ddb64b..bd94315a968 100644
--- a/tests/system/suite_general/tst_cmake_speedcrunch/test.py
+++ b/tests/system/suite_general/tst_cmake_speedcrunch/test.py
@@ -6,8 +6,8 @@ def main():
     if(which("cmake") == None):
         test.fatal("cmake not found")
         return
-
-    test.verify(os.path.exists(SpeedCrunchPath))
+    if not neededFilePresent(SpeedCrunchPath):
+        return
 
     startApplication("qtcreator" + SettingsPath)
 
diff --git a/tests/system/suite_general/tst_openqt_creator/test.py b/tests/system/suite_general/tst_openqt_creator/test.py
index b880c44f827..567cacc88e8 100644
--- a/tests/system/suite_general/tst_openqt_creator/test.py
+++ b/tests/system/suite_general/tst_openqt_creator/test.py
@@ -1,13 +1,15 @@
 source("../../shared/qtcreator.py")
 
 def main():
-    test.verify(os.path.exists(srcPath + "/creator/qtcreator.pro"))
-    test.verify(os.path.exists(srcPath + "/creator-test-data/speedcrunch/src/speedcrunch.pro"))
+    pathCreator = srcPath + "/creator/qtcreator.pro"
+    pathSpeedcrunch = srcPath + "/creator-test-data/speedcrunch/src/speedcrunch.pro"
+    if not neededFilePresent(pathCreator) or not neededFilePresent(pathSpeedcrunch):
+        return
 
     startApplication("qtcreator" + SettingsPath)
 
-    openQmakeProject(srcPath + "/creator/qtcreator.pro")
-    openQmakeProject(srcPath + "/creator-test-data/speedcrunch/src/speedcrunch.pro")
+    openQmakeProject(pathCreator)
+    openQmakeProject(pathSpeedcrunch)
 
     # Wait for parsing to complete
     waitForSignal("{type='CppTools::Internal::CppModelManager' unnamed='1'}", "sourceFilesRefreshed(QStringList)", 30000)
diff --git a/tests/system/suite_qtquick/tst_qml_editor/test.py b/tests/system/suite_qtquick/tst_qml_editor/test.py
index 488836b73b4..939b72020f8 100644
--- a/tests/system/suite_qtquick/tst_qml_editor/test.py
+++ b/tests/system/suite_qtquick/tst_qml_editor/test.py
@@ -5,10 +5,13 @@ templateDir = None
 
 def main():
     global workingDir,templateDir
+    sourceExample = os.path.abspath(sdkPath + "/Examples/4.7/declarative/keyinteraction/focus")
+    if not neededFilePresent(sourceExample):
+        return
     startApplication("qtcreator" + SettingsPath)
     # using a temporary directory won't mess up an eventually exisiting
     workingDir = tempDir()
-    prepareTemplate()
+    prepareTemplate(sourceExample)
     createNewQtQuickApplication()
     # wait for parsing to complete
     waitForSignal("{type='CppTools::Internal::CppModelManager' unnamed='1'}", "sourceFilesRefreshed(QStringList)", 30000)
@@ -16,11 +19,10 @@ def main():
 
     invokeMenuItem("File", "Exit")
 
-def prepareTemplate():
+def prepareTemplate(sourceExample):
     global templateDir
     templateDir = tempDir()
     templateDir = os.path.abspath(templateDir + "/template")
-    sourceExample = os.path.abspath(sdkPath + "/Examples/4.7/declarative/keyinteraction/focus")
     shutil.copytree(sourceExample, templateDir)
 
 def createNewQtQuickApplication():
diff --git a/tests/system/suite_qtquick/tst_qtquick_creation2/test.py b/tests/system/suite_qtquick/tst_qtquick_creation2/test.py
index 780fd0afcc3..87a9fcea0c5 100644
--- a/tests/system/suite_qtquick/tst_qtquick_creation2/test.py
+++ b/tests/system/suite_qtquick/tst_qtquick_creation2/test.py
@@ -5,10 +5,13 @@ templateDir = None
 
 def main():
     global workingDir,templateDir
+    sourceExample = os.path.abspath(sdkPath + "/Examples/4.7/declarative/text/textselection")
+    if not neededFilePresent(sourceExample):
+        return
     startApplication("qtcreator" + SettingsPath)
     # using a temporary directory won't mess up an eventually exisiting
     workingDir = tempDir()
-    prepareTemplate()
+    prepareTemplate(sourceExample)
     createNewQtQuickApplication()
     # wait for parsing to complete
     waitForSignal("{type='CppTools::Internal::CppModelManager' unnamed='1'}", "sourceFilesRefreshed(QStringList)", 30000)
@@ -22,11 +25,10 @@ def main():
         logApplicationOutput()
     invokeMenuItem("File", "Exit")
 
-def prepareTemplate():
+def prepareTemplate(sourceExample):
     global templateDir
     templateDir = tempDir()
     templateDir = os.path.abspath(templateDir + "/template")
-    sourceExample = os.path.abspath(sdkPath + "/Examples/4.7/declarative/text/textselection")
     shutil.copytree(sourceExample, templateDir)
 
 def createNewQtQuickApplication():
-- 
GitLab