From 4599f3c12a8dde52413214aeea92ee0a22289e75 Mon Sep 17 00:00:00 2001 From: Brendan Le Foll Date: Tue, 7 Apr 2015 23:38:48 +0100 Subject: [PATCH] tests: add cmake ctest infrastructure so `make test` can run Signed-off-by: Brendan Le Foll --- CMakeLists.txt | 18 ++++++++++++++---- src/python/CMakeLists.txt | 7 ------- tests/CMakeLists.txt | 18 ++++++------------ 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8597080..9660201 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,7 +49,6 @@ set (CMAKE_SWIG_FLAGS "") find_path (SYSTEM_USR_DIR "stdlib.h") include_directories (${SYSTEM_USR_DIR}) -option (GTEST "Build all gtests." OFF) option (BUILDDOC "Build all doc." OFF) option (BUILDSWIG "Build swig modules." ON) option (BUILDSWIGPYTHON "Build swig python modules." ON) @@ -58,6 +57,7 @@ option (IPK "Generate IPK using CPack" OFF) option (BUILDPYTHON3 "Use python3 for building/installing" OFF) option (INSTALLGPIOTOOL "Install gpio tool" OFF) option (BUILDARCH "Override architecture to build for - override" OFF) +option (TESTS "Override the addition of tests" ON) if (NOT BUILDARCH) include (TargetArch) @@ -77,9 +77,19 @@ else () message(FATAL_ERROR "Only x86 and arm platforms currently supported") endif() -if (GTEST) - enable_testing () - add_subdirectory (tests) +if (BUILDSWIGPYTHON) + if (BUILDPYTHON3) + set (PYTHONBUILD_VERSION 3) + else () + set (PYTHONBUILD_VERSION 2.7) + endif () + find_package (PythonInterp ${PYTHONBUILD_VERSION} REQUIRED) + if (TESTS) + if (${PYTHONINTERP_FOUND}) + enable_testing () + add_subdirectory (tests) + endif () + endif () endif () if (BUILDDOC) diff --git a/src/python/CMakeLists.txt b/src/python/CMakeLists.txt index 9eb7c13..9b9fd8e 100644 --- a/src/python/CMakeLists.txt +++ b/src/python/CMakeLists.txt @@ -1,11 +1,4 @@ -if (BUILDPYTHON3) - set (PYTHONBUILD_VERSION 3) -else () - set (PYTHONBUILD_VERSION 2.7) -endif () - find_package (PythonLibs ${PYTHONBUILD_VERSION} REQUIRED) -find_package (PythonInterp ${PYTHONBUILD_VERSION} REQUIRED) INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH}) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 8b079db..273b46d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,15 +1,9 @@ -find_package (GTest REQUIRED) +add_test (NAME py_general COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/general_checks.py) +set_tests_properties(py_general PROPERTIES ENVIRONMENT "PYTHONPATH=${CMAKE_BINARY_DIR}/src/python/") -set(PROJECT_TEST_NAME "${PROJECT_NAME}_test") +add_test (NAME py_platform COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/platform_checks.py) +set_tests_properties(py_platform PROPERTIES ENVIRONMENT "PYTHONPATH=${CMAKE_BINARY_DIR}/src/python/") -include_directories( - ${GTEST_INCLUDE_DIRS} - ${PROJECT_SOURCE_DIR}/api - ${PROJECT_SOURCE_DIR}/include -) +add_test (NAME py_gpio COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/gpio_checks.py) +set_tests_properties(py_gpio PROPERTIES ENVIRONMENT "PYTHONPATH=${CMAKE_BINARY_DIR}/src/python/") -add_executable(${PROJECT_TEST_NAME} "mraa_test.cxx") - -target_link_libraries(${PROJECT_TEST_NAME} ${PROJECT_NAME_STR} ${GTEST_BOTH_LIBRARIES} mraa pthread) - -add_test(Basic ${PROJECT_TEST_NAME}) -- 2.7.4