feat/test: Add test harness #1

Merged
nishi merged 5 commits from feat/test into master 2026-05-29 00:23:20 +09:00
8 changed files with 76 additions and 0 deletions

View file

@ -3,3 +3,5 @@ project(fishbowl)
add_subdirectory(engine)
add_subdirectory(client)
enable_testing()

43
CMakePresets.json Normal file
View file

@ -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
}
}
]
}

View file

@ -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()

View file

@ -0,0 +1,7 @@
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/CPM.cmake")
CPMAddPackage(
NAME "catch2"
GITHUB_REPOSITORY "catchorg/Catch2"
GIT_TAG "v3.15.0"
)

View file

@ -6,6 +6,7 @@
#include <fstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <fishbone/config.h>

View file

@ -28,6 +28,9 @@ namespace fishbone {
Mutex();
~Mutex();
Mutex(const Mutex&) = delete;
Mutex& operator=(const Mutex&) = delete;
void lock();
void unlock();
};

View file

@ -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)

View file

@ -0,0 +1 @@
#include <catch2/catch_test_macros.hpp>