summaryrefslogtreecommitdiffstats
path: root/tests/CMakeLists.txt
diff options
context:
space:
mode:
authorGravatar Jeremie Guichard <djebrest@gmail.com>2017-02-25 22:52:22 +0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2017-02-25 09:24:23 -0800
commit08bc1edc8189a3eab14bb7193abf5270dfe6d235 (patch)
tree915f59ef562f317336edf2ed661ded187818d8e8 /tests/CMakeLists.txt
parente418bb7e28d958798e43804c12f311a3e6b83720 (diff)
downloadsubsurface-08bc1edc8189a3eab14bb7193abf5270dfe6d235.tar.gz
Improve install and test rules for Windows test execution
Update install rules to create a staging_tests folder for easy deployment to test target. Update test rules for compile time testing when wine is available on build machine. Signed-off-by: Jeremie Guichard <djebrest@gmail.com>
Diffstat (limited to 'tests/CMakeLists.txt')
-rw-r--r--tests/CMakeLists.txt64
1 files changed, 61 insertions, 3 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 9336424eb..3d8d19f7a 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -5,20 +5,78 @@ qt5_add_resources(SUBSURFACE_TEST_RESOURCES ../subsurface.qrc)
# In cross compilation cases or when test will not be executed at build time
# a differnt value can be set via cmake -DSUBSURFACE_TEST_DATA.
if(NOT SUBSURFACE_TEST_DATA)
- set(SUBSURFACE_TEST_DATA ${SUBSURFACE_SOURCE})
+ if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
+ # For windows case we expect tests to be executed
+ # with WORKING_DIRECTORY pointing to folder where test data can be found
+ set(SUBSURFACE_TEST_DATA .)
+ else()
+ set(SUBSURFACE_TEST_DATA ${SUBSURFACE_SOURCE})
+ endif()
endif()
add_library(RESOURCE_LIBRARY STATIC ${SUBSURFACE_TEST_RESOURCES})
+if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
+
+ # Prepare a staging_tests folder
+ # Test can run accessing data and dependecies for build time testing
+ # or can be deployed for target testing
+ # It inludes:
+ # - test data
+ # - test binaries (see TEST macro)
+ # - test binaries dependencies (see TEST macro)
+ set(WINDOWS_STAGING_TESTS ${CMAKE_BINARY_DIR}/staging_tests)
+ install(DIRECTORY ${SUBSURFACE_SOURCE}/dives DESTINATION ${WINDOWS_STAGING_TESTS})
+ install(FILES ${SUBSURFACE_SOURCE}/wreck.jpg DESTINATION ${WINDOWS_STAGING_TESTS})
+
+ # Check if we can run tests locally using wine
+ # Add a fake test used to ensure data is deployed to WINDOWS_STAGING_TESTS before running
+ find_program(WINE_PROGRAM wine)
+ if(WINE_PROGRAM)
+ add_test(
+ NAME InstallTestsDataAndDependencies
+ COMMAND "${CMAKE_COMMAND}" --build ${CMAKE_CURRENT_BINARY_DIR} --target install
+ )
+ endif()
+endif()
+
+# Helper macro TEST used to created rules to build, link, install and run tests
macro(TEST NAME FILE)
add_executable(${NAME} ${FILE} )
- target_link_libraries(${NAME} subsurface_corelib RESOURCE_LIBRARY ${QT_TEST_LIBRARIES} ${SUBSURFACE_LINK_LIBRARIES} )
- add_test(NAME ${NAME} COMMAND $<TARGET_FILE:${NAME}>)
+ target_link_libraries(
+ ${NAME}
+ subsurface_corelib
+ RESOURCE_LIBRARY
+ ${QT_TEST_LIBRARIES}
+ ${SUBSURFACE_LINK_LIBRARIES}
+ )
+
+ if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
+ # Re-install dependencies in WINDOWS_STAGING_TESTS (and not in WINDOWSSTAGING)
+ # to avoid packing testing related dlls in the installer
+ install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DSUBSURFACE_TARGET=${NAME} -DSUBSURFACE_SOURCE=${SUBSURFACE_SOURCE} -DSTAGING=${WINDOWS_STAGING_TESTS} -P ${CMAKE_SOURCE_DIR}/cmake/Modules/dlllist.cmake)")
+
+ # Run test using wine
+ if(WINE_PROGRAM)
+ add_test(
+ NAME ${NAME}
+ COMMAND "$<TARGET_FILE:${NAME}>"
+ WORKING_DIRECTORY ${WINDOWS_STAGING_TESTS}
+ )
+ # Set WINEPATH (%PATH%) to WINDOWS_STAGING_TESTS allowing wine to find dlls
+ # WINEDEBUG=-all is used to avoid anoying winde debug outputs
+ set_tests_properties(${NAME} PROPERTIES ENVIRONMENT "WINEPATH=${WINDOWS_STAGING_TESTS};WINEDEBUG=-all")
+ set_tests_properties(${NAME} PROPERTIES DEPENDS PrepareTests)
+ endif()
+ else()
+ add_test(NAME ${NAME} COMMAND $<TARGET_FILE:${NAME}>)
+ endif()
endmacro()
enable_testing()
add_definitions(-g)
add_definitions(-DSUBSURFACE_TEST_DATA="${SUBSURFACE_TEST_DATA}")
+
TEST(TestUnitConversion testunitconversion.cpp)
TEST(TestProfile testprofile.cpp)
TEST(TestGpsCoords testgpscoords.cpp)