mirror of
1
0
Fork 0

feat: new example

This commit is contained in:
Henry Schreiner 2020-08-05 16:09:16 -04:00
parent 4517453d66
commit 571a244dbd
3 changed files with 34 additions and 1 deletions

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.11...3.16)
cmake_minimum_required(VERSION 3.11...3.18)
project(ModernCMakeExamples)
set(MODERN_CMAKE_BUILD_TESTING ON)
@ -7,6 +7,7 @@ include(CTest)
add_subdirectory(simple-project)
add_subdirectory(extended-project)
add_subdirectory(fetch)
add_subdirectory(root-usefile)
add_subdirectory(root-simple)

View File

@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.14...3.18)
project(FetchExample LANGUAGES CXX)
include(FetchContent)
include(CTest)
FetchContent_Declare(
catch
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v2.13.0
)
# CMake 3.14+
FetchContent_MakeAvailable(catch)
add_executable(fetch_example main.cpp)
target_link_libraries(fetch_example PRIVATE Catch2::Catch2)
add_test(NAME fetch_example COMMAND fetch_example)

13
examples/fetch/main.cpp Normal file
View File

@ -0,0 +1,13 @@
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#include "catch2/catch.hpp"
unsigned int Factorial( unsigned int number ) {
return number <= 1 ? number : Factorial(number-1)*number;
}
TEST_CASE( "Factorials are computed", "[factorial]" ) {
REQUIRE( Factorial(1) == 1 );
REQUIRE( Factorial(2) == 2 );
REQUIRE( Factorial(3) == 6 );
REQUIRE( Factorial(10) == 3628800 );
}