New header-only modules: - Void::Hash — FNV-1a 32/64, CRC-32, DJB2, MurmurHash3-32, UDL literals - Void::Random — Xoshiro256** PRNG, uniform_int/real, coin_flip, shuffle, random_string - Void::Uuid — v4 (random), v5_lite (name-based), parse, RFC 4122 namespaces - Void::Encoding — Base64 (standard + URL-safe), Hex encode/decode - Void::Bits — popcount, bit extract/deposit, rotation, align, byteswap, masks - Void::Math — Vec2/Vec3/Vec4, Mat4 (identity, translation, scale, rotation) Testing module: move Stacktrace from INTERNAL_DEPS to OPTIONAL_DEPS. Added Detail/Color.hpp shim that delegates to Stacktrace::Color when present or provides inline ANSI fallback otherwise. All Stacktrace calls in SignalHandler, ConsoleReporter, and Runner are gated on VOID_HAS_STACKTRACE. Fix Repr.hpp reflect_struct to handle template specializations that lack std::meta::identifier_of (now guarded by has_identifier check). 33/33 tests pass. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
108 lines
2.8 KiB
C++
108 lines
2.8 KiB
C++
#include <Void/Log/Log.hpp>
|
|
#include <Void/Testing/Assert.hpp>
|
|
#include <Void/Testing/Test.hpp>
|
|
|
|
#include <atomic>
|
|
#include <string>
|
|
#include <thread>
|
|
#include <vector>
|
|
|
|
// Reset the global sink between tests via a scoped RAII guard.
|
|
struct SinkGuard {
|
|
~SinkGuard() { Void::Log::set_sink({}); }
|
|
};
|
|
|
|
Void::Testing::Test no_sink_is_silent()
|
|
{
|
|
SinkGuard guard;
|
|
bool called = false;
|
|
// No sink installed — this must not crash or invoke anything.
|
|
Void::Log::log(Void::Log::Level::Info, "test", "silent message");
|
|
Void::Testing::expect(!called);
|
|
}
|
|
|
|
Void::Testing::Test sink_receives_all_fields()
|
|
{
|
|
SinkGuard guard;
|
|
Void::Log::Level got_level{};
|
|
std::string got_module;
|
|
std::string got_message;
|
|
|
|
Void::Log::set_sink(
|
|
[&](Void::Log::Level l, std::string_view mod, std::string_view msg) {
|
|
got_level = l;
|
|
got_module = mod;
|
|
got_message = msg;
|
|
});
|
|
|
|
Void::Log::log(Void::Log::Level::Warning, "MyModule", "something happened");
|
|
|
|
Void::Testing::expect(got_level == Void::Log::Level::Warning);
|
|
Void::Testing::expect(got_module == "MyModule");
|
|
Void::Testing::expect(got_message == "something happened");
|
|
}
|
|
|
|
Void::Testing::Test set_sink_replaces_previous()
|
|
{
|
|
SinkGuard guard;
|
|
int first_calls = 0;
|
|
int second_calls = 0;
|
|
|
|
Void::Log::set_sink([&](auto, auto, auto) { ++first_calls; });
|
|
Void::Log::log(Void::Log::Level::Info, "m", "a");
|
|
|
|
Void::Log::set_sink([&](auto, auto, auto) { ++second_calls; });
|
|
Void::Log::log(Void::Log::Level::Info, "m", "b");
|
|
|
|
Void::Testing::expect_eq(first_calls, 1);
|
|
Void::Testing::expect_eq(second_calls, 1);
|
|
}
|
|
|
|
Void::Testing::Test clear_sink_silences_output()
|
|
{
|
|
SinkGuard guard;
|
|
int calls = 0;
|
|
Void::Log::set_sink([&](auto, auto, auto) { ++calls; });
|
|
Void::Log::log(Void::Log::Level::Info, "m", "before clear");
|
|
Void::Log::set_sink({});
|
|
Void::Log::log(Void::Log::Level::Info, "m", "after clear");
|
|
Void::Testing::expect_eq(calls, 1);
|
|
}
|
|
|
|
Void::Testing::Test concurrent_log_calls_are_safe()
|
|
{
|
|
SinkGuard guard;
|
|
std::atomic<int> count{0};
|
|
Void::Log::set_sink([&](auto, auto, auto) { ++count; });
|
|
|
|
constexpr int N = 64;
|
|
std::vector<std::thread> threads;
|
|
threads.reserve(N);
|
|
for (int i = 0; i < N; ++i) {
|
|
threads.emplace_back([] {
|
|
Void::Log::log(Void::Log::Level::Debug, "test", "concurrent");
|
|
});
|
|
}
|
|
for (auto& t : threads) {
|
|
t.join();
|
|
}
|
|
|
|
Void::Testing::expect_eq(count.load(), N);
|
|
}
|
|
|
|
Void::Testing::Test all_levels_are_forwarded()
|
|
{
|
|
SinkGuard guard;
|
|
int calls = 0;
|
|
Void::Log::set_sink([&](auto, auto, auto) { ++calls; });
|
|
|
|
Void::Log::log(Void::Log::Level::Trace, "m", "t");
|
|
Void::Log::log(Void::Log::Level::Debug, "m", "d");
|
|
Void::Log::log(Void::Log::Level::Info, "m", "i");
|
|
Void::Log::log(Void::Log::Level::Warning, "m", "w");
|
|
Void::Log::log(Void::Log::Level::Error, "m", "e");
|
|
Void::Log::log(Void::Log::Level::Fatal, "m", "f");
|
|
|
|
Void::Testing::expect_eq(calls, 6);
|
|
}
|