Skip to content

Commit

Permalink
Add "make check" target to build and run tests
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ryanofsky committed May 13, 2020
1 parent 9d23fdd commit 21d2ee6
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 48 deletions.
47 changes: 1 addition & 46 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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}
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/src>
)
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)
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -44,6 +44,6 @@ mkdir build
cd build
cmake ..
make
make all test
make check # Optionally build and run tests
make install
```
66 changes: 66 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 DEPENDS mptest)
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}
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/src>
)
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()
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 21d2ee6

Please sign in to comment.