Skip to content

Files

Latest commit

 

History

History

add_subdirectory_approvaltests_catch2

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

add_subdirectory_approvaltests_catch2

Topic Detail
Directory add_subdirectory_approvaltests_catch2
Purpose Demo how to build your tests against clones or forks of ApprovalTests.cpp and Catch2.
Those source code of those dependencies will be included in your IDE, alongside your own source code.
This allows you to make edits to the dependent projects.
Dependencies ApprovalTests.cpp - cloned on your machine
Catch2 - cloned on your machine
Mechanism Uses CMake's add_subdirectory()
More Detail See Use own ApprovalTests.cpp and Catch2 clones

The top-level CMakeLists.txt file is:

cmake_minimum_required(VERSION 3.8 FATAL_ERROR)

project(add_subdirectory_approvaltests_catch2)

enable_testing()

add_subdirectory(dependencies)
add_subdirectory(tests)

snippet source

The CMakeLists.txt to pull in dependencies is:

# -------------------------------------------------------------------
# ApprovalTests.cpp
add_subdirectory(
        ../../ApprovalTests.cpp
        ${CMAKE_CURRENT_BINARY_DIR}/approvaltests.cpp_build
)

# -------------------------------------------------------------------
# Catch2
set(CATCH_BUILD_TESTING OFF CACHE BOOL "")
add_subdirectory(
        ../../Catch2
        ${CMAKE_CURRENT_BINARY_DIR}/catch2_build
)

snippet source

And the CMakeLists.txt that builds the tests is:

add_executable(tests
        main.cpp
        tests.cpp
)
target_link_libraries(tests ApprovalTests::ApprovalTests Catch2::Catch2)

target_compile_features(tests PUBLIC cxx_std_11)
set_target_properties(tests PROPERTIES CXX_EXTENSIONS OFF)

add_test(
        NAME tests
        COMMAND tests)

snippet source

The build script is:

#!/bin/bash

# Force execution to halt if there are any errors in this script:
set -e
set -o pipefail

mkdir -p build
cd       build
cmake -DCMAKE_BUILD_TYPE=Debug ..
cmake --build .
ctest --output-on-failure . -C Debug

snippet source