From fb61013d350a15747176464118db4fe4e033127d Mon Sep 17 00:00:00 2001 From: Amber Date: Sun, 22 Oct 2023 15:34:25 -0400 Subject: [PATCH] Adding gtests --- .gitignore | 1 + CMakeLists.txt | 11 +++++++---- tests/CMakeLists.txt | 16 ++++++++++++++++ tests/self_test.cpp | 7 +++++++ 4 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 tests/CMakeLists.txt create mode 100644 tests/self_test.cpp diff --git a/.gitignore b/.gitignore index 46f42f8..3a500f3 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ install_manifest.txt compile_commands.json CTestTestfile.cmake _deps +build \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index d926ada..9eb1987 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,10 +1,8 @@ -# FILEPATH: /C:/Users/green/source/repos/callbackDemo/c_library/CMakeLists.txt - -# Set the minimum version of CMake required to build the project cmake_minimum_required(VERSION 3.20) # Set the name of the project and the language it is written in -project(C_Callback C) +# CXX is included because we are using googletest. +project(C_Callback C CXX) # create a shared library add_library(C_Callback SHARED) @@ -14,3 +12,8 @@ target_include_directories(C_Callback PUBLIC include) # add the sources to the library target_sources(C_Callback PRIVATE src/C_Callback.c) + +# Add the tests +include(CTest) +add_subdirectory(tests) + diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..f945ede --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.20) + +include(FetchContent) + +FetchContent_Declare( + googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG v1.14.0 +) + +FetchContent_MakeAvailable(googletest) + +add_executable(self_test self_test.cpp) +target_link_libraries(self_test gtest_main) + +add_test(NAME self_test COMMAND self_test) diff --git a/tests/self_test.cpp b/tests/self_test.cpp new file mode 100644 index 0000000..06fd95c --- /dev/null +++ b/tests/self_test.cpp @@ -0,0 +1,7 @@ +#include + +TEST(SelfTest, Test1) { + EXPECT_EQ(1, 1); + EXPECT_TRUE(true); + EXPECT_FALSE(false); +} \ No newline at end of file