15 add test framework #16
Merged@github-juk3n wants to merge
15-add-test-framework into mainMerged as
66a711aee891.5 files changed
modified
.gitignore +1 -1 | @@ -1,3 +1,3 @@ | ||
| 1 | 1 | *.vscode* |
| 2 | -build/* | |
| 2 | +*/build/* | |
| 3 | 3 | *sqlite* |
| \ No newline at end of file | ||
| @@ -1,3 +1,3 @@ | |||
| 1 | *.vscode* | 1 | *.vscode* |
| 2 | -build/* | 2 | +*/build/* |
| 3 | *sqlite* | 3 | *sqlite* |
| \ No newline at end of file | \ No newline at end of file | ||
renamed
app/CMakeLists.txt +24 -5 | similarity index 66% | ||
| rename from CMakeLists.txt | ||
| rename to app/CMakeLists.txt | ||
| @@ -17,25 +17,41 @@ if(NOT ftxui_POPULATED) | ||
| 17 | 17 | endif() |
| 18 | 18 | |
| 19 | 19 | |
| 20 | +FetchContent_Declare(googletest | |
| 21 | + GIT_REPOSITORY https://github.com/google/googletest | |
| 22 | + GIT_TAG v1.14.0 | |
| 23 | +) | |
| 24 | +FetchContent_MakeAvailable(googletest) | |
| 25 | + | |
| 20 | 26 | |
| 21 | -find_program(CLANG_TIDY NAMES "clang-tidy" REQUIRED) | |
| 22 | -set(CLANG_TIDY_COMMAND "${CLANG_TIDY}" "-checks=-*,modernize-*") | |
| 27 | +#find_program(CLANG_TIDY NAMES "clang-tidy" REQUIRED) | |
| 28 | +#set(CLANG_TIDY_COMMAND "${CLANG_TIDY}" "-checks=-*,modernize-*") | |
| 23 | 29 | |
| 24 | 30 | |
| 25 | 31 | find_package(SQLite3 REQUIRED) |
| 26 | 32 | |
| 27 | 33 | include_directories(${CMAKE_SOURCE_DIR}/include) |
| 28 | - | |
| 34 | +enable_testing() | |
| 29 | 35 | add_executable(fluffy src/main.cpp) |
| 30 | 36 | |
| 31 | 37 | |
| 38 | + | |
| 39 | +add_executable( | |
| 40 | + tests | |
| 41 | + tests/gameTest.cpp | |
| 42 | +) | |
| 43 | +target_link_libraries( | |
| 44 | + tests | |
| 45 | + GTest::gtest_main | |
| 46 | +) | |
| 47 | + | |
| 32 | 48 | target_link_libraries(fluffy |
| 33 | 49 | PRIVATE ftxui::screen |
| 34 | 50 | PRIVATE ftxui::dom |
| 35 | 51 | PRIVATE ftxui::component |
| 36 | 52 | PRIVATE SQLite::SQLite3 |
| 37 | 53 | ) |
| 38 | -set_target_properties(fluffy PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}") | |
| 54 | +#set_target_properties(fluffy PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}") | |
| 39 | 55 | |
| 40 | 56 | if (EMSCRIPTEN) |
| 41 | 57 | string(APPEND CMAKE_CXX_FLAGS " -s USE_PTHREADS") |
| @@ -45,4 +61,7 @@ if (EMSCRIPTEN) | ||
| 45 | 61 | foreach(file "index.html" "run_webassembly.py") |
| 46 | 62 | configure_file("src/${file}" ${file}) |
| 47 | 63 | endforeach(file) |
| 48 | -endif() | |
| \ No newline at end of file | ||
| 64 | +endif() | |
| 65 | + | |
| 66 | +include(GoogleTest) | |
| 67 | +gtest_discover_tests(tests) | |
| similarity index 66% | |||
| rename from CMakeLists.txt | |||
| rename to app/CMakeLists.txt | |||
| @@ -17,25 +17,41 @@ if(NOT ftxui_POPULATED) | |||
| 17 | endif() | 17 | endif() |
| 18 | 18 | ||
| 19 | 19 | ||
| 20 | +FetchContent_Declare(googletest | ||
| 21 | + GIT_REPOSITORY https://github.com/google/googletest | ||
| 22 | + GIT_TAG v1.14.0 | ||
| 23 | +) | ||
| 24 | +FetchContent_MakeAvailable(googletest) | ||
| 25 | + | ||
| 20 | 26 | ||
| 21 | -find_program(CLANG_TIDY NAMES "clang-tidy" REQUIRED) | 27 | +#find_program(CLANG_TIDY NAMES "clang-tidy" REQUIRED) |
| 22 | -set(CLANG_TIDY_COMMAND "${CLANG_TIDY}" "-checks=-*,modernize-*") | 28 | +#set(CLANG_TIDY_COMMAND "${CLANG_TIDY}" "-checks=-*,modernize-*") |
| 23 | 29 | ||
| 24 | 30 | ||
| 25 | find_package(SQLite3 REQUIRED) | 31 | find_package(SQLite3 REQUIRED) |
| 26 | 32 | ||
| 27 | include_directories(${CMAKE_SOURCE_DIR}/include) | 33 | include_directories(${CMAKE_SOURCE_DIR}/include) |
| 28 | - | 34 | +enable_testing() |
| 29 | add_executable(fluffy src/main.cpp) | 35 | add_executable(fluffy src/main.cpp) |
| 30 | 36 | ||
| 31 | 37 | ||
| 38 | + | ||
| 39 | +add_executable( | ||
| 40 | + tests | ||
| 41 | + tests/gameTest.cpp | ||
| 42 | +) | ||
| 43 | +target_link_libraries( | ||
| 44 | + tests | ||
| 45 | + GTest::gtest_main | ||
| 46 | +) | ||
| 47 | + | ||
| 32 | target_link_libraries(fluffy | 48 | target_link_libraries(fluffy |
| 33 | PRIVATE ftxui::screen | 49 | PRIVATE ftxui::screen |
| 34 | PRIVATE ftxui::dom | 50 | PRIVATE ftxui::dom |
| 35 | PRIVATE ftxui::component | 51 | PRIVATE ftxui::component |
| 36 | PRIVATE SQLite::SQLite3 | 52 | PRIVATE SQLite::SQLite3 |
| 37 | ) | 53 | ) |
| 38 | -set_target_properties(fluffy PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}") | 54 | +#set_target_properties(fluffy PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}") |
| 39 | 55 | ||
| 40 | if (EMSCRIPTEN) | 56 | if (EMSCRIPTEN) |
| 41 | string(APPEND CMAKE_CXX_FLAGS " -s USE_PTHREADS") | 57 | string(APPEND CMAKE_CXX_FLAGS " -s USE_PTHREADS") |
| @@ -45,4 +61,7 @@ if (EMSCRIPTEN) | |||
| 45 | foreach(file "index.html" "run_webassembly.py") | 61 | foreach(file "index.html" "run_webassembly.py") |
| 46 | configure_file("src/${file}" ${file}) | 62 | configure_file("src/${file}" ${file}) |
| 47 | endforeach(file) | 63 | endforeach(file) |
| 48 | -endif() | ||
| \ No newline at end of file | \ No newline at end of file | ||
| 64 | +endif() | ||
| 65 | + | ||
| 66 | +include(GoogleTest) | ||
| 67 | +gtest_discover_tests(tests) | ||
renamed
app/include/game.hpp +0 -0 | similarity index 100% | ||
| rename from include/game.hpp | ||
| rename to app/include/game.hpp |
| similarity index 100% | |||
| rename from include/game.hpp | |||
| rename to app/include/game.hpp |
renamed
app/src/main.cpp +0 -0 | similarity index 100% | ||
| rename from src/main.cpp | ||
| rename to app/src/main.cpp |
| similarity index 100% | |||
| rename from src/main.cpp | |||
| rename to app/src/main.cpp |
added
app/tests/gameTest.cpp +11 -0 | new file mode 100644 | ||
| @@ -0,0 +1,11 @@ | ||
| 1 | +#include <gtest/gtest.h> | |
| 2 | + | |
| 3 | +#include <game.hpp> | |
| 4 | + | |
| 5 | +TEST(GameTest, Creation) { | |
| 6 | + Game sut{0, "sut", "sut/path"}; | |
| 7 | + | |
| 8 | + EXPECT_EQ(0, sut.getId()); | |
| 9 | + EXPECT_EQ("sut", sut.getName()); | |
| 10 | + EXPECT_EQ("sut/path", sut.getPath()); | |
| 11 | +} | |
| \ No newline at end of file | ||
| new file mode 100644 | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | +#include <gtest/gtest.h> | ||
| 2 | + | ||
| 3 | +#include <game.hpp> | ||
| 4 | + | ||
| 5 | +TEST(GameTest, Creation) { | ||
| 6 | + Game sut{0, "sut", "sut/path"}; | ||
| 7 | + | ||
| 8 | + EXPECT_EQ(0, sut.getId()); | ||
| 9 | + EXPECT_EQ("sut", sut.getName()); | ||
| 10 | + EXPECT_EQ("sut/path", sut.getPath()); | ||
| 11 | +} | ||
| \ No newline at end of file | \ No newline at end of file | ||