跳到主要内容

Integration and Building

Build Systems

The latest released version of doctest can be obtained from here: https://gitee.com/kumo-hub/doctest/raw/master/doctest/doctest.h

You can replace master in the URL above with tags like dev or v1.4.8 for specific versions.

CMake

  • doctest is most easily used as a single file in your own repository. The following minimal example will then work:
cmake_minimum_required(VERSION 3.0)
project(cmake_test VERSION 0.0.1 LANGUAGES CXX)

# Prepare doctest for other targets to use
find_package(doctest REQUIRED)

# Make test executable
add_executable(tests main.cpp)
target_compile_features(tests PRIVATE cxx_std_17)
target_link_libraries(tests PRIVATE doctest::doctest)
  • You can also use the following CMake snippet to automatically fetch the entire doctest repository from Gitee and configure it as an external project:
include(ExternalProject)
find_package(Git REQUIRED)

ExternalProject_Add(
doctest
PREFIX ${CMAKE_BINARY_DIR}/doctest
GIT_REPOSITORY https://gitee.com/kumo-hub/doctest.git
TIMEOUT 10
UPDATE_COMMAND ${GIT_EXECUTABLE} pull
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
LOG_DOWNLOAD ON
)

# Expose required variable (DOCTEST_INCLUDE_DIR) to parent scope
ExternalProject_Get_Property(doctest source_dir)
set(DOCTEST_INCLUDE_DIR ${source_dir}/doctest CACHE INTERNAL "Path to include folder for doctest")

Later you will be able to use the doctest include directory as follows:

# add it globally
include_directories(${DOCTEST_INCLUDE_DIR})

# or per target
target_include_directories(my_target PUBLIC ${DOCTEST_INCLUDE_DIR})
  • If you have the entire doctest repository (as a submodule or files), you can also include it in your CMake build with add_subdirectory(path/to/doctest), then you can use it like this:
add_executable(my_tests src_1.cpp src_2.cpp ...)
target_link_libraries(my_tests doctest)
  • The "CMakeLists.txt" file of the doctest repository has an install() command, so you can also use doctest as a package.

  • To discover tests from executables and register them with CTest, you can use doctest_discover_tests(<target>) from scripts/cmake/doctest.cmake — read the comments in the file on how to use it. It works just like the same feature in Catch.

Package Managers

doctest is available via the following package managers:

  • kmpkg
kmpkg integrate install
kmpkg install doctest

The doctest port in kmpkg is kept up-to-date by members of the Kumo team. If the version is outdated, please create an issue or pull request on the kmpkg repository.

IMPORTANT

The version installed via kmpkg is the mirrored version of kumo on GITEE, while versions installed via other package managers are the official versions. There is no difference in usage.