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