diff --git a/CMakeLists.txt b/CMakeLists.txt index 57a51bd..ce34960 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,3 +3,5 @@ project(fishbowl) add_subdirectory(engine) add_subdirectory(client) + +enable_testing() \ No newline at end of file diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 0000000..8f412dd --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,43 @@ +{ + "version": 10, + "cmakeMinimumRequired": { + "major": 3, + "minor": 11, + "patch": 0 + }, + "configurePresets": [ + { + "name": "default", + "displayName": "Default", + "binaryDir": "build" + }, + { + "name": "default-with-tests", + "displayName": "Default (with tests)", + "inherits": "default", + "cacheVariables": { + "FISHBONE_BUILD_TESTS": "ON", + "CMAKE_EXPORT_COMPILE_COMMANDS": "ON" + } + } + ], + "buildPresets": [ + { + "name": "default", + "configurePreset": "default" + }, + { + "name": "default-with-tests", + "configurePreset": "default-with-tests" + } + ], + "testPresets": [ + { + "name": "default", + "configurePreset": "default-with-tests", + "output": { + "outputOnFailure": true + } + } + ] +} \ No newline at end of file diff --git a/engine/CMakeLists.txt b/engine/CMakeLists.txt index e9d2d9a..2c32755 100644 --- a/engine/CMakeLists.txt +++ b/engine/CMakeLists.txt @@ -1,6 +1,8 @@ cmake_minimum_required(VERSION 3.11) project(fishbone) +option(FISHBONE_BUILD_TESTS "Compile tests for fishbone" OFF) + if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/cmake/CPM.cmake") message(STATUS "Downloading CPM.cmake...") file(MAKE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/cmake") @@ -56,3 +58,11 @@ fb_add_dep(fishbone lz4) # Networking fb_add_dep(fishbone enet) + +# Testing +if(FISHBONE_BUILD_TESTS) + include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/deps/catch2.cmake") + list(APPEND CMAKE_MODULE_PATH ${Catch2_SOURCE_DIR}/extras) + enable_testing() + add_subdirectory(tests) +endif() \ No newline at end of file diff --git a/engine/cmake/deps/catch2.cmake b/engine/cmake/deps/catch2.cmake new file mode 100644 index 0000000..25816da --- /dev/null +++ b/engine/cmake/deps/catch2.cmake @@ -0,0 +1,7 @@ +include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/CPM.cmake") + +CPMAddPackage( + NAME "catch2" + GITHUB_REPOSITORY "catchorg/Catch2" + GIT_TAG "v3.15.0" +) \ No newline at end of file diff --git a/engine/include/fishbone/machdep.h b/engine/include/fishbone/machdep.h index 90879c8..8e7b4ac 100644 --- a/engine/include/fishbone/machdep.h +++ b/engine/include/fishbone/machdep.h @@ -6,6 +6,7 @@ #include #include +#include #include #include diff --git a/engine/include/fishbone/thread.h b/engine/include/fishbone/thread.h index b210e17..014bd9b 100644 --- a/engine/include/fishbone/thread.h +++ b/engine/include/fishbone/thread.h @@ -28,6 +28,9 @@ namespace fishbone { Mutex(); ~Mutex(); + Mutex(const Mutex&) = delete; + Mutex& operator=(const Mutex&) = delete; + void lock(); void unlock(); }; diff --git a/engine/tests/CMakeLists.txt b/engine/tests/CMakeLists.txt new file mode 100644 index 0000000..e7c1c11 --- /dev/null +++ b/engine/tests/CMakeLists.txt @@ -0,0 +1,9 @@ +include (CTest) +include (Catch) + +file(GLOB_RECURSE SRCS src/**.cc src/**.c) + +add_executable(fishbone_test ${SRCS}) +target_link_libraries(fishbone_test PRIVATE fishbone Catch2::Catch2WithMain) +target_include_directories(fishbone_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src) +catch_discover_tests(fishbone_test) \ No newline at end of file diff --git a/engine/tests/src/placeholder.cc b/engine/tests/src/placeholder.cc new file mode 100644 index 0000000..96821ce --- /dev/null +++ b/engine/tests/src/placeholder.cc @@ -0,0 +1 @@ +#include