2018-04-07 16:16:55 -04:00
|
|
|
# Compile and link with coverage
|
2018-04-08 18:42:15 -04:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fprofile-arcs -ftest-coverage -Wno-missing-field-initializers")
|
2018-04-07 16:16:55 -04:00
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
|
2016-06-14 23:32:35 -04:00
|
|
|
|
2017-01-26 11:17:02 -05:00
|
|
|
link_libraries(${libs})
|
|
|
|
include_directories(${dirs})
|
|
|
|
include_directories(${CMAKE_CURRENT_LIST_DIR})
|
2016-06-14 23:32:35 -04:00
|
|
|
|
2018-04-07 17:35:47 -04:00
|
|
|
# Download and unpack googletest at configure time {{{
|
|
|
|
configure_file(
|
|
|
|
CMakeLists.txt.in
|
|
|
|
${CMAKE_BINARY_DIR}/googletest-download/CMakeLists.txt
|
|
|
|
)
|
|
|
|
execute_process( COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
|
|
|
|
RESULT_VARIABLE result
|
|
|
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download)
|
|
|
|
|
|
|
|
if(result)
|
|
|
|
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
execute_process(COMMAND ${CMAKE_COMMAND} --build .
|
|
|
|
RESULT_VARIABLE result
|
|
|
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download )
|
|
|
|
|
|
|
|
if(result)
|
|
|
|
message(FATAL_ERROR "Build step for googletest failed: ${result}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Add googletest directly to our build. This defines
|
2018-04-08 11:53:13 -04:00
|
|
|
# the gtest, gtest_main, gmock and gmock_main targets.
|
2018-04-07 17:35:47 -04:00
|
|
|
add_subdirectory(${CMAKE_BINARY_DIR}/googletest-src
|
|
|
|
${CMAKE_BINARY_DIR}/googletest-build
|
|
|
|
EXCLUDE_FROM_ALL)
|
|
|
|
|
|
|
|
# }}}
|
2018-04-07 16:16:55 -04:00
|
|
|
|
2018-05-15 08:58:09 -04:00
|
|
|
# Disable errors for warnings so that we can run tests even with some warnings
|
|
|
|
string(REGEX REPLACE "-Werror[^ ]*" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
|
|
|
|
string(REPLACE "-pedantic-errors" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
|
|
|
|
|
2018-04-07 16:16:55 -04:00
|
|
|
function(unit_test file tests)
|
|
|
|
set(multi_value_args SOURCES)
|
|
|
|
|
|
|
|
cmake_parse_arguments("BIN" "" "" "${multi_value_args}" ${ARGN})
|
|
|
|
|
|
|
|
# Prefix all sources needed by the tests with ../src/ so that the calls to the
|
|
|
|
# unit_test function become cleaner
|
|
|
|
SET(sources "")
|
|
|
|
FOREACH(f ${BIN_SOURCES})
|
2018-04-28 17:18:02 -04:00
|
|
|
# Do not add main.cpp, because it will override the main function
|
|
|
|
if(NOT "${f}" STREQUAL "main.cpp")
|
|
|
|
LIST(APPEND sources "../src/${f}")
|
|
|
|
endif()
|
2018-04-07 16:16:55 -04:00
|
|
|
ENDFOREACH(f)
|
|
|
|
|
2016-10-24 19:47:00 -04:00
|
|
|
string(REPLACE "/" "_" testname ${file})
|
2018-04-07 16:16:55 -04:00
|
|
|
set(name "unit_test.${testname}")
|
|
|
|
add_executable(${name} unit_tests/${file}.cpp ${sources})
|
|
|
|
|
2018-04-08 11:53:13 -04:00
|
|
|
# Link against gmock (this automatically links against gtest)
|
|
|
|
target_link_libraries(${name} gmock_main)
|
2018-04-07 16:16:55 -04:00
|
|
|
|
|
|
|
add_test(NAME ${name} COMMAND ${name})
|
|
|
|
|
|
|
|
# Add test to list of unit tests
|
|
|
|
list(APPEND ${tests} "${name}")
|
|
|
|
set(${tests} ${${tests}} PARENT_SCOPE)
|
2016-10-24 19:47:00 -04:00
|
|
|
endfunction()
|
2016-06-14 23:32:35 -04:00
|
|
|
|
2018-04-07 16:16:55 -04:00
|
|
|
unit_test(utils/color unit_tests)
|
2018-05-15 08:58:09 -04:00
|
|
|
|
2018-04-07 16:16:55 -04:00
|
|
|
unit_test(utils/math unit_tests)
|
2018-05-15 08:58:09 -04:00
|
|
|
|
2018-04-07 16:16:55 -04:00
|
|
|
unit_test(utils/memory unit_tests)
|
2018-05-15 08:58:09 -04:00
|
|
|
|
2018-05-01 11:40:11 -04:00
|
|
|
unit_test(utils/scope unit_tests)
|
2018-05-15 08:58:09 -04:00
|
|
|
|
2018-04-07 16:16:55 -04:00
|
|
|
unit_test(utils/string unit_tests
|
|
|
|
SOURCES
|
|
|
|
utils/string.cpp)
|
2018-05-15 08:58:09 -04:00
|
|
|
|
2018-04-07 16:16:55 -04:00
|
|
|
unit_test(utils/file unit_tests
|
|
|
|
SOURCES
|
|
|
|
utils/command.cpp
|
|
|
|
utils/file.cpp
|
|
|
|
utils/env.cpp
|
|
|
|
utils/process.cpp
|
|
|
|
utils/io.cpp
|
|
|
|
utils/string.cpp
|
|
|
|
utils/concurrency.cpp
|
|
|
|
components/logger.cpp)
|
|
|
|
unit_test(components/command_line unit_tests
|
|
|
|
SOURCES
|
|
|
|
components/command_line.cpp
|
|
|
|
utils/string.cpp)
|
2018-05-15 08:58:09 -04:00
|
|
|
|
2018-05-06 11:52:06 -04:00
|
|
|
unit_test(components/bar unit_tests)
|
2016-11-20 18:07:34 -05:00
|
|
|
|
2018-04-28 17:18:02 -04:00
|
|
|
unit_test(components/builder unit_tests
|
|
|
|
SOURCES
|
|
|
|
${files})
|
|
|
|
|
2018-04-07 16:16:55 -04:00
|
|
|
# Compile all unit tests with 'make all_unit_tests'
|
|
|
|
add_custom_target("all_unit_tests" DEPENDS ${unit_tests})
|