From 24e7b64b89f38f264424c1e178686a7918969993 Mon Sep 17 00:00:00 2001 From: "Kevin M. Godby" Date: Fri, 17 Jun 2016 00:55:05 -0500 Subject: [PATCH 1/3] Added header-dependency tests. --- CMakeLists.txt | 11 ++++- tests/CMakeLists.txt | 19 ++++++++ tests/header_dependencies/CMakeLists.txt | 58 ++++++++++++++++++++++++ tests/header_dependencies/main.c | 7 +++ tests/header_dependencies/main.cpp | 4 ++ 5 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 tests/CMakeLists.txt create mode 100644 tests/header_dependencies/CMakeLists.txt create mode 100644 tests/header_dependencies/main.c create mode 100644 tests/header_dependencies/main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index f11d7327..25f2ebcf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) add_library(spdlog INTERFACE) option(SPDLOG_BUILD_EXAMPLES "Build examples" OFF) +option(SPDLOG_BUILD_TESTS "Build tests" OFF) target_include_directories( spdlog @@ -20,9 +21,15 @@ target_include_directories( "$" ) +set(HEADER_BASE "${CMAKE_CURRENT_SOURCE_DIR}/include") + +include(CTest) if(SPDLOG_BUILD_EXAMPLES) - enable_testing() - add_subdirectory(example) + add_subdirectory(example) +endif() + +if(SPDLOG_BUILD_TESTS) + add_subdirectory(tests) endif() ### Install ### diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 00000000..307ddeb6 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,19 @@ +# +# Tests +# + +enable_testing() + +# Build Catch unit tests +add_library(catch INTERFACE) +target_include_directories(catch INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) + +file(GLOB catch_tests LIST_DIRECTORIES false RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) +add_executable(catch_tests ${catch_tests}) +target_link_libraries(catch_tests spdlog) +add_test(NAME catch_tests COMMAND catch_tests) +file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/logs") + +# Ensure headers include their own dependencies +add_subdirectory(header_dependencies) + diff --git a/tests/header_dependencies/CMakeLists.txt b/tests/header_dependencies/CMakeLists.txt new file mode 100644 index 00000000..81779694 --- /dev/null +++ b/tests/header_dependencies/CMakeLists.txt @@ -0,0 +1,58 @@ +# +# Ensure all headers include all dependencies +# + +set(IGNORED_HEADERS "") + +set(COMMON_TEST_LIBRARIES spdlog) + +add_custom_target(header_dependencies) + +file(GLOB_RECURSE headers RELATIVE "${HEADER_BASE}" ${HEADER_BASE}/*.h) +set(test_index 0) +foreach(HEADER ${headers}) + # Sample of relevant variables computed here + # HEADER: details/line_logger_impl.h + # symbolname: spdlog_details_line_logger_impl + + # Compute symbolname + string(REPLACE ".h" "" symbolname "${HEADER}") + string(MAKE_C_IDENTIFIER "${symbolname}" symbolname) + + list(FIND IGNORED_HEADERS "${HEADER}" _index) + # If we didn't explicitly ignore this and if we built this target + if(${_index} EQUAL -1) + #message(STATUS "${HEADER}: '${symbolname}'") + + set(extension cpp) + + # Name the test and output file with a number, to dodge Windows path length limits. + # Call it header, instead of test, to avoid polluting the 'executable namespace' + set(test_name "header_${extension}_${test_index}") + + set(source_file "${CMAKE_CURRENT_SOURCE_DIR}/main.${extension}") + + add_executable(${test_name} "${source_file}") + target_compile_definitions(${test_name} PRIVATE HEADER_TO_TEST="${HEADER}") + target_include_directories(${test_name} + PRIVATE + ${BUILDTREE_HEADER_BASE} + ${HEADER_BASE}) + + set_target_properties(${test_name} PROPERTIES + FOLDER "Header dependency tests") + + target_link_libraries(${test_name} + PRIVATE + ${COMMON_TEST_LIBRARIES} + ${LIBRARIES_${symbolname}} + ${LIBRARIES_${libname}}) + + add_test(NAME ${test_name}_builds COMMAND ${test_name}) + add_dependencies(header_dependencies ${test_name}) + + math(EXPR test_index "${test_index} + 1") + endif() +endforeach() + + diff --git a/tests/header_dependencies/main.c b/tests/header_dependencies/main.c new file mode 100644 index 00000000..d2b5af77 --- /dev/null +++ b/tests/header_dependencies/main.c @@ -0,0 +1,7 @@ + +#include HEADER_TO_TEST + +int main(int argc, char** argv) +{ + return 0; +} diff --git a/tests/header_dependencies/main.cpp b/tests/header_dependencies/main.cpp new file mode 100644 index 00000000..7716c88b --- /dev/null +++ b/tests/header_dependencies/main.cpp @@ -0,0 +1,4 @@ + +#include HEADER_TO_TEST + +int main(int argc, char *argv[]) { return 0; } From cb3b7728a1845e620b12151ccb40c2dfed99e48a Mon Sep 17 00:00:00 2001 From: "Kevin M. Godby" Date: Fri, 17 Jun 2016 00:55:24 -0500 Subject: [PATCH 2/3] Fix missing include detected by new header dependency tests. --- include/spdlog/sinks/stdout_sinks.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/spdlog/sinks/stdout_sinks.h b/include/spdlog/sinks/stdout_sinks.h index ca4c55ac..30c19a54 100644 --- a/include/spdlog/sinks/stdout_sinks.h +++ b/include/spdlog/sinks/stdout_sinks.h @@ -6,6 +6,7 @@ #pragma once #include +#include #include #include From 3a44818b2af2ddea564cc031c83574113ad7344c Mon Sep 17 00:00:00 2001 From: gabime Date: Sat, 18 Jun 2016 15:04:08 +0300 Subject: [PATCH 3/3] fixed pr #228 to include pthread and removed header_dependecies test --- tests/CMakeLists.txt | 9 +++- tests/header_dependencies/CMakeLists.txt | 58 ------------------------ tests/header_dependencies/main.c | 7 --- tests/header_dependencies/main.cpp | 4 -- 4 files changed, 7 insertions(+), 71 deletions(-) delete mode 100644 tests/header_dependencies/CMakeLists.txt delete mode 100644 tests/header_dependencies/main.c delete mode 100644 tests/header_dependencies/main.cpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 307ddeb6..185fb082 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -9,11 +9,16 @@ add_library(catch INTERFACE) target_include_directories(catch INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) file(GLOB catch_tests LIST_DIRECTORIES false RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) + +if (CMAKE_COMPILER_IS_GNUCXX) + set ( CMAKE_CXX_FLAGS "--std=c++11 -pthread") + set ( CMAKE_EXE_LIKKER_FLAGS "-pthread") +endif () + add_executable(catch_tests ${catch_tests}) target_link_libraries(catch_tests spdlog) add_test(NAME catch_tests COMMAND catch_tests) file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/logs") -# Ensure headers include their own dependencies -add_subdirectory(header_dependencies) + diff --git a/tests/header_dependencies/CMakeLists.txt b/tests/header_dependencies/CMakeLists.txt deleted file mode 100644 index 81779694..00000000 --- a/tests/header_dependencies/CMakeLists.txt +++ /dev/null @@ -1,58 +0,0 @@ -# -# Ensure all headers include all dependencies -# - -set(IGNORED_HEADERS "") - -set(COMMON_TEST_LIBRARIES spdlog) - -add_custom_target(header_dependencies) - -file(GLOB_RECURSE headers RELATIVE "${HEADER_BASE}" ${HEADER_BASE}/*.h) -set(test_index 0) -foreach(HEADER ${headers}) - # Sample of relevant variables computed here - # HEADER: details/line_logger_impl.h - # symbolname: spdlog_details_line_logger_impl - - # Compute symbolname - string(REPLACE ".h" "" symbolname "${HEADER}") - string(MAKE_C_IDENTIFIER "${symbolname}" symbolname) - - list(FIND IGNORED_HEADERS "${HEADER}" _index) - # If we didn't explicitly ignore this and if we built this target - if(${_index} EQUAL -1) - #message(STATUS "${HEADER}: '${symbolname}'") - - set(extension cpp) - - # Name the test and output file with a number, to dodge Windows path length limits. - # Call it header, instead of test, to avoid polluting the 'executable namespace' - set(test_name "header_${extension}_${test_index}") - - set(source_file "${CMAKE_CURRENT_SOURCE_DIR}/main.${extension}") - - add_executable(${test_name} "${source_file}") - target_compile_definitions(${test_name} PRIVATE HEADER_TO_TEST="${HEADER}") - target_include_directories(${test_name} - PRIVATE - ${BUILDTREE_HEADER_BASE} - ${HEADER_BASE}) - - set_target_properties(${test_name} PROPERTIES - FOLDER "Header dependency tests") - - target_link_libraries(${test_name} - PRIVATE - ${COMMON_TEST_LIBRARIES} - ${LIBRARIES_${symbolname}} - ${LIBRARIES_${libname}}) - - add_test(NAME ${test_name}_builds COMMAND ${test_name}) - add_dependencies(header_dependencies ${test_name}) - - math(EXPR test_index "${test_index} + 1") - endif() -endforeach() - - diff --git a/tests/header_dependencies/main.c b/tests/header_dependencies/main.c deleted file mode 100644 index d2b5af77..00000000 --- a/tests/header_dependencies/main.c +++ /dev/null @@ -1,7 +0,0 @@ - -#include HEADER_TO_TEST - -int main(int argc, char** argv) -{ - return 0; -} diff --git a/tests/header_dependencies/main.cpp b/tests/header_dependencies/main.cpp deleted file mode 100644 index 7716c88b..00000000 --- a/tests/header_dependencies/main.cpp +++ /dev/null @@ -1,4 +0,0 @@ - -#include HEADER_TO_TEST - -int main(int argc, char *argv[]) { return 0; }