Merge pull request 'Build containers, toolchains and portability fixes' (#35) from chore/toolchains-and-portability into main
This commit was merged in pull request #35.
This commit is contained in:
commit
b3c566ed4d
17 files changed
+359
-94
No files matched your search
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"name": "VoidLibrary (GCC 16, CMake 4, Ninja)",
|
||||
"build": {
|
||||
"dockerfile": "../Dockerfile",
|
||||
"context": ".."
|
||||
},
|
||||
"workspaceFolder": "/src",
|
||||
"workspaceMount": "source=${localWorkspaceFolder},target=/src,type=bind",
|
||||
"remoteUser": "root",
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
"extensions": [
|
||||
"ms-vscode.cpptools",
|
||||
"ms-vscode.cmake-tools",
|
||||
"twxs.cmake"
|
||||
],
|
||||
"settings": {
|
||||
"cmake.generator": "Ninja",
|
||||
"cmake.configureSettings": {
|
||||
"CMAKE_CXX_COMPILER": "g++-16",
|
||||
"CMAKE_C_COMPILER": "gcc-16",
|
||||
"CMAKE_BUILD_TYPE": "Debug"
|
||||
},
|
||||
"C_Cpp.default.cppStandard": "c++26"
|
||||
}
|
||||
}
|
||||
},
|
||||
"postCreateCommand": "cmake --version && g++-16 --version && ninja --version"
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
# Windows builds: MSYS2 (native) and MinGW-w64 (cross)
|
||||
|
||||
## MSYS2 (native Windows, recommended for a full build)
|
||||
|
||||
Install the MINGW64 toolchain and the optional libraries used by the modules:
|
||||
|
||||
```bash
|
||||
pacman -S --needed base-devel \
|
||||
mingw-w64-x86_64-toolchain \
|
||||
mingw-w64-x86_64-cmake \
|
||||
mingw-w64-x86_64-ninja \
|
||||
mingw-w64-x86_64-boost \
|
||||
mingw-w64-x86_64-openssl \
|
||||
mingw-w64-x86_64-libsodium \
|
||||
mingw-w64-x86_64-libarchive \
|
||||
mingw-w64-x86_64-sqlite3 \
|
||||
mingw-w64-x86_64-lua
|
||||
```
|
||||
|
||||
Then, from a **MINGW64** shell (not the MSYS shell):
|
||||
|
||||
```bash
|
||||
cmake -B build -S . -G Ninja -DCMAKE_BUILD_TYPE=Debug
|
||||
cmake --build build
|
||||
ctest --test-dir build --output-on-failure
|
||||
```
|
||||
|
||||
Notes:
|
||||
|
||||
- C++26 reflection requires GCC 16 or newer (`-freflection`). The build
|
||||
probes for it; on older GCC some reflection-only tests are skipped.
|
||||
- `Void::IO` currently has a POSIX (epoll) backend only; select the modules
|
||||
you need with `-DVOID_ENABLED_MODULES=...` if a module is not yet available
|
||||
on Windows.
|
||||
- The Windows branches of `Void::System` (paths, bounded reads, audio) are
|
||||
compiled by this configuration.
|
||||
|
||||
## MinGW-w64 cross build (Linux container)
|
||||
|
||||
`Dockerfile.mingw` uses the LLVM-MinGW toolchain (Clang + libc++ + the
|
||||
MinGW-w64 runtime) on top of Ubuntu, together with CMake 4 and Ninja. The
|
||||
matching devcontainer is in `.devcontainer/mingw/`.
|
||||
|
||||
```bash
|
||||
docker build -f Dockerfile.mingw -t voidlibrary-mingw .
|
||||
docker run --rm -v "$PWD:/src" -w /src voidlibrary-mingw bash -lc '
|
||||
cmake -B build-mingw -S . -G Ninja \
|
||||
-DCMAKE_TOOLCHAIN_FILE=cmake/toolchains/mingw-w64.cmake \
|
||||
-DCMAKE_BUILD_TYPE=Debug \
|
||||
-DVOID_ENABLE_TESTING=OFF \
|
||||
-DVOID_ENABLED_MODULES="Core;Functional;Containers;Math;Text;Algorithms;Unicode;Time;LogState"
|
||||
cmake --build build-mingw
|
||||
'
|
||||
```
|
||||
|
||||
Cross-compiling cannot use the host's Boost/OpenSSL/libsodium/libarchive/SQLite/
|
||||
Lua libraries. Modules that need them (or the POSIX-only IO backend) are
|
||||
therefore excluded from a cross build; use MSYS2 on Windows for those.
|
||||
|
||||
- The toolchain file accepts GCC- or Clang-based MinGW prefixes and picks
|
||||
whichever compiler exists.
|
||||
- `CMAKE_CXX_STANDARD` can be pinned for older toolchains
|
||||
(`-DCMAKE_CXX_STANDARD=23`); the build probes capabilities against the
|
||||
selected standard.
|
||||
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "VoidLibrary (MinGW-w64 cross build)",
|
||||
"build": {
|
||||
"dockerfile": "../../Dockerfile.mingw",
|
||||
"context": "../.."
|
||||
},
|
||||
"workspaceFolder": "/src",
|
||||
"workspaceMount": "source=${localWorkspaceFolder},target=/src,type=bind",
|
||||
"remoteUser": "root",
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
"extensions": [
|
||||
"ms-vscode.cpptools",
|
||||
"ms-vscode.cmake-tools",
|
||||
"twxs.cmake"
|
||||
],
|
||||
"settings": {
|
||||
"cmake.generator": "Ninja",
|
||||
"cmake.configureSettings": {
|
||||
"CMAKE_TOOLCHAIN_FILE": "cmake/toolchains/mingw-w64.cmake",
|
||||
"CMAKE_BUILD_TYPE": "Debug"
|
||||
},
|
||||
"C_Cpp.default.cppStandard": "c++26"
|
||||
}
|
||||
}
|
||||
},
|
||||
"postCreateCommand": "cmake --version && x86_64-w64-mingw32-g++ --version && ninja --version"
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
build*
|
||||
.git
|
||||
.gitea
|
||||
.github
|
||||
.dockerignore
|
||||
Dockerfile
|
||||
@@ -15,10 +15,20 @@ option(VOID_ENABLE_UBSAN "Enable UndefinedBehaviorSanitizer (Clang/GCC)" OFF)
|
||||
option(VOID_ENABLE_TSAN "Enable ThreadSanitizer (Clang/GCC)" OFF)
|
||||
option(VOID_ENABLE_COVERAGE "Enable code coverage instrumentation" OFF)
|
||||
|
||||
# C++26 is the default. Cross/toolchain-limited builds (e.g. MinGW-w64
|
||||
# with an older GCC) may pin a lower standard explicitly.
|
||||
if(NOT DEFINED CMAKE_CXX_STANDARD)
|
||||
set(CMAKE_CXX_STANDARD 26)
|
||||
endif()
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
if(NOT DEFINED CMAKE_CXX_MODULE_MAP_FORMAT)
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
set(CMAKE_CXX_MODULE_MAP_FORMAT "clang")
|
||||
else()
|
||||
set(CMAKE_CXX_MODULE_MAP_FORMAT "gcc")
|
||||
endif()
|
||||
endif()
|
||||
set(CXX_SCAN_FOR_MODULES OFF)
|
||||
# <Void/Data/Reflect.hpp>, <Void/Configuration/Bind.hpp>, etc.
|
||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 16)
|
||||
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
# Development image for VoidLibrary.
|
||||
#
|
||||
# Toolchain: GCC 16 (C++26 reflection), CMake 4, Ninja.
|
||||
# Optional dependencies used by the modules: Boost, OpenSSL, libsodium,
|
||||
# libarchive, SQLite3 and Lua 5.4.
|
||||
#
|
||||
# The image does not copy or build the sources: mount the repository at /src
|
||||
# (the devcontainer does this) and configure/build there.
|
||||
|
||||
FROM ubuntu:24.04
|
||||
|
||||
ARG DEBIAN_FRONTEND=noninteractive
|
||||
ARG GCC_VERSION=16
|
||||
ARG CMAKE_VERSION=4.2.3
|
||||
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends \
|
||||
build-essential \
|
||||
ca-certificates \
|
||||
curl \
|
||||
git \
|
||||
gnupg \
|
||||
ninja-build \
|
||||
pkg-config \
|
||||
software-properties-common \
|
||||
libboost-all-dev \
|
||||
libssl-dev \
|
||||
libsodium-dev \
|
||||
libarchive-dev \
|
||||
libsqlite3-dev \
|
||||
liblua5.4-dev \
|
||||
zlib1g-dev \
|
||||
&& add-apt-repository -y ppa:ubuntu-toolchain-r/test \
|
||||
&& apt-get update \
|
||||
&& apt-get install -y --no-install-recommends \
|
||||
gcc-${GCC_VERSION} \
|
||||
g++-${GCC_VERSION} \
|
||||
&& update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-${GCC_VERSION} 100 \
|
||||
&& update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-${GCC_VERSION} 100 \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN curl -fsSL -o /tmp/cmake.tar.gz \
|
||||
"https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}-linux-x86_64.tar.gz" \
|
||||
&& tar -xzf /tmp/cmake.tar.gz -C /opt \
|
||||
&& ln -s "/opt/cmake-${CMAKE_VERSION}-linux-x86_64/bin/cmake" /usr/local/bin/cmake \
|
||||
&& ln -s "/opt/cmake-${CMAKE_VERSION}-linux-x86_64/bin/ctest" /usr/local/bin/ctest \
|
||||
&& ln -s "/opt/cmake-${CMAKE_VERSION}-linux-x86_64/bin/cpack" /usr/local/bin/cpack \
|
||||
&& rm /tmp/cmake.tar.gz
|
||||
|
||||
WORKDIR /src
|
||||
|
||||
CMD ["bash"]
|
||||
@@ -0,0 +1,29 @@
|
||||
# MinGW-w64 cross-build environment for VoidLibrary (Windows x64 from Linux).
|
||||
#
|
||||
# Uses the LLVM-MinGW toolchain (Clang + libc++ + MinGW-w64 runtime), which is
|
||||
# new enough for the C++26 features this project uses. Reflection is not
|
||||
# available on Clang, so the reflection-only tests are skipped exactly as on
|
||||
# any non-reflecting compiler.
|
||||
|
||||
FROM mstorsjo/llvm-mingw:latest
|
||||
|
||||
ARG CMAKE_VERSION=4.2.3
|
||||
|
||||
# The base image is Ubuntu 24.04 with CMake 3.28; Void requires CMake 4.
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends ca-certificates curl git \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN curl -fsSL -o /tmp/cmake.tar.gz \
|
||||
"https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}-linux-x86_64.tar.gz" \
|
||||
&& tar -xzf /tmp/cmake.tar.gz -C /opt \
|
||||
&& ln -sf "/opt/cmake-${CMAKE_VERSION}-linux-x86_64/bin/cmake" /usr/local/bin/cmake \
|
||||
&& ln -sf "/opt/cmake-${CMAKE_VERSION}-linux-x86_64/bin/ctest" /usr/local/bin/ctest \
|
||||
&& ln -sf "/opt/cmake-${CMAKE_VERSION}-linux-x86_64/bin/cpack" /usr/local/bin/cpack \
|
||||
&& rm /tmp/cmake.tar.gz
|
||||
|
||||
ENV PATH="/opt/llvm-mingw/bin:${PATH}"
|
||||
|
||||
WORKDIR /src
|
||||
|
||||
CMD ["bash"]
|
||||
@@ -33,7 +33,7 @@ function(void_probe_capabilities)
|
||||
endif()
|
||||
|
||||
cmake_push_check_state(RESET)
|
||||
set(CMAKE_REQUIRED_FLAGS "-std=c++26")
|
||||
set(CMAKE_REQUIRED_FLAGS "-std=c++${CMAKE_CXX_STANDARD}")
|
||||
check_cxx_source_compiles(
|
||||
"#include <expected>\nint main() { std::expected<int, int> e{0}; return *e; }\n"
|
||||
VOID_HAS_STD_EXPECTED
|
||||
@@ -46,10 +46,12 @@ function(void_probe_capabilities)
|
||||
endif()
|
||||
|
||||
cmake_push_check_state(RESET)
|
||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 16)
|
||||
set(CMAKE_REQUIRED_FLAGS "-std=c++26 -freflection")
|
||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND
|
||||
CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 16 AND
|
||||
CMAKE_CXX_STANDARD GREATER_EQUAL 26)
|
||||
set(CMAKE_REQUIRED_FLAGS "-std=c++${CMAKE_CXX_STANDARD} -freflection")
|
||||
else()
|
||||
set(CMAKE_REQUIRED_FLAGS "-std=c++26")
|
||||
set(CMAKE_REQUIRED_FLAGS "-std=c++${CMAKE_CXX_STANDARD}")
|
||||
endif()
|
||||
check_cxx_source_compiles(
|
||||
"#include <meta>\nconsteval bool probe() { constexpr auto r = ^^int; return std::meta::is_type(r); }\nstatic_assert(probe());\nint main() { return 0; }\n"
|
||||
|
||||
+3
-3
@@ -33,7 +33,7 @@ function(void_add_module MODULE_NAME)
|
||||
set(LIB_TYPE "INTERFACE")
|
||||
set(SCOPE "INTERFACE")
|
||||
add_library(${TGT} INTERFACE)
|
||||
target_compile_features(${TGT} INTERFACE cxx_std_26)
|
||||
target_compile_features(${TGT} INTERFACE cxx_std_${CMAKE_CXX_STANDARD})
|
||||
else()
|
||||
set(SCOPE "PUBLIC")
|
||||
if (MODULE_NAME STREQUAL "Testing")
|
||||
@@ -45,7 +45,7 @@ function(void_add_module MODULE_NAME)
|
||||
add_library(${TGT})
|
||||
endif()
|
||||
target_sources(${TGT} PRIVATE ${SRC})
|
||||
target_compile_features(${TGT} PUBLIC cxx_std_26)
|
||||
target_compile_features(${TGT} PUBLIC cxx_std_${CMAKE_CXX_STANDARD})
|
||||
endif()
|
||||
get_target_property(_module_target_type ${TGT} TYPE)
|
||||
if(_module_target_type STREQUAL "SHARED_LIBRARY" OR
|
||||
@@ -221,7 +221,7 @@ function(void_add_module MODULE_NAME)
|
||||
endif()
|
||||
|
||||
set_target_properties(${TGT} PROPERTIES
|
||||
CXX_STANDARD 26
|
||||
CXX_STANDARD ${CMAKE_CXX_STANDARD}
|
||||
CXX_STANDARD_REQUIRED ON
|
||||
CXX_EXTENSIONS OFF
|
||||
EXPORT_NAME ${MODULE_NAME}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
# CMake toolchain for cross-compiling to Windows x64 with MinGW-w64.
|
||||
#
|
||||
# Works with the GCC-based mingw-w64 package and with the LLVM-MinGW
|
||||
# toolchain (Dockerfile.mingw). Override the compiler paths for your install.
|
||||
#
|
||||
# Usage:
|
||||
# cmake -B build-mingw -S . -G Ninja \
|
||||
# -DCMAKE_TOOLCHAIN_FILE=cmake/toolchains/mingw-w64.cmake \
|
||||
# -DCMAKE_BUILD_TYPE=Debug
|
||||
|
||||
set(CMAKE_SYSTEM_NAME Windows)
|
||||
set(CMAKE_SYSTEM_PROCESSOR x86_64)
|
||||
|
||||
if(NOT DEFINED VOID_MINGW_PREFIX)
|
||||
set(VOID_MINGW_PREFIX x86_64-w64-mingw32)
|
||||
endif()
|
||||
|
||||
find_program(VOID_MINGW_CXX NAMES "${VOID_MINGW_PREFIX}-clang++"
|
||||
"${VOID_MINGW_PREFIX}-g++" REQUIRED)
|
||||
find_program(VOID_MINGW_C NAMES "${VOID_MINGW_PREFIX}-clang"
|
||||
"${VOID_MINGW_PREFIX}-gcc" REQUIRED)
|
||||
find_program(VOID_MINGW_RC NAMES "${VOID_MINGW_PREFIX}-windres")
|
||||
|
||||
set(CMAKE_CXX_COMPILER "${VOID_MINGW_CXX}")
|
||||
set(CMAKE_C_COMPILER "${VOID_MINGW_C}")
|
||||
if(VOID_MINGW_RC)
|
||||
set(CMAKE_RC_COMPILER "${VOID_MINGW_RC}")
|
||||
endif()
|
||||
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
|
||||
@@ -263,6 +263,7 @@ class AudioDevice
|
||||
HWAVEOUT wave{};
|
||||
WAVEHDR header{};
|
||||
WAVEFORMATEX format{};
|
||||
std::vector<PcmSample> playback;
|
||||
bool prepared{false};
|
||||
#endif
|
||||
};
|
||||
@@ -343,11 +344,14 @@ class AudioDevice
|
||||
"waveOutOpen failed"}};
|
||||
}
|
||||
voice.header = WAVEHDR{};
|
||||
// waveOut only reads the samples, but WAVEHDR exposes a mutable
|
||||
// buffer; keep an owned mutable copy instead of casting away
|
||||
// constness of the shared buffer.
|
||||
voice.playback = voice.buffer->samples;
|
||||
voice.header.lpData =
|
||||
reinterpret_cast<LPSTR>(
|
||||
const_cast<PcmSample*>(voice.buffer->samples.data()));
|
||||
reinterpret_cast<LPSTR>(voice.playback.data());
|
||||
voice.header.dwBufferLength = static_cast<DWORD>(
|
||||
voice.buffer->samples.size() * sizeof(PcmSample));
|
||||
voice.playback.size() * sizeof(PcmSample));
|
||||
if (::waveOutPrepareHeader(voice.wave, &voice.header,
|
||||
sizeof(WAVEHDR)) !=
|
||||
MMSYSERR_NOERROR) {
|
||||
|
||||
@@ -209,22 +209,18 @@ private:
|
||||
|
||||
[[nodiscard]] inline std::string win32_message(DWORD error)
|
||||
{
|
||||
char* buffer = nullptr;
|
||||
std::array<char, 512> buffer{};
|
||||
const DWORD length = ::FormatMessageA(
|
||||
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
nullptr,
|
||||
error,
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
reinterpret_cast<char*>(&buffer),
|
||||
0,
|
||||
buffer.data(),
|
||||
static_cast<DWORD>(buffer.size()),
|
||||
nullptr);
|
||||
std::string message = (length != 0 && buffer != nullptr)
|
||||
? std::string{buffer, length}
|
||||
std::string message = length != 0
|
||||
? std::string{buffer.data(), length}
|
||||
: std::string{"unknown error"};
|
||||
if (buffer != nullptr) {
|
||||
::LocalFree(buffer);
|
||||
}
|
||||
while (!message.empty() &&
|
||||
(message.back() == '\n' || message.back() == '\r' ||
|
||||
message.back() == ' ' || message.back() == '.')) {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <Void/Core/Meta.hpp>
|
||||
#include <Void/Testing/Annotations.hpp>
|
||||
#include <Void/Testing/Config.hpp>
|
||||
#include <Void/Testing/Detail/Registry.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
@@ -11,6 +10,7 @@
|
||||
|
||||
#if __has_include(<meta>)
|
||||
#include <meta>
|
||||
#include <Void/Testing/Annotations.hpp>
|
||||
#define VOID_TESTING_HAS_REFLECTION 1
|
||||
#endif
|
||||
|
||||
@@ -95,6 +95,13 @@ namespace Void::Testing
|
||||
}
|
||||
}
|
||||
|
||||
/// Non-capturing thunk: a template argument is a constant
|
||||
/// expression, unlike a reflected member captured by a lambda.
|
||||
template <meta::info M> static void run_method_thunk()
|
||||
{
|
||||
run_method<M>();
|
||||
}
|
||||
|
||||
static std::string suite_label()
|
||||
{
|
||||
if constexpr (constexpr auto n =
|
||||
@@ -138,12 +145,17 @@ namespace Void::Testing
|
||||
skip_reason = std::string{s->reason.view()};
|
||||
}
|
||||
|
||||
constexpr auto name = meta::identifier_of(m);
|
||||
constexpr const char* file = loc.file_name();
|
||||
constexpr int line =
|
||||
static_cast<int>(loc.line());
|
||||
constexpr auto run = &run_method_thunk<m>;
|
||||
reg.add(TestCase{
|
||||
.run = [] { run_method<m>(); },
|
||||
.name = std::string{meta::identifier_of(m)},
|
||||
.run = run,
|
||||
.name = std::string{name},
|
||||
.suite = suite,
|
||||
.file = loc.file_name(),
|
||||
.line = static_cast<int>(loc.line()),
|
||||
.file = file,
|
||||
.line = line,
|
||||
.disabled = disabled,
|
||||
.skip_reason = std::move(skip_reason),
|
||||
.tags = std::move(tags),
|
||||
|
||||
@@ -8,14 +8,14 @@ namespace Void::Testing {
|
||||
using namespace Void::Testing::Detail::Color;
|
||||
|
||||
void ConsoleReporter::on_run_start(const RunConfig&, int total_tests) {
|
||||
os_ << "\n" << apply(bold_blue, "╭──────────────────────────────────────────────╮") << "\n"
|
||||
<< apply(bold_blue, "│") << apply(bold_white, " Void Testing") << apply(dim, " v1.0") << std::string(31, ' ') << apply(bold_blue, "│") << "\n"
|
||||
<< std::format("{}│{} Discovered {} test{}{}│\n", apply(bold_blue, "╰"), apply(dim, ""), apply(bold_white, std::to_string(total_tests)), total_tests != 1 ? "s" : "", std::string(total_tests < 10 ? 33 : 28, ' '))
|
||||
<< apply(bold_blue, "╰──────────────────────────────────────────────╯") << "\n\n";
|
||||
os_ << "\n" << Void::Testing::Detail::Color::apply(bold_blue, "╭──────────────────────────────────────────────╮") << "\n"
|
||||
<< Void::Testing::Detail::Color::apply(bold_blue, "│") << Void::Testing::Detail::Color::apply(bold_white, " Void Testing") << Void::Testing::Detail::Color::apply(dim, " v1.0") << std::string(31, ' ') << Void::Testing::Detail::Color::apply(bold_blue, "│") << "\n"
|
||||
<< std::format("{}│{} Discovered {} test{}{}│\n", Void::Testing::Detail::Color::apply(bold_blue, "╰"), Void::Testing::Detail::Color::apply(dim, ""), Void::Testing::Detail::Color::apply(bold_white, std::to_string(total_tests)), total_tests != 1 ? "s" : "", std::string(total_tests < 10 ? 33 : 28, ' '))
|
||||
<< Void::Testing::Detail::Color::apply(bold_blue, "╰──────────────────────────────────────────────╯") << "\n\n";
|
||||
}
|
||||
|
||||
void ConsoleReporter::on_suite_start(const std::string& suite_name, int test_count) {
|
||||
os_ << std::format(" {} {} [{} test{}]\n", apply(bold_blue, "◆"), apply(bold_white, suite_name), apply(dim, std::to_string(test_count)), test_count != 1 ? "s" : "");
|
||||
os_ << std::format(" {} {} [{} test{}]\n", Void::Testing::Detail::Color::apply(bold_blue, "◆"), Void::Testing::Detail::Color::apply(bold_white, suite_name), Void::Testing::Detail::Color::apply(dim, std::to_string(test_count)), test_count != 1 ? "s" : "");
|
||||
}
|
||||
|
||||
void ConsoleReporter::on_test_start(const TestCase&) {}
|
||||
@@ -25,46 +25,46 @@ void ConsoleReporter::on_test_end(const TestResult& result) {
|
||||
double ms = std::chrono::duration<double, std::milli>(result.duration).count();
|
||||
std::string time_str = ms < 1.0 ? std::format("{:.3f}ms", ms) : std::format("{:.1f}ms", ms);
|
||||
std::string tags_str;
|
||||
if (!result.tags.empty()) { for(const auto& t : result.tags) tags_str += "[" + t + "]"; tags_str = " " + apply(dim, tags_str); }
|
||||
if (!result.tags.empty()) { for(const auto& t : result.tags) tags_str += "[" + t + "]"; tags_str = " " + Void::Testing::Detail::Color::apply(dim, tags_str); }
|
||||
|
||||
switch (result.state) {
|
||||
case TestState::Passed: os_ << std::format(" {} {:<40s}{}{}\n", apply(bold_green, "✔"), apply(green, result.name), tags_str, apply(dim, time_str)); break;
|
||||
case TestState::Passed: os_ << std::format(" {} {:<40s}{}{}\n", Void::Testing::Detail::Color::apply(bold_green, "✔"), Void::Testing::Detail::Color::apply(green, result.name), tags_str, Void::Testing::Detail::Color::apply(dim, time_str)); break;
|
||||
case TestState::Failed:
|
||||
os_ << std::format(" {} {:<40s}{}{}\n", apply(bold_red, "✘"), apply(red, result.name), tags_str, apply(dim, time_str));
|
||||
os_ << std::format(" {} {:<40s}{}{}\n", Void::Testing::Detail::Color::apply(bold_red, "✘"), Void::Testing::Detail::Color::apply(red, result.name), tags_str, Void::Testing::Detail::Color::apply(dim, time_str));
|
||||
for (const auto& ar : result.assertions) if (!ar.passed) print_assertion_failure(ar);
|
||||
if (!result.crash_info.empty()) print_crash_info(result);
|
||||
break;
|
||||
case TestState::Skipped: os_ << std::format(" {} {:<40s}{}\n", apply(bold_yellow, "⊘"), apply(yellow, result.name), apply(dim, std::format("[SKIPPED: {}]", result.skip_reason.empty() ? "no reason" : result.skip_reason))); break;
|
||||
case TestState::Crashed: os_ << std::format(" {} {:<40s}{}\n", apply(bold_red, "⚡"), apply(red, result.name), apply(dim, time_str)); print_crash_info(result); break;
|
||||
case TestState::Skipped: os_ << std::format(" {} {:<40s}{}\n", Void::Testing::Detail::Color::apply(bold_yellow, "⊘"), Void::Testing::Detail::Color::apply(yellow, result.name), Void::Testing::Detail::Color::apply(dim, std::format("[SKIPPED: {}]", result.skip_reason.empty() ? "no reason" : result.skip_reason))); break;
|
||||
case TestState::Crashed: os_ << std::format(" {} {:<40s}{}\n", Void::Testing::Detail::Color::apply(bold_red, "⚡"), Void::Testing::Detail::Color::apply(red, result.name), Void::Testing::Detail::Color::apply(dim, time_str)); print_crash_info(result); break;
|
||||
}
|
||||
}
|
||||
|
||||
void ConsoleReporter::print_assertion_failure(const AssertionResult& ar) {
|
||||
os_ << apply(red, " ╭─── Assertion Failed") << apply(dim, " ──────────────────────╮") << "\n";
|
||||
os_ << Void::Testing::Detail::Color::apply(red, " ╭─── Assertion Failed") << Void::Testing::Detail::Color::apply(dim, " ──────────────────────╮") << "\n";
|
||||
std::filesystem::path p{ar.location.file_name()};
|
||||
os_ << std::format(" │ {}:{}\n", apply(bold_white, p.filename().string()), ar.location.line());
|
||||
if (!ar.expression.empty()) os_ << std::format(" │ {}\n", apply(cyan, ar.expression));
|
||||
if (!ar.expected_repr.empty()) os_ << std::format(" │ {} {}\n", apply(bold_white, "expected:"), apply(green, ar.expected_repr));
|
||||
if (!ar.actual_repr.empty()) os_ << std::format(" │ {} {}\n", apply(bold_white, "actual: "), apply(red, ar.actual_repr));
|
||||
os_ << std::format(" │ {}:{}\n", Void::Testing::Detail::Color::apply(bold_white, p.filename().string()), ar.location.line());
|
||||
if (!ar.expression.empty()) os_ << std::format(" │ {}\n", Void::Testing::Detail::Color::apply(cyan, ar.expression));
|
||||
if (!ar.expected_repr.empty()) os_ << std::format(" │ {} {}\n", Void::Testing::Detail::Color::apply(bold_white, "expected:"), Void::Testing::Detail::Color::apply(green, ar.expected_repr));
|
||||
if (!ar.actual_repr.empty()) os_ << std::format(" │ {} {}\n", Void::Testing::Detail::Color::apply(bold_white, "actual: "), Void::Testing::Detail::Color::apply(red, ar.actual_repr));
|
||||
if (!ar.message.empty()) os_ << std::format(" │ {}\n", ar.message);
|
||||
os_ << apply(red, " ╰────────────────────────────────────────────╯") << "\n";
|
||||
os_ << Void::Testing::Detail::Color::apply(red, " ╰────────────────────────────────────────────╯") << "\n";
|
||||
}
|
||||
|
||||
void ConsoleReporter::print_crash_info(const TestResult& result) {
|
||||
os_ << apply(bold_red, " ╭─── Crash") << apply(dim, " ───────────────────────────╮") << "\n";
|
||||
if (!result.crash_info.empty()) os_ << std::format(" │ {}\n", apply(red, result.crash_info));
|
||||
os_ << apply(bold_red, " ╰────────────────────────────────────────────╯") << "\n";
|
||||
if (!result.stacktrace.empty()) os_ << apply(dim, " Stacktrace:\n") << result.stacktrace << "\n";
|
||||
os_ << Void::Testing::Detail::Color::apply(bold_red, " ╭─── Crash") << Void::Testing::Detail::Color::apply(dim, " ───────────────────────────╮") << "\n";
|
||||
if (!result.crash_info.empty()) os_ << std::format(" │ {}\n", Void::Testing::Detail::Color::apply(red, result.crash_info));
|
||||
os_ << Void::Testing::Detail::Color::apply(bold_red, " ╰────────────────────────────────────────────╯") << "\n";
|
||||
if (!result.stacktrace.empty()) os_ << Void::Testing::Detail::Color::apply(dim, " Stacktrace:\n") << result.stacktrace << "\n";
|
||||
}
|
||||
|
||||
void ConsoleReporter::on_run_end(const RunResult& result) {
|
||||
os_ << "\n" << apply(dim, "╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍") << "\n"
|
||||
<< std::format(" {} tests: ", apply(bold_white, std::to_string(result.total)));
|
||||
if (result.passed > 0) os_ << std::format("{} {} ", apply(bold_green, std::to_string(result.passed)), apply(green, "✔"));
|
||||
if (result.failed + result.crashed > 0) os_ << std::format("{} {} ", apply(bold_red, std::to_string(result.failed + result.crashed)), apply(red, "✘"));
|
||||
if (result.skipped > 0) os_ << std::format("{} {} ", apply(bold_yellow, std::to_string(result.skipped)), apply(yellow, "⊘"));
|
||||
os_ << "\n" << Void::Testing::Detail::Color::apply(dim, "╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍") << "\n"
|
||||
<< std::format(" {} tests: ", Void::Testing::Detail::Color::apply(bold_white, std::to_string(result.total)));
|
||||
if (result.passed > 0) os_ << std::format("{} {} ", Void::Testing::Detail::Color::apply(bold_green, std::to_string(result.passed)), Void::Testing::Detail::Color::apply(green, "✔"));
|
||||
if (result.failed + result.crashed > 0) os_ << std::format("{} {} ", Void::Testing::Detail::Color::apply(bold_red, std::to_string(result.failed + result.crashed)), Void::Testing::Detail::Color::apply(red, "✘"));
|
||||
if (result.skipped > 0) os_ << std::format("{} {} ", Void::Testing::Detail::Color::apply(bold_yellow, std::to_string(result.skipped)), Void::Testing::Detail::Color::apply(yellow, "⊘"));
|
||||
double total_ms = std::chrono::duration<double, std::milli>(result.total_duration).count();
|
||||
os_ << std::format(" {} {}\n", apply(dim, "in"), apply(bold_cyan, total_ms < 1000 ? std::format("{:.1f}ms", total_ms) : std::format("{:.2f}s", total_ms / 1000.0)))
|
||||
<< apply(dim, "╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍") << "\n\n";
|
||||
os_ << std::format(" {} {}\n", Void::Testing::Detail::Color::apply(dim, "in"), Void::Testing::Detail::Color::apply(bold_cyan, total_ms < 1000 ? std::format("{:.1f}ms", total_ms) : std::format("{:.2f}s", total_ms / 1000.0)))
|
||||
<< Void::Testing::Detail::Color::apply(dim, "╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍") << "\n\n";
|
||||
}
|
||||
} // namespace Void::Testing
|
||||
+36
-36
@@ -447,7 +447,7 @@ namespace Void::Testing
|
||||
|
||||
std::cout
|
||||
<< "\n"
|
||||
<< apply(bold_blue,
|
||||
<< Void::Testing::Detail::Color::apply(bold_blue,
|
||||
"\xe2\x95\xad\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80"
|
||||
"\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80"
|
||||
"\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80"
|
||||
@@ -461,12 +461,12 @@ namespace Void::Testing
|
||||
"\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80"
|
||||
"\xe2\x94\x80\xe2\x94\x80\xe2\x95\xae")
|
||||
<< "\n"
|
||||
<< apply(bold_blue, "\xe2\x94\x82")
|
||||
<< apply(bold_white, " Void Testing")
|
||||
<< apply(dim, " \xe2\x80\x94 Command Line Interface")
|
||||
<< std::string(28, ' ') << apply(bold_blue, "\xe2\x94\x82")
|
||||
<< Void::Testing::Detail::Color::apply(bold_blue, "\xe2\x94\x82")
|
||||
<< Void::Testing::Detail::Color::apply(bold_white, " Void Testing")
|
||||
<< Void::Testing::Detail::Color::apply(dim, " \xe2\x80\x94 Command Line Interface")
|
||||
<< std::string(28, ' ') << Void::Testing::Detail::Color::apply(bold_blue, "\xe2\x94\x82")
|
||||
<< "\n"
|
||||
<< apply(bold_blue,
|
||||
<< Void::Testing::Detail::Color::apply(bold_blue,
|
||||
"\xe2\x95\xb0\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80"
|
||||
"\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80"
|
||||
"\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80"
|
||||
@@ -481,76 +481,76 @@ namespace Void::Testing
|
||||
"\xe2\x94\x80\xe2\x94\x80\xe2\x95\xaf")
|
||||
<< "\n"
|
||||
<< "\n"
|
||||
<< " " << apply(bold_white, "USAGE:") << "\n"
|
||||
<< " " << apply(cyan, "<executable>") << " "
|
||||
<< apply(dim, "[options]") << "\n"
|
||||
<< " " << Void::Testing::Detail::Color::apply(bold_white, "USAGE:") << "\n"
|
||||
<< " " << Void::Testing::Detail::Color::apply(cyan, "<executable>") << " "
|
||||
<< Void::Testing::Detail::Color::apply(dim, "[options]") << "\n"
|
||||
<< "\n"
|
||||
<< " " << apply(bold_white, "OPTIONS:") << "\n";
|
||||
<< " " << Void::Testing::Detail::Color::apply(bold_white, "OPTIONS:") << "\n";
|
||||
|
||||
constexpr std::size_t OPT_WIDTH = 23;
|
||||
auto opt = [&](std::string_view name) {
|
||||
#ifdef VOID_HAS_TEXT
|
||||
return apply(green, Void::Str::pad_right(name, OPT_WIDTH));
|
||||
return Void::Testing::Detail::Color::apply(green, Void::Str::pad_right(name, OPT_WIDTH));
|
||||
#else
|
||||
std::string s{name};
|
||||
if (s.size() < OPT_WIDTH) {
|
||||
s.append(OPT_WIDTH - s.size(), ' ');
|
||||
}
|
||||
return apply(green, s);
|
||||
return Void::Testing::Detail::Color::apply(green, s);
|
||||
#endif
|
||||
};
|
||||
|
||||
std::cout
|
||||
<< " " << opt("--filter <pattern>")
|
||||
<< apply(dim, "Run tests matching the regex pattern") << "\n"
|
||||
<< Void::Testing::Detail::Color::apply(dim, "Run tests matching the regex pattern") << "\n"
|
||||
<< " " << opt("--suite <name>")
|
||||
<< apply(dim, "Run only tests in the specified suite") << "\n"
|
||||
<< Void::Testing::Detail::Color::apply(dim, "Run only tests in the specified suite") << "\n"
|
||||
<< " " << opt("--tag <name>")
|
||||
<< apply(dim, "Run only tests with the specified tag") << "\n"
|
||||
<< Void::Testing::Detail::Color::apply(dim, "Run only tests with the specified tag") << "\n"
|
||||
<< " " << opt("--list")
|
||||
<< apply(dim, "List discovered tests without running them")
|
||||
<< Void::Testing::Detail::Color::apply(dim, "List discovered tests without running them")
|
||||
<< "\n"
|
||||
<< " " << opt("--shuffle")
|
||||
<< apply(dim, "Randomize the order of test execution") << "\n"
|
||||
<< Void::Testing::Detail::Color::apply(dim, "Randomize the order of test execution") << "\n"
|
||||
<< " " << opt("--seed <n>")
|
||||
<< apply(dim, "Set the random seed (implies --shuffle)") << "\n"
|
||||
<< Void::Testing::Detail::Color::apply(dim, "Set the random seed (implies --shuffle)") << "\n"
|
||||
<< " " << opt("--repeat <n>")
|
||||
<< apply(dim, "Repeat the test run n times") << "\n"
|
||||
<< Void::Testing::Detail::Color::apply(dim, "Repeat the test run n times") << "\n"
|
||||
<< " " << opt("--reporter <type>")
|
||||
<< apply(dim, "Choose the output reporter: console, junit")
|
||||
<< Void::Testing::Detail::Color::apply(dim, "Choose the output reporter: console, junit")
|
||||
<< "\n"
|
||||
<< " " << opt("--output <file>")
|
||||
<< apply(dim, "Write reporter output to a file") << "\n"
|
||||
<< Void::Testing::Detail::Color::apply(dim, "Write reporter output to a file") << "\n"
|
||||
#ifdef VOID_HAS_LOG
|
||||
<< " " << opt("--log-file <file>")
|
||||
<< apply(dim,
|
||||
<< Void::Testing::Detail::Color::apply(dim,
|
||||
"Mirror test events to <file> via Void::Logging")
|
||||
<< "\n"
|
||||
#endif
|
||||
#ifdef VOID_HAS_ASYNC
|
||||
<< " " << opt("--parallel <n>")
|
||||
<< apply(dim,
|
||||
<< Void::Testing::Detail::Color::apply(dim,
|
||||
"Run tests across n threads (no crash detection)")
|
||||
<< "\n"
|
||||
#endif
|
||||
<< " " << opt("--verbose")
|
||||
<< apply(dim, "Enable verbose output") << "\n"
|
||||
<< Void::Testing::Detail::Color::apply(dim, "Enable verbose output") << "\n"
|
||||
<< " " << opt("--no-color")
|
||||
<< apply(dim, "Disable colored console output") << "\n"
|
||||
<< Void::Testing::Detail::Color::apply(dim, "Disable colored console output") << "\n"
|
||||
<< " " << opt("--allow-empty")
|
||||
<< apply(dim, "Do not fail when selection matches zero tests") << "\n"
|
||||
<< Void::Testing::Detail::Color::apply(dim, "Do not fail when selection matches zero tests") << "\n"
|
||||
<< " " << opt("--help")
|
||||
<< apply(dim, "Show this help message") << "\n"
|
||||
<< Void::Testing::Detail::Color::apply(dim, "Show this help message") << "\n"
|
||||
<< "\n"
|
||||
<< " " << apply(bold_white, "EXAMPLES:") << "\n"
|
||||
<< " " << apply(cyan, "./run_tests") << " "
|
||||
<< apply(yellow, "--filter") << " \"math_tests.*\"" << "\n"
|
||||
<< " " << apply(cyan, "./run_tests") << " "
|
||||
<< apply(yellow, "--tag") << " integration "
|
||||
<< apply(yellow, "--shuffle") << "\n"
|
||||
<< " " << apply(cyan, "./run_tests") << " "
|
||||
<< apply(yellow, "--reporter") << " junit "
|
||||
<< apply(yellow, "--output") << " results.xml" << "\n"
|
||||
<< " " << Void::Testing::Detail::Color::apply(bold_white, "EXAMPLES:") << "\n"
|
||||
<< " " << Void::Testing::Detail::Color::apply(cyan, "./run_tests") << " "
|
||||
<< Void::Testing::Detail::Color::apply(yellow, "--filter") << " \"math_tests.*\"" << "\n"
|
||||
<< " " << Void::Testing::Detail::Color::apply(cyan, "./run_tests") << " "
|
||||
<< Void::Testing::Detail::Color::apply(yellow, "--tag") << " integration "
|
||||
<< Void::Testing::Detail::Color::apply(yellow, "--shuffle") << "\n"
|
||||
<< " " << Void::Testing::Detail::Color::apply(cyan, "./run_tests") << " "
|
||||
<< Void::Testing::Detail::Color::apply(yellow, "--reporter") << " junit "
|
||||
<< Void::Testing::Detail::Color::apply(yellow, "--output") << " results.xml" << "\n"
|
||||
<< "\n";
|
||||
|
||||
return {};
|
||||
|
||||
@@ -167,7 +167,7 @@ if(TARGET VoidTests AND (TARGET Void::System OR TARGET Void::IPC))
|
||||
add_executable(VoidProcessHelper
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/helpers/ProcessHelper.cpp")
|
||||
set_target_properties(VoidProcessHelper PROPERTIES
|
||||
CXX_STANDARD 26
|
||||
CXX_STANDARD ${CMAKE_CXX_STANDARD}
|
||||
CXX_STANDARD_REQUIRED ON
|
||||
CXX_EXTENSIONS OFF
|
||||
VOID_TESTING_NO_AUTO_SCAN TRUE)
|
||||
@@ -181,7 +181,7 @@ if(TARGET VoidTests AND TARGET Void::Archive)
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/helpers/ArchiveWorker.cpp")
|
||||
target_link_libraries(VoidArchiveWorker PRIVATE Void::Archive)
|
||||
set_target_properties(VoidArchiveWorker PROPERTIES
|
||||
CXX_STANDARD 26
|
||||
CXX_STANDARD ${CMAKE_CXX_STANDARD}
|
||||
CXX_STANDARD_REQUIRED ON
|
||||
CXX_EXTENSIONS OFF
|
||||
VOID_TESTING_NO_AUTO_SCAN TRUE)
|
||||
|
||||
@@ -33,7 +33,7 @@ Void::Testing::Test request_ledger_replays_exact_repeat()
|
||||
auto repeat = ledger.check(k, "op");
|
||||
Void::Testing::expect(repeat.status == Status::replay);
|
||||
Void::Testing::require(repeat.result.has_value());
|
||||
Void::Testing::expect_eq(*repeat.result, 7);
|
||||
Void::Testing::expect_eq(repeat.result->value(), 7);
|
||||
}
|
||||
|
||||
Void::Testing::Test request_ledger_replays_rejected_outcome()
|
||||
@@ -67,7 +67,7 @@ Void::Testing::Test request_ledger_detects_payload_conflict()
|
||||
// The conflicting retry changed nothing.
|
||||
auto repeat = ledger.check(k, "payload-a");
|
||||
Void::Testing::expect(repeat.status == Status::replay);
|
||||
Void::Testing::expect_eq(*repeat.result, 10);
|
||||
Void::Testing::expect_eq(repeat.result->value(), 10);
|
||||
}
|
||||
|
||||
Void::Testing::Test request_ledger_delayed_retry_after_newer_operations()
|
||||
@@ -82,7 +82,7 @@ Void::Testing::Test request_ledger_delayed_retry_after_newer_operations()
|
||||
|
||||
auto delayed = ledger.check(first, "one");
|
||||
Void::Testing::expect(delayed.status == Status::replay);
|
||||
Void::Testing::expect_eq(*delayed.result, 100);
|
||||
Void::Testing::expect_eq(delayed.result->value(), 100);
|
||||
}
|
||||
|
||||
Void::Testing::Test request_ledger_epoch_rollover()
|
||||
@@ -136,7 +136,7 @@ Void::Testing::Test request_ledger_in_progress_and_result_is_immutable()
|
||||
Void::Testing::expect(!ledger.record(k, 6));
|
||||
auto repeat = ledger.check(k, "op");
|
||||
Void::Testing::expect(repeat.status == Status::replay);
|
||||
Void::Testing::expect_eq(*repeat.result, 5);
|
||||
Void::Testing::expect_eq(repeat.result->value(), 5);
|
||||
|
||||
const auto snap = ledger.snapshot();
|
||||
Void::Testing::expect_eq(snap.size, std::size_t{1});
|
||||
|
||||
Reference in new issue
Block a user