From 5a654758ad79adc9789269e41b699469bddafe85 Mon Sep 17 00:00:00 2001 From: maelstrom Date: Thu, 28 May 2026 16:48:24 +0200 Subject: [PATCH 1/5] feat: add test harness --- CMakeLists.txt | 2 ++ CMakePresets.json | 42 +++++++++++++++++++++++++++++++++ engine/CMakeLists.txt | 10 ++++++++ engine/cmake/deps/catch2.cmake | 7 ++++++ engine/tests/CMakeLists.txt | 9 +++++++ engine/tests/src/placeholder.cc | 1 + 6 files changed, 71 insertions(+) create mode 100644 CMakePresets.json create mode 100644 engine/cmake/deps/catch2.cmake create mode 100644 engine/tests/CMakeLists.txt create mode 100644 engine/tests/src/placeholder.cc 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..de96574 --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,42 @@ +{ + "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" + } + } + ], + "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/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 -- 2.39.5 From 2daddafe3a6ed38d9e9bfdbb392e490355e8df89 Mon Sep 17 00:00:00 2001 From: maelstrom Date: Thu, 28 May 2026 16:48:34 +0200 Subject: [PATCH 2/5] fix: missing cstring import for memcpy --- engine/src/soundldr/flac.cc | 1 + engine/src/soundldr/mp3.cc | 1 + engine/src/soundldr/vorbis.cc | 1 + engine/src/soundldr/wav.cc | 1 + engine/src/soundldr/xmp.cc | 1 + 5 files changed, 5 insertions(+) diff --git a/engine/src/soundldr/flac.cc b/engine/src/soundldr/flac.cc index f812160..42a35c5 100644 --- a/engine/src/soundldr/flac.cc +++ b/engine/src/soundldr/flac.cc @@ -1,3 +1,4 @@ +#include #include struct fishbone::Sound::Impl { diff --git a/engine/src/soundldr/mp3.cc b/engine/src/soundldr/mp3.cc index 057330f..c6fc083 100644 --- a/engine/src/soundldr/mp3.cc +++ b/engine/src/soundldr/mp3.cc @@ -1,3 +1,4 @@ +#include #include struct fishbone::Sound::Impl { diff --git a/engine/src/soundldr/vorbis.cc b/engine/src/soundldr/vorbis.cc index 56d3047..574ebc6 100644 --- a/engine/src/soundldr/vorbis.cc +++ b/engine/src/soundldr/vorbis.cc @@ -1,3 +1,4 @@ +#include #include struct fishbone::Sound::Impl { diff --git a/engine/src/soundldr/wav.cc b/engine/src/soundldr/wav.cc index 5703b68..62b9abc 100644 --- a/engine/src/soundldr/wav.cc +++ b/engine/src/soundldr/wav.cc @@ -1,3 +1,4 @@ +#include #include struct fishbone::Sound::Impl { diff --git a/engine/src/soundldr/xmp.cc b/engine/src/soundldr/xmp.cc index f2f0a77..7b4e845 100644 --- a/engine/src/soundldr/xmp.cc +++ b/engine/src/soundldr/xmp.cc @@ -1,3 +1,4 @@ +#include #include struct fishbone::Sound::Impl { -- 2.39.5 From 291ae59de9bfe1e570d8282345db371c5307e97f Mon Sep 17 00:00:00 2001 From: maelstrom Date: Thu, 28 May 2026 16:49:55 +0200 Subject: [PATCH 3/5] chore: add CMAKE_EXPORT_COMPILE_COMMANDS=ON by default --- CMakePresets.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakePresets.json b/CMakePresets.json index de96574..8f412dd 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -16,7 +16,8 @@ "displayName": "Default (with tests)", "inherits": "default", "cacheVariables": { - "FISHBONE_BUILD_TESTS": "ON" + "FISHBONE_BUILD_TESTS": "ON", + "CMAKE_EXPORT_COMPILE_COMMANDS": "ON" } } ], -- 2.39.5 From 4f15a6f7d99a1da0defe7a1074b56d917c77ab2d Mon Sep 17 00:00:00 2001 From: maelstrom Date: Thu, 28 May 2026 17:19:36 +0200 Subject: [PATCH 4/5] fix: prevent accidental copying of Mutex --- engine/include/fishbone/thread.h | 3 +++ 1 file changed, 3 insertions(+) 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(); }; -- 2.39.5 From 61db6ed694d5ef8ea41acd61b797bbad634b653f Mon Sep 17 00:00:00 2001 From: maelstrom Date: Thu, 28 May 2026 17:22:30 +0200 Subject: [PATCH 5/5] chore: moved include into machdep.h --- engine/include/fishbone/machdep.h | 1 + engine/src/soundldr/flac.cc | 1 - engine/src/soundldr/mp3.cc | 1 - engine/src/soundldr/vorbis.cc | 1 - engine/src/soundldr/wav.cc | 1 - engine/src/soundldr/xmp.cc | 1 - 6 files changed, 1 insertion(+), 5 deletions(-) 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/src/soundldr/flac.cc b/engine/src/soundldr/flac.cc index 42a35c5..f812160 100644 --- a/engine/src/soundldr/flac.cc +++ b/engine/src/soundldr/flac.cc @@ -1,4 +1,3 @@ -#include #include struct fishbone::Sound::Impl { diff --git a/engine/src/soundldr/mp3.cc b/engine/src/soundldr/mp3.cc index c6fc083..057330f 100644 --- a/engine/src/soundldr/mp3.cc +++ b/engine/src/soundldr/mp3.cc @@ -1,4 +1,3 @@ -#include #include struct fishbone::Sound::Impl { diff --git a/engine/src/soundldr/vorbis.cc b/engine/src/soundldr/vorbis.cc index 574ebc6..56d3047 100644 --- a/engine/src/soundldr/vorbis.cc +++ b/engine/src/soundldr/vorbis.cc @@ -1,4 +1,3 @@ -#include #include struct fishbone::Sound::Impl { diff --git a/engine/src/soundldr/wav.cc b/engine/src/soundldr/wav.cc index 62b9abc..5703b68 100644 --- a/engine/src/soundldr/wav.cc +++ b/engine/src/soundldr/wav.cc @@ -1,4 +1,3 @@ -#include #include struct fishbone::Sound::Impl { diff --git a/engine/src/soundldr/xmp.cc b/engine/src/soundldr/xmp.cc index 7b4e845..f2f0a77 100644 --- a/engine/src/soundldr/xmp.cc +++ b/engine/src/soundldr/xmp.cc @@ -1,4 +1,3 @@ -#include #include struct fishbone::Sound::Impl { -- 2.39.5