summaryrefslogtreecommitdiffstats
path: root/tests/CMakeLists.txt
blob: b9d60262f7b1773abafe7012ab132da87ca5513a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
add_subdirectory(libsample)
add_subdirectory(libother)

if(WIN32 OR DEFINED AVOID_PROTECTED_HACK)
    message(STATUS "Tests will be generated avoiding the protected hack!")
    set(GENERATOR_EXTRA_FLAGS --avoid-protected-hack)
else()
    message(STATUS "Tests will be generated using the protected hack!")
    set(GENERATOR_EXTRA_FLAGS )
endif()

add_subdirectory(samplebinding)
add_subdirectory(otherbinding)

file(GLOB TEST_FILES samplebinding/*_test.py otherbinding/*_test.py)

set(test_blacklist "")

find_package(PythonInterp REQUIRED)
if(NOT CTEST_TESTING_TIMEOUT)
    set(CTEST_TESTING_TIMEOUT 60)
endif()

if(CMAKE_VERSION VERSION_LESS 2.8)
    message("CMake version greater than 2.8 necessary to run tests")
else()
    if(WIN32)
        set(TEST_PYTHONPATH     "${sample_BINARY_DIR};${other_BINARY_DIR}")
        set(TEST_LIBRARY_PATH   "$ENV{PATH};${libsample_BINARY_DIR};${libother_BINARY_DIR};${libshiboken_BINARY_DIR}")
        set(LIBRARY_PATH_VAR    "PATH")
        string(REPLACE "\\" "/" TEST_PYTHONPATH "${TEST_PYTHONPATH}")
        string(REPLACE "\\" "/" TEST_LIBRARY_PATH "${TEST_LIBRARY_PATH}")
        string(REPLACE ";" "\\;" TEST_PYTHONPATH "${TEST_PYTHONPATH}")
        string(REPLACE ";" "\\;" TEST_LIBRARY_PATH "${TEST_LIBRARY_PATH}")
    else()
        set(TEST_PYTHONPATH     "${sample_BINARY_DIR}:${other_BINARY_DIR}")
        set(TEST_LIBRARY_PATH   "$ENV{LD_LIBRARY_PATH}:${libsample_BINARY_DIR}:${libother_BINARY_DIR}:${libshiboken_BINARY_DIR}")
        set(LIBRARY_PATH_VAR    "LD_LIBRARY_PATH")
    endif()

    foreach(test_file ${TEST_FILES})
        string(REGEX MATCH "/([^/]+)_test.py" test_name ${test_file})
        list(FIND test_blacklist ${CMAKE_MATCH_1} expect_fail)
        add_test(${CMAKE_MATCH_1} ${PYTHON_EXECUTABLE} ${test_file})
        set_tests_properties(${CMAKE_MATCH_1} PROPERTIES ENVIRONMENT "PYTHONPATH=${TEST_PYTHONPATH};${LIBRARY_PATH_VAR}=${TEST_LIBRARY_PATH}")
        set_tests_properties(${CMAKE_MATCH_1} PROPERTIES TIMEOUT ${CTEST_TESTING_TIMEOUT})
        if (${expect_fail} GREATER -1)
            set_tests_properties(${CMAKE_MATCH_1} PROPERTIES WILL_FAIL TRUE)
        endif()
    endforeach()
endif()