mirror of
https://github.com/cpm-cmake/CPM.cmake.git
synced 2025-11-18 07:07:47 -05:00
Added GTest (googletest) Example (#84)
* Added GTest (googletest) Example The examples tests the Fibonacci library similar to the doctest example. * Update examples/gtest/CMakeLists.txt Co-Authored-By: Lars Melchior <TheLartians@users.noreply.github.com>
This commit is contained in:
45
examples/gtest/CMakeLists.txt
Normal file
45
examples/gtest/CMakeLists.txt
Normal file
@@ -0,0 +1,45 @@
|
||||
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
|
||||
|
||||
project(CPMExampleGtest)
|
||||
|
||||
# ---- Options ----
|
||||
|
||||
option(ENABLE_TEST_COVERAGE "Enable test coverage" OFF)
|
||||
|
||||
# ---- Dependencies ----
|
||||
|
||||
include(../../cmake/CPM.cmake)
|
||||
|
||||
CPMAddPackage(
|
||||
NAME fibonacci
|
||||
GIT_REPOSITORY https://github.com/TheLartians/Fibonacci.git
|
||||
VERSION 1.0
|
||||
)
|
||||
|
||||
CPMAddPackage(
|
||||
NAME googletest
|
||||
GITHUB_REPOSITORY google/googletest
|
||||
GIT_TAG release-1.8.1
|
||||
VERSION 1.8.1
|
||||
OPTIONS
|
||||
"INSTALL_GTEST OFF"
|
||||
"gtest_force_shared_crt ON"
|
||||
)
|
||||
|
||||
# ---- Create binary ----
|
||||
|
||||
add_executable(CPMExampleGtest main.cpp)
|
||||
target_link_libraries(CPMExampleGtest fibonacci gtest gtest_main gmock)
|
||||
set_target_properties(CPMExampleGtest PROPERTIES CXX_STANDARD 17)
|
||||
|
||||
# ---- Enable testing ----
|
||||
|
||||
enable_testing()
|
||||
add_test(CPMExampleGtest CPMExampleGtest)
|
||||
|
||||
# ---- Add code coverage ----
|
||||
|
||||
if (${ENABLE_TEST_COVERAGE})
|
||||
set_target_properties(CPMExampleGtest PROPERTIES CXX_STANDARD 17 COMPILE_FLAGS "-O0 -g -fprofile-arcs -ftest-coverage --coverage")
|
||||
target_link_options(CPMExampleGtest PUBLIC "--coverage")
|
||||
endif()
|
||||
13
examples/gtest/main.cpp
Normal file
13
examples/gtest/main.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <fibonacci.h>
|
||||
|
||||
TEST(FibonacciTests, BasicChecks)
|
||||
{
|
||||
ASSERT_TRUE(fibonnacci(0) == 0);
|
||||
ASSERT_TRUE(fibonnacci(1) == 1);
|
||||
ASSERT_TRUE(fibonnacci(2) == 1);
|
||||
ASSERT_TRUE(fibonnacci(3) == 2);
|
||||
ASSERT_TRUE(fibonnacci(4) == 3);
|
||||
ASSERT_TRUE(fibonnacci(5) == 5);
|
||||
ASSERT_TRUE(fibonnacci(13) == 233);
|
||||
}
|
||||
Reference in New Issue
Block a user