From 0684305ccca6928fec1464072b85b17c5fa60ce6 Mon Sep 17 00:00:00 2001 From: lukasz126 Date: Wed, 21 Feb 2024 00:57:22 +0100 Subject: [PATCH] added gtest --- .github/workflows/ci_basic.yaml | 9 +++++---- communicator/tests/CMakeLists.txt | 18 ++++++++++++++++++ communicator/tests/exampleTest.cpp | 9 +++++++++ 3 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 communicator/tests/CMakeLists.txt create mode 100644 communicator/tests/exampleTest.cpp diff --git a/.github/workflows/ci_basic.yaml b/.github/workflows/ci_basic.yaml index d0fdca2..45f7564 100644 --- a/.github/workflows/ci_basic.yaml +++ b/.github/workflows/ci_basic.yaml @@ -7,6 +7,8 @@ env: BUILD_TYPE: Release BUILD_PATH: ${{github.workspace}}/communicator/build SOURCE: ${{github.workspace}}/communicator + TEST_BUILD_PATH: ${{github.workspace}}/communicator/tests/build + jobs: build: @@ -41,8 +43,7 @@ jobs: - name: Pre-commit actions uses: pre-commit/action@v3.0.1 - # TODO uncomment when tests are added - # - name: Test - # working-directory: ${{env.BUILD_PATH}} - # run: ctest -C ${{env.BUILD_TYPE}} + - name: Test + working-directory: ${{env.TEST_BUILD_PATH}} + run: ctest -C ${{env.BUILD_TYPE}} diff --git a/communicator/tests/CMakeLists.txt b/communicator/tests/CMakeLists.txt new file mode 100644 index 0000000..a329cb8 --- /dev/null +++ b/communicator/tests/CMakeLists.txt @@ -0,0 +1,18 @@ +cmake_minimum_required(VERSION 3.5) +project(CommunicatorGTest) + +include(FetchContent) +FetchContent_Declare( + googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG main +) + +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) +FetchContent_MakeAvailable(googletest) + +# Now simply link against gtest or gtest_main as needed. Eg +add_executable(example-gt exampleTest.cpp) +target_link_libraries(example-gt gtest_main) +enable_testing() +add_test(NAME example_test COMMAND example-gt) \ No newline at end of file diff --git a/communicator/tests/exampleTest.cpp b/communicator/tests/exampleTest.cpp new file mode 100644 index 0000000..8983b2d --- /dev/null +++ b/communicator/tests/exampleTest.cpp @@ -0,0 +1,9 @@ +#include "gtest/gtest.h" + +// Demonstrate some basic assertions. +TEST(exampleTest, BasicAssertions) { + // Expect two strings not to be equal. + EXPECT_STRNE("hello", "world"); + // Expect equality. + EXPECT_EQ(7 * 6, 42); +} \ No newline at end of file