diff --git a/.github/workflows/learn-github-actions.yml b/.github/workflows/learn-github-actions.yml index 0e89c7d..15fa1e1 100644 --- a/.github/workflows/learn-github-actions.yml +++ b/.github/workflows/learn-github-actions.yml @@ -23,4 +23,4 @@ jobs: run: cmake --build "build_${{ matrix.build-tool }}_${{ matrix.compiler }}" - name: Test the project - run: ctest --test-dir "build_${{ matrix.build-tool }}_${{ matrix.compiler }}" + run: ctest --test-dir "build_${{ matrix.build-tool }}_${{ matrix.compiler }}/tests" diff --git a/.gitignore b/.gitignore index af96791..c975984 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .vscode build +Testing diff --git a/CMakeLists.txt b/CMakeLists.txt index 73bc446..967cbd6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,8 +11,10 @@ set(CMAKE_CXX_STANDARD_REQUIRED TRUE) include_directories(${PROJECT_SOURCE_DIR}/include) -# Create sources variable -file(GLOB_RECURSE SOURCES "src/*.cpp") -message("Sources: ${SOURCES}") +add_executable(hello + src/low/low.cpp + src/mid/mid.cpp + src/main.cpp +) -add_executable(hello ${SOURCES}) +add_subdirectory(tests) diff --git a/Makefile b/Makefile index 116e769..7bfefc2 100644 --- a/Makefile +++ b/Makefile @@ -4,8 +4,11 @@ build: cmake -S . -B build -G Ninja cmake --build build -run: build +test: build + ctest --test-dir build/tests + +run: test ./build/hello clean: - rm -rf build + rm -rf build Testing diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..5781690 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 3.22) +project(HelloTests) + +include(FetchContent) +FetchContent_Declare( + googletest + URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip +) +FetchContent_MakeAvailable(googletest) + +add_executable(HelloTests + low/test_low.cpp + ../src/low/low.cpp +) +target_link_libraries(HelloTests gtest_main) + +enable_testing() + +add_test(NAME HelloTests COMMAND HelloTests) diff --git a/tests/low/test_low.cpp b/tests/low/test_low.cpp new file mode 100644 index 0000000..0920e34 --- /dev/null +++ b/tests/low/test_low.cpp @@ -0,0 +1,8 @@ +#include + +#include "low/low.h" + +TEST(LowTestSuite, MessageTest) { + std::string result = message(); + EXPECT_EQ(result, "Hello!"); +}