Skip to content

Commit

Permalink
Add testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Roman Pavelka committed Jul 14, 2023
1 parent c7cdd05 commit 5e60763
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/learn-github-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.vscode
build
Testing
10 changes: 6 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 19 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
8 changes: 8 additions & 0 deletions tests/low/test_low.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <gtest/gtest.h>

#include "low/low.h"

TEST(LowTestSuite, MessageTest) {
std::string result = message();
EXPECT_EQ(result, "Hello!");
}

0 comments on commit 5e60763

Please sign in to comment.