У меня есть проект, организованный как:
|--cmake/
|--Modules/
|-- ParseAndAddCatchTests.cmake
|--test/
|--Tests/
|-- # Nothing here yet
|--catch.hpp
|--main.cpp
|--main.cpp
|--CMakeLists.txt
Вот мой CMakeLists.txt:
cmake_minimum_required(VERSION 3.5)
set (CMAKE_CXX_STANDARD 14)
project(TCGBench)
set (VERSION_MAJOR 1)
set (VERSION_MINOR 0)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/Modules")
include(CTest)
enable_testing()
#
# Create a library target for the Catch header-only test framework.
#
add_library(Catch INTERFACE)
target_include_directories(Catch
INTERFACE
test/
)
#
# Create a target for executing the Catch unit tests.
#
add_executable(unit_tests
test/main.cpp
)
target_include_directories(unit_tests
PUBLIC
test/
)
target_link_libraries(unit_tests
Catch
)
target_compile_options(unit_tests
PRIVATE
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
-Werror -Wall -Wextra>
$<$<CXX_COMPILER_ID:MSVC>:
/W4>
)
# Load and use the .cmake file provided by Catch so all the test cases
# are made available to CTest.
include(ParseAndAddCatchTests)
ParseAndAddCatchTests(unit_tests)
install(
TARGETS unit_tests
RUNTIME DESTINATION bin
)
set(SOURCE main.cpp)
add_executable(${PROJECT_NAME} ${SOURCE})
Вот мой test \ main. cpp file:
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
SCENARIO( "Verify equality in main" )
{
REQUIRE( 1 == 1 );
}
SCENARIO( "Verify failurein main" )
{
REQUIRE( 1 == 2 );
}
catch.hpp доступен здесь: https://github.com/erichschroeter/cmake-catch2-example/blob/master/test/catch.hpp ParseAndAddCatchTests.cmake здесь: https://github.com/erichschroeter/cmake-catch2-example/blob/master/cmake/Modules/ParseAndAddCatchTests.cmake CMake configure работает нормально, сборка CMake тоже, но в файле журнала тестирования есть это просто:
Start testing: May 07 17:52 Paris, Madrid (heure d?�t�)
----------------------------------------------------------
End testing: May 07 17:52 Paris, Madrid (heure d?�t�)
И никаких следов моих тестов на улов. Если кто знает, будет полезно! Спасибо.