-
MacOS:
brew install catch2
-
Ubuntu:
sudo apt install catch2
-
build:
cd build cmake .. make
-
test one executable:
tests/test
-
test specific test case:
tests/test "factorial test #2"
or test specific tag:
tests/test --list-tags tests/test \[one]
-
./src/CMakeLists.txt
includes files as lib:add_library(fct factorial.cpp) # lib name: fct add_library(bnm binomial.cpp) # lib name: bnm
-
./tests/CMakeLists.txt
adds executable and links libs (works for multiple executables with their libraries):add_executable( test # name of the executable test_factorial.cpp test_binomial.cpp ) target_link_libraries( test # linking libraries from `src/CMakeLists.txt` fct bnm Catch2::Catch2WithMain )
-
./CMakeLists.txt
main file:cmake_minimum_required(VERSION 3.10) project(Catch2Template LANGUAGES CXX VERSION 0.0.1) find_package(Catch2 REQUIRED) include_directories(include) add_subdirectory(src) add_subdirectory(tests)