Add option for passing command line test arguments
Command line arguments can be passed to the test binaries by the ARGS
argument of unit_test_add_suite function or by the
UNIT_TEST_COMMON_ARGS global variable.
Signed-off-by: Imre Kis <imre.kis@arm.com>
Change-Id: Ie10072eca670db3e3b3cb6f4109ab1e667d88a36
diff --git a/cmake/UnitTest.cmake b/cmake/UnitTest.cmake
index 27ce31d..4f0594a 100644
--- a/cmake/UnitTest.cmake
+++ b/cmake/UnitTest.cmake
@@ -72,6 +72,10 @@
Lists of source files that are included in all test builds.
+.. cmake:variable:: UNIT_TEST_COMMON_ARGS
+
+Common command line arguments for every test binary
+
Functions
^^^^^^^^^
@@ -92,6 +96,7 @@
set(CPICKER_CACHE_PATH ${CMAKE_CURRENT_BINARY_DIR}/cpicker_cache CACHE PATH "Directory of c-picker generated file")
set(UNIT_TEST_COMMON_SOURCES ${CMAKE_CURRENT_LIST_DIR}/../common/main.cpp CACHE STRING "List of common test source files")
+set(UNIT_TEST_COMMON_ARGS "" CACHE STRING "Common command line arguments for every test run")
if (POSITION_INDEPENDENT_CODE)
string(APPEND CPPUTEST_CXX_FLAGS -fPIC " " -pie)
@@ -211,6 +216,7 @@
INCLUDE_DIRECTORIES include_directories
COMPILE_DEFINITIONS defines
DEPENDS dependencies
+ ARGS arguments
)
The ``unit_test_add_suite`` CMake function provides a convenient interface for
@@ -253,6 +259,9 @@
``DEPENDS`` (multi, optional)
Extra targets as dependencies of the test build
+ ``ARGS`` (multi, optional)
+ Extra command line arguments for the test binary
+
Global dependencies:
``UNIT_TEST_PROJECT_PATH``
@@ -264,6 +273,9 @@
``UNIT_TEST_COMMON_SOURCES``
Common source files for every test build
+ ``UNIT_TEST_COMMON_ARGS``
+ Common command line arguments for every test binary
+
``CTest``
Built-in testing module of CMake
@@ -271,7 +283,7 @@
function(unit_test_add_suite)
set(_OPTIONS_ARGS)
set(_ONE_VALUE_ARGS NAME)
- set(_MULTI_VALUE_ARGS SOURCES INCLUDE_DIRECTORIES COMPILE_DEFINITIONS DEPENDS)
+ set(_MULTI_VALUE_ARGS SOURCES INCLUDE_DIRECTORIES COMPILE_DEFINITIONS DEPENDS ARGS)
cmake_parse_arguments(_MY_PARAMS "${_OPTIONS_ARGS}" "${_ONE_VALUE_ARGS}" "${_MULTI_VALUE_ARGS}" ${ARGN})
if(NOT DEFINED BUILD_TESTING)
@@ -288,6 +300,7 @@
set(TEST_INCLUDE_DIRECTORIES ${_MY_PARAMS_INCLUDE_DIRECTORIES})
set(TEST_COMPILE_DEFINITIONS ${_MY_PARAMS_COMPILE_DEFINITIONS})
set(TEST_DEPENDS ${_MY_PARAMS_DEPENDS})
+ set(TEST_ARGS ${_MY_PARAMS_ARGS})
add_executable(${TEST_NAME} ${UNIT_TEST_COMMON_SOURCES})
@@ -335,5 +348,5 @@
if (TEST_DEPENDS)
add_dependencies(${TEST_NAME} ${TEST_DEPENDS})
endif()
- add_test(${TEST_NAME} ${TEST_NAME})
+ add_test(${TEST_NAME} ${TEST_NAME} ${UNIT_TEST_COMMON_ARGS} ${TEST_ARGS})
endfunction()