Skip to content

Commit

Permalink
Adding gtests
Browse files Browse the repository at this point in the history
  • Loading branch information
greenliquidlight committed Oct 22, 2023
1 parent e073394 commit fb61013
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps
build
11 changes: 7 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)

16 changes: 16 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 7 additions & 0 deletions tests/self_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <gtest/gtest.h>

TEST(SelfTest, Test1) {
EXPECT_EQ(1, 1);
EXPECT_TRUE(true);
EXPECT_FALSE(false);
}

0 comments on commit fb61013

Please sign in to comment.