From 287ade1d321c983ddd00025864f9ea59d31c4493 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Tue, 3 Sep 2024 19:51:41 +0200 Subject: add googletest unit testing setup --- .gitmodules | 5 +++++ contributing.md | 9 +++++++++ lib/googletest | 1 + src/CMakeLists.txt | 2 +- test/CMakeLists.txt | 21 +++++++++++++++++++++ test/dummy.cpp | 6 ++++++ test/makefile | 7 +++++++ 7 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 .gitmodules create mode 160000 lib/googletest create mode 100644 test/CMakeLists.txt create mode 100644 test/dummy.cpp create mode 100644 test/makefile diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..f8a9861 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,5 @@ +[submodule "lib/googletest"] + path = lib/googletest + url = https://github.com/google/googletest + branch = v1.15.x + shallow = true diff --git a/contributing.md b/contributing.md index c018917..f8c7d97 100644 --- a/contributing.md +++ b/contributing.md @@ -17,6 +17,13 @@ sure to separate the include statements using a blank line (clang-format may sort include statements, but does not sort across empty lines). +## CMakeLists specific + +- Make sure list arguments (e.g. sources, libraries) given to commands (e.g. + `target_sources`, `target_link_libraries`) are on separate lines. This makes + resolving merge conflicts when multiple sources were added by different + people to the same CMakeLists.txt easier. + # Documentation - All documentation is written in U.S. English @@ -26,4 +33,6 @@ - External libraries should be included as Git submodules under the `lib/` subdirectory +- When adding new submodules, make sure to manually set the `branch` and + `shallow` options in the [.gitmodules](./.gitmodules) file diff --git a/lib/googletest b/lib/googletest new file mode 160000 index 0000000..b514bdc --- /dev/null +++ b/lib/googletest @@ -0,0 +1 @@ +Subproject commit b514bdc898e2951020cbdca1304b75f5950d1f59 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3ade1e3..0090188 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.28) set(CMAKE_C_STANDARD 11) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_EXPORT_COMPILE_COMMANDS 1) # enable debug features diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..26aa460 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,21 @@ +cmake_minimum_required(VERSION 3.28) + +set(CMAKE_C_STANDARD 11) +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_EXPORT_COMPILE_COMMANDS 1) + +set(CMAKE_BUILD_TYPE Debug) + +project(test C CXX) + +add_subdirectory(../lib/googletest googletest) + +add_executable(test + dummy.cpp +) + +target_link_libraries(test + gtest_main + # TODO: add crepe engine +) + diff --git a/test/dummy.cpp b/test/dummy.cpp new file mode 100644 index 0000000..08850b2 --- /dev/null +++ b/test/dummy.cpp @@ -0,0 +1,6 @@ +#include + +TEST(dummy, foo) { + ASSERT_TRUE(1); +} + diff --git a/test/makefile b/test/makefile new file mode 100644 index 0000000..7aeee34 --- /dev/null +++ b/test/makefile @@ -0,0 +1,7 @@ +TARGET = $(BUILD_DIR)/test + +include ../lazy.mk + +test: $(TARGET) FORCE + $(TARGET) + -- cgit v1.2.3