FindSquish.cmake 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file LICENSE.rst or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FindSquish
  5. ----------
  6. Finds Squish, a cross-platform automated GUI testing framework for
  7. applications built on various GUI technologies:
  8. .. code-block:: cmake
  9. find_package(Squish [<version>] [...])
  10. Squish supports testing of both native and cross-platform toolkits, such as
  11. Qt, Java, and Tk.
  12. Result Variables
  13. ^^^^^^^^^^^^^^^^
  14. This module defines the following variables:
  15. ``Squish_FOUND``
  16. Boolean indicating whether (the requested version of) Squish is found.
  17. For backward compatibility, the ``SQUISH_FOUND`` variable is also set to
  18. the same value.
  19. ``Squish_VERSION``
  20. .. versionadded:: 4.2
  21. The full version of the Squish found.
  22. ``SQUISH_INSTALL_DIR_FOUND``
  23. Boolean indicating whether the Squish installation directory is found.
  24. ``SQUISH_SERVER_EXECUTABLE_FOUND``
  25. Boolean indicating whether the Squish server executable is found.
  26. ``SQUISH_CLIENT_EXECUTABLE_FOUND``
  27. Boolean indicating whether the Squish client executable is found.
  28. Cache Variables
  29. ^^^^^^^^^^^^^^^
  30. The following cache variables may also be set:
  31. ``SQUISH_INSTALL_DIR``
  32. The Squish installation directory containing ``bin``, ``lib``, etc.
  33. ``SQUISH_SERVER_EXECUTABLE``
  34. The path to the ``squishserver`` executable.
  35. ``SQUISH_CLIENT_EXECUTABLE``
  36. The path to the ``squishrunner`` executable.
  37. Commands
  38. ^^^^^^^^
  39. This module provides the following commands, if Squish is found:
  40. .. command:: squish_add_test
  41. Adds a Squish test to the project:
  42. .. code-block:: cmake
  43. squish_add_test(
  44. <name>
  45. AUT <target>
  46. SUITE <suite-name>
  47. TEST <squish-test-case-name>
  48. [PRE_COMMAND <command>]
  49. [POST_COMMAND <command>]
  50. [SETTINGSGROUP <group>]
  51. )
  52. This command is built on top of the :command:`add_test` command and adds a
  53. Squish test called ``<name>`` to the CMake project. It supports Squish
  54. versions 4 and newer.
  55. During the CMake testing phase, the Squish server is started, the test is
  56. executed on the client, and the server is stopped once the test completes. If
  57. any of these steps fail (including if the test itself fails), a fatal error is
  58. raised indicating the test did not pass.
  59. The arguments are:
  60. ``<name>``
  61. The name of the test. This is passed as the first argument to the
  62. :command:`add_test` command.
  63. ``AUT <target>``
  64. The name of the CMake target to be used as the AUT (Application Under Test),
  65. i.e., the executable that will be tested.
  66. ``SUITE <suite-name>``
  67. Either the full path to the Squish test suite or just the suite name (i.e.,
  68. the last directory name of the suite). In the latter case, the
  69. ``CMakeLists.txt`` invoking ``squish_add_test()`` must reside in the parent
  70. directory of the suite.
  71. ``TEST <squish-test-case-name>``
  72. The name of the Squish test, corresponding to the subdirectory of the test
  73. within the suite directory.
  74. ``PRE_COMMAND <command>``
  75. An optional command to execute before starting the Squish test. Pass it as
  76. a string. This may be a single command, or a :ref:`semicolon-separated list
  77. <CMake Language Lists>` of command and arguments.
  78. ``POST_COMMAND <command>``
  79. An optional command to execute after the Squish test has completed. Pass it
  80. as a string. This may be a single command, or a :ref:`semicolon-separated
  81. list <CMake Language Lists>` of command and arguments.
  82. ``SETTINGSGROUP <group>``
  83. .. deprecated:: 3.18
  84. This argument is now ignored. It was previously used to specify a
  85. settings group name for executing the test instead of the default value
  86. ``CTest_<username>``.
  87. .. versionchanged:: 3.18
  88. In previous CMake versions, this command was named ``squish_v4_add_test()``.
  89. .. command:: squish_v3_add_test
  90. Adds a Squish test to the project, when using Squish version 3.x:
  91. .. code-block:: cmake
  92. squish_v3_add_test(
  93. <test-name>
  94. <application-under-test>
  95. <squish-test-case-name>
  96. <environment-variables>
  97. <test-wrapper>
  98. )
  99. .. note::
  100. This command is for Squish version 3, which is not maintained anymore. Use
  101. a newer Squish version, and ``squish_add_test()`` command.
  102. The arguments are:
  103. ``<name>``
  104. The name of the test.
  105. ``<application-under-test>``
  106. The path to the executable used as the AUT (Application Under Test), i.e.,
  107. the executable that will be tested.
  108. ``<squish-test-case-name>``
  109. The name of the Squish test, corresponding to the subdirectory of the test
  110. within the suite directory.
  111. ``<environment-variables>``
  112. A semicolon-separated list of environment variables and their values
  113. (VAR=VALUE).
  114. ``<test-wrapper>``
  115. A string of one or more (semicolon-separated list) test wrappers needed by
  116. the test case.
  117. Deprecated Variables
  118. ^^^^^^^^^^^^^^^^^^^^
  119. The following variables are provided for backward compatibility:
  120. ``SQUISH_VERSION``
  121. .. deprecated:: 4.2
  122. Superseded by the ``Squish_VERSION``.
  123. The full version of the Squish found.
  124. ``SQUISH_VERSION_MAJOR``
  125. .. deprecated:: 4.2
  126. Superseded by the ``Squish_VERSION``.
  127. The major version of the Squish found.
  128. ``SQUISH_VERSION_MINOR``
  129. .. deprecated:: 4.2
  130. Superseded by the ``Squish_VERSION``.
  131. The minor version of the Squish found.
  132. ``SQUISH_VERSION_PATCH``
  133. .. deprecated:: 4.2
  134. Superseded by the ``Squish_VERSION``.
  135. The patch version of the Squish found.
  136. Examples
  137. ^^^^^^^^
  138. Finding Squish and specifying a minimum required version:
  139. .. code-block:: cmake
  140. find_package(Squish 6.5)
  141. Adding a Squish test:
  142. .. code-block:: cmake
  143. enable_testing()
  144. find_package(Squish 6.5)
  145. if(Squish_FOUND)
  146. squish_add_test(
  147. projectTestName
  148. AUT projectApp
  149. SUITE ${CMAKE_CURRENT_SOURCE_DIR}/tests/projectSuite
  150. TEST someSquishTest
  151. )
  152. endif()
  153. Example, how to use the ``squish_v3_add_test()`` command:
  154. .. code-block:: cmake
  155. enable_testing()
  156. find_package(Squish 3.0)
  157. if(Squish_FOUND)
  158. squish_v3_add_test(
  159. projectTestName
  160. $<TARGET_FILE:projectApp>
  161. someSquishTest
  162. "FOO=1;BAR=2"
  163. testWrapper
  164. )
  165. endif()
  166. #]=======================================================================]
  167. set(SQUISH_INSTALL_DIR_STRING "Directory containing the bin, doc, and lib directories for Squish; this should be the root of the installation directory.")
  168. set(SQUISH_SERVER_EXECUTABLE_STRING "The squishserver executable program.")
  169. set(SQUISH_CLIENT_EXECUTABLE_STRING "The squishclient executable program.")
  170. # Search only if the location is not already known.
  171. if(NOT SQUISH_INSTALL_DIR)
  172. # Get the system search path as a list.
  173. file(TO_CMAKE_PATH "$ENV{PATH}" SQUISH_INSTALL_DIR_SEARCH2)
  174. # Construct a set of paths relative to the system search path.
  175. set(SQUISH_INSTALL_DIR_SEARCH "")
  176. foreach(dir ${SQUISH_INSTALL_DIR_SEARCH2})
  177. set(SQUISH_INSTALL_DIR_SEARCH ${SQUISH_INSTALL_DIR_SEARCH} "${dir}/../lib/fltk")
  178. endforeach()
  179. string(REPLACE "//" "/" SQUISH_INSTALL_DIR_SEARCH "${SQUISH_INSTALL_DIR_SEARCH}")
  180. # Look for an installation
  181. find_path(SQUISH_INSTALL_DIR
  182. NAMES bin/squishrunner bin/squishrunner.exe
  183. HINTS
  184. # Look for an environment variable SQUISH_INSTALL_DIR.
  185. ENV SQUISH_INSTALL_DIR
  186. # Look in places relative to the system executable search path.
  187. ${SQUISH_INSTALL_DIR_SEARCH}
  188. DOC "The ${SQUISH_INSTALL_DIR_STRING}"
  189. )
  190. endif()
  191. # search for the executables
  192. if(SQUISH_INSTALL_DIR)
  193. set(SQUISH_INSTALL_DIR_FOUND 1)
  194. # find the client program
  195. if(NOT SQUISH_CLIENT_EXECUTABLE)
  196. find_program(SQUISH_CLIENT_EXECUTABLE ${SQUISH_INSTALL_DIR}/bin/squishrunner${CMAKE_EXECUTABLE_SUFFIX} DOC "The ${SQUISH_CLIENT_EXECUTABLE_STRING}")
  197. endif()
  198. # find the server program
  199. if(NOT SQUISH_SERVER_EXECUTABLE)
  200. find_program(SQUISH_SERVER_EXECUTABLE ${SQUISH_INSTALL_DIR}/bin/squishserver${CMAKE_EXECUTABLE_SUFFIX} DOC "The ${SQUISH_SERVER_EXECUTABLE_STRING}")
  201. endif()
  202. else()
  203. set(SQUISH_INSTALL_DIR_FOUND 0)
  204. endif()
  205. unset(Squish_VERSION)
  206. unset(SQUISH_VERSION)
  207. unset(SQUISH_VERSION_MAJOR)
  208. unset(SQUISH_VERSION_MINOR)
  209. unset(SQUISH_VERSION_PATCH)
  210. # record if executables are set
  211. if(SQUISH_CLIENT_EXECUTABLE)
  212. set(SQUISH_CLIENT_EXECUTABLE_FOUND 1)
  213. execute_process(COMMAND "${SQUISH_CLIENT_EXECUTABLE}" --version
  214. OUTPUT_VARIABLE _squishVersionOutput
  215. ERROR_QUIET )
  216. if("${_squishVersionOutput}" MATCHES "([0-9]+)\\.([0-9]+)\\.([0-9]+)")
  217. set(SQUISH_VERSION_MAJOR "${CMAKE_MATCH_1}")
  218. set(SQUISH_VERSION_MINOR "${CMAKE_MATCH_2}")
  219. set(SQUISH_VERSION_PATCH "${CMAKE_MATCH_3}")
  220. set(Squish_VERSION "${SQUISH_VERSION_MAJOR}.${SQUISH_VERSION_MINOR}.${SQUISH_VERSION_PATCH}" )
  221. set(SQUISH_VERSION "${Squish_VERSION}")
  222. endif()
  223. else()
  224. set(SQUISH_CLIENT_EXECUTABLE_FOUND 0)
  225. endif()
  226. if(SQUISH_SERVER_EXECUTABLE)
  227. set(SQUISH_SERVER_EXECUTABLE_FOUND 1)
  228. else()
  229. set(SQUISH_SERVER_EXECUTABLE_FOUND 0)
  230. endif()
  231. # record if Squish was found
  232. include(FindPackageHandleStandardArgs)
  233. find_package_handle_standard_args(Squish REQUIRED_VARS SQUISH_INSTALL_DIR SQUISH_CLIENT_EXECUTABLE SQUISH_SERVER_EXECUTABLE
  234. VERSION_VAR Squish_VERSION)
  235. set(_SQUISH_MODULE_DIR "${CMAKE_CURRENT_LIST_DIR}")
  236. macro(squish_v3_add_test testName testAUT testCase envVars testWrapper)
  237. if("${SQUISH_VERSION_MAJOR}" STRGREATER "3")
  238. message(STATUS "Using squish_v3_add_test(), but SQUISH_VERSION_MAJOR is ${SQUISH_VERSION_MAJOR}.\nThis may not work.")
  239. endif()
  240. # There's no target used for this command, so we don't need to do anything
  241. # here for CMP0178.
  242. add_test(${testName}
  243. ${CMAKE_COMMAND} -V -VV
  244. "-Dsquish_version:STRING=3"
  245. "-Dsquish_aut:STRING=${testAUT}"
  246. "-Dsquish_server_executable:STRING=${SQUISH_SERVER_EXECUTABLE}"
  247. "-Dsquish_client_executable:STRING=${SQUISH_CLIENT_EXECUTABLE}"
  248. "-Dsquish_libqtdir:STRING=${QT_LIBRARY_DIR}"
  249. "-Dsquish_test_case:STRING=${testCase}"
  250. "-Dsquish_env_vars:STRING=${envVars}"
  251. "-Dsquish_wrapper:STRING=${testWrapper}"
  252. "-Dsquish_module_dir:STRING=${_SQUISH_MODULE_DIR}"
  253. -P "${_SQUISH_MODULE_DIR}/SquishTestScript.cmake"
  254. )
  255. set_tests_properties(${testName}
  256. PROPERTIES FAIL_REGULAR_EXPRESSION "FAILED;ERROR;FATAL"
  257. )
  258. endmacro()
  259. function(squish_v4_add_test testName)
  260. if(NOT "${SQUISH_VERSION_MAJOR}" STRGREATER "3")
  261. message(STATUS "Using squish_add_test(), but SQUISH_VERSION_MAJOR is ${SQUISH_VERSION_MAJOR}.\nThis may not work.")
  262. endif()
  263. set(oneValueArgs AUT SUITE TEST SETTINGSGROUP PRE_COMMAND POST_COMMAND)
  264. cmake_parse_arguments(_SQUISH "" "${oneValueArgs}" "" ${ARGN} )
  265. if(_SQUISH_UNPARSED_ARGUMENTS)
  266. message(FATAL_ERROR "Unknown keywords given to SQUISH_ADD_TEST(): \"${_SQUISH_UNPARSED_ARGUMENTS}\"")
  267. endif()
  268. if(NOT _SQUISH_AUT)
  269. message(FATAL_ERROR "Required argument AUT not given for SQUISH_ADD_TEST()")
  270. endif()
  271. if(NOT _SQUISH_SUITE)
  272. message(FATAL_ERROR "Required argument SUITE not given for SQUISH_ADD_TEST()")
  273. endif()
  274. if(NOT _SQUISH_TEST)
  275. message(FATAL_ERROR "Required argument TEST not given for SQUISH_ADD_TEST()")
  276. endif()
  277. get_filename_component(absTestSuite "${_SQUISH_SUITE}" ABSOLUTE)
  278. if(NOT EXISTS "${absTestSuite}")
  279. message(FATAL_ERROR "Could not find squish test suite ${_SQUISH_SUITE} (checked ${absTestSuite})")
  280. endif()
  281. set(absTestCase "${absTestSuite}/${_SQUISH_TEST}")
  282. if(NOT EXISTS "${absTestCase}")
  283. message(FATAL_ERROR "Could not find squish testcase ${_SQUISH_TEST} (checked ${absTestCase})")
  284. endif()
  285. if(_SQUISH_SETTINGSGROUP)
  286. message("SETTINGSGROUP is deprecated and will be ignored.")
  287. endif()
  288. # There's no target used for this command, so we don't need to do anything
  289. # here for CMP0178.
  290. add_test(NAME ${testName}
  291. COMMAND ${CMAKE_COMMAND} -V -VV
  292. "-Dsquish_version:STRING=4"
  293. "-Dsquish_aut:STRING=$<TARGET_FILE_BASE_NAME:${_SQUISH_AUT}>"
  294. "-Dsquish_aut_dir:STRING=$<TARGET_FILE_DIR:${_SQUISH_AUT}>"
  295. "-Dsquish_server_executable:STRING=${SQUISH_SERVER_EXECUTABLE}"
  296. "-Dsquish_client_executable:STRING=${SQUISH_CLIENT_EXECUTABLE}"
  297. "-Dsquish_libqtdir:STRING=${QT_LIBRARY_DIR}"
  298. "-Dsquish_test_suite:STRING=${absTestSuite}"
  299. "-Dsquish_test_case:STRING=${_SQUISH_TEST}"
  300. "-Dsquish_env_vars:STRING=${envVars}"
  301. "-Dsquish_wrapper:STRING=${testWrapper}"
  302. "-Dsquish_module_dir:STRING=${_SQUISH_MODULE_DIR}"
  303. "-Dsquish_pre_command:STRING=${_SQUISH_PRE_COMMAND}"
  304. "-Dsquish_post_command:STRING=${_SQUISH_POST_COMMAND}"
  305. -P "${_SQUISH_MODULE_DIR}/SquishTestScript.cmake"
  306. )
  307. set_tests_properties(${testName}
  308. PROPERTIES FAIL_REGULAR_EXPRESSION "FAIL;FAILED;ERROR;FATAL"
  309. )
  310. endfunction()
  311. macro(squish_add_test)
  312. if("${SQUISH_VERSION_MAJOR}" STRGREATER "3")
  313. squish_v4_add_test(${ARGV})
  314. else()
  315. squish_v3_add_test(${ARGV})
  316. endif()
  317. endmacro()