From 037835320bd28d0416913d597f1f6298e8eaea00 Mon Sep 17 00:00:00 2001 From: Russell Yanofsky Date: Wed, 13 May 2020 07:18:00 -0400 Subject: [PATCH] Add "make check" target to build and run tests CTest already provides a "make test" target, but this only runs previously built tests. Also in this commit: - Move all test code and build rules to a new test/ subdirectory to separate test code from non-test code - Add a new "make tests" target used internally by "make check" to build tests without running them --- CMakeLists.txt | 47 +------------------ README.md | 4 +- test/CMakeLists.txt | 66 +++++++++++++++++++++++++++ {src => test/src}/mp/test/foo-types.h | 0 {src => test/src}/mp/test/foo.capnp | 0 {src => test/src}/mp/test/foo.h | 0 {src => test/src}/mp/test/test.cpp | 0 7 files changed, 69 insertions(+), 48 deletions(-) create mode 100644 test/CMakeLists.txt rename {src => test/src}/mp/test/foo-types.h (100%) rename {src => test/src}/mp/test/foo.capnp (100%) rename {src => test/src}/mp/test/foo.h (100%) rename {src => test/src}/mp/test/test.cpp (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2ab8536..59c92ae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,6 @@ cmake_minimum_required(VERSION 3.0) project("Libmultiprocess" CXX) include(CMakePushCheckState) -include(CTest) include(CheckCXXSourceCompiles) find_package(CapnProto REQUIRED) find_package(Threads REQUIRED) @@ -92,48 +91,4 @@ install(FILES "include/mpgen.mk" DESTINATION "include") install(EXPORT Multiprocess DESTINATION lib/cmake/Multiprocess) -if(BUILD_TESTING AND TARGET CapnProto::kj-test) - add_custom_command( - OUTPUT - src/mp/test/foo.capnp.h - src/mp/test/foo.capnp.c++ - src/mp/test/foo.capnp.proxy.h - src/mp/test/foo.capnp.proxy-server.c++ - src/mp/test/foo.capnp.proxy-client.c++ - src/mp/test/foo.capnp.proxy-types.c++ - src/mp/test/foo.capnp.proxy-types.h - COMMAND mpgen "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/src" "${CMAKE_CURRENT_SOURCE_DIR}/src/mp/test/foo.capnp" "${CMAKE_CURRENT_SOURCE_DIR}/include" "${capnp_PREFIX}/include" - DEPENDS src/mp/test/foo.capnp mpgen - ) - add_executable(mptest EXCLUDE_FROM_ALL - ${MP_PROXY_HDRS} - src/mp/test/foo.capnp.h - src/mp/test/foo.capnp.c++ - src/mp/test/foo.capnp.proxy.h - src/mp/test/foo.capnp.proxy-server.c++ - src/mp/test/foo.capnp.proxy-client.c++ - src/mp/test/foo.capnp.proxy-types.c++ - src/mp/test/foo.capnp.proxy-types.h - src/mp/test/foo-types.h - src/mp/test/foo.h - src/mp/test/test.cpp - ) - target_include_directories(mptest PUBLIC - ${CAPNP_INCLUDE_DIRECTORY} - $ - $ - $ - $ - ) - target_link_libraries(mptest PRIVATE CapnProto::capnp) - target_link_libraries(mptest PRIVATE CapnProto::capnp-rpc) - target_link_libraries(mptest PRIVATE CapnProto::kj) - target_link_libraries(mptest PRIVATE CapnProto::kj-async) - target_link_libraries(mptest PRIVATE CapnProto::kj-test) - target_link_libraries(mptest PRIVATE Threads::Threads) - target_link_libraries(mptest PRIVATE multiprocess) - set_target_properties(mptest PROPERTIES - CXX_STANDARD 17 - CXX_STANDARD_REQUIRED YES) - add_test(NAME mptest COMMAND mptest) -endif() +add_subdirectory(test EXCLUDE_FROM_ALL) diff --git a/README.md b/README.md index b376839..f6869d3 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ There is also optional support for thread mapping, so each thread making interpr ## Example -A simple interface description can be found at [src/mp/test/foo.capnp](src/mp/test/foo.capnp), implementation in [src/mp/test/foo.h](src/mp/test/foo.h), and usage in [src/mp/test/test.cpp](src/mp/test/test.cpp). +A simple interface description can be found at [test/src/mp/test/foo.capnp](test/src/mp/test/foo.capnp), implementation in [test/src/mp/test/foo.h](test/src/mp/test/foo.h), and usage in [test/src/mp/test/test.cpp](test/src/mp/test/test.cpp). ## Future directions @@ -44,6 +44,6 @@ mkdir build cd build cmake .. make -make all test +make check # Optionally build and run tests make install ``` diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..bfd6c4d --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,66 @@ +# Copyright (c) 2020 The Bitcoin Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. + +include(CTest) + +# Custom test targets for convenience, based on +# https://gitlab.kitware.com/cmake/community/-/wikis/doc/tutorials/EmulateMakeCheck. +# +# CTest already provides a "make test" target, but it just runs existing tests +# that were previously built, without building anything itself. Define "make +# tests" here as a custom target to build all available tests and "make check" +# as a custom target to build and run them. +add_custom_target(tests) +add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS tests) + +if(BUILD_TESTING AND TARGET CapnProto::kj-test) + add_custom_command( + OUTPUT + src/mp/test/foo.capnp.h + src/mp/test/foo.capnp.c++ + src/mp/test/foo.capnp.proxy.h + src/mp/test/foo.capnp.proxy-server.c++ + src/mp/test/foo.capnp.proxy-client.c++ + src/mp/test/foo.capnp.proxy-types.c++ + src/mp/test/foo.capnp.proxy-types.h + COMMAND mpgen "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/src" "${CMAKE_CURRENT_SOURCE_DIR}/src/mp/test/foo.capnp" "${CMAKE_SOURCE_DIR}/include" "${capnp_PREFIX}/include" + DEPENDS src/mp/test/foo.capnp mpgen + ) + + set_property(SOURCE ${MP_PROXY_HDRS} PROPERTY GENERATED 1) + + add_executable(mptest + ${MP_PROXY_HDRS} + src/mp/test/foo.capnp.h + src/mp/test/foo.capnp.c++ + src/mp/test/foo.capnp.proxy.h + src/mp/test/foo.capnp.proxy-server.c++ + src/mp/test/foo.capnp.proxy-client.c++ + src/mp/test/foo.capnp.proxy-types.c++ + src/mp/test/foo.capnp.proxy-types.h + src/mp/test/foo-types.h + src/mp/test/foo.h + src/mp/test/test.cpp + ) + target_include_directories(mptest PUBLIC + ${CAPNP_INCLUDE_DIRECTORY} + $ + $ + $ + $ + ) + target_link_libraries(mptest PRIVATE CapnProto::capnp) + target_link_libraries(mptest PRIVATE CapnProto::capnp-rpc) + target_link_libraries(mptest PRIVATE CapnProto::kj) + target_link_libraries(mptest PRIVATE CapnProto::kj-async) + target_link_libraries(mptest PRIVATE CapnProto::kj-test) + target_link_libraries(mptest PRIVATE Threads::Threads) + target_link_libraries(mptest PRIVATE multiprocess) + set_target_properties(mptest PROPERTIES + CXX_STANDARD 17 + CXX_STANDARD_REQUIRED YES) + + add_dependencies(tests mptest) + add_test(NAME mptest COMMAND mptest) +endif() diff --git a/src/mp/test/foo-types.h b/test/src/mp/test/foo-types.h similarity index 100% rename from src/mp/test/foo-types.h rename to test/src/mp/test/foo-types.h diff --git a/src/mp/test/foo.capnp b/test/src/mp/test/foo.capnp similarity index 100% rename from src/mp/test/foo.capnp rename to test/src/mp/test/foo.capnp diff --git a/src/mp/test/foo.h b/test/src/mp/test/foo.h similarity index 100% rename from src/mp/test/foo.h rename to test/src/mp/test/foo.h diff --git a/src/mp/test/test.cpp b/test/src/mp/test/test.cpp similarity index 100% rename from src/mp/test/test.cpp rename to test/src/mp/test/test.cpp