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>
172 lines
5.9 KiB
C++
172 lines
5.9 KiB
C++
// Cross-module integration tests for the kitchen-sink VoidInternalTests
|
|
// binary. Exercises Logging + Result + Stacktrace + FileSystem + Log working
|
|
// together — the kind of thing the standalone per-module tests can't
|
|
// reach because they only link one module.
|
|
|
|
#include <Void/FileSystem/Path.hpp>
|
|
#include <Void/FileSystem/TempDir.hpp>
|
|
#include <Void/Log/Log.hpp>
|
|
#include <Void/Log/LoggingAdapter.hpp>
|
|
#include <Void/Logging/ConsoleLogger.hpp>
|
|
#include <Void/Logging/FileLogger.hpp>
|
|
#include <Void/Logging/Level.hpp>
|
|
#include <Void/Result/Error.hpp>
|
|
#include <Void/Result/Result.hpp>
|
|
#include <Void/Stacktrace/Stacktrace.hpp>
|
|
#include <Void/Testing/Assert.hpp>
|
|
#include <Void/Testing/Test.hpp>
|
|
|
|
#include <filesystem>
|
|
#include <sstream>
|
|
#include <string>
|
|
|
|
namespace
|
|
{
|
|
struct ConfigError {
|
|
std::string file;
|
|
int line;
|
|
std::string detail;
|
|
};
|
|
} // namespace
|
|
|
|
// Reflection-based repr (Phase 2.6) renders user-defined error structs
|
|
// inside Testing assertions without any per-type formatter.
|
|
Void::Testing::Test repr_handles_user_error_struct()
|
|
{
|
|
const auto out = Void::Testing::Detail::repr(
|
|
ConfigError{"settings.toml", 17, "missing key 'name'"});
|
|
Void::Testing::expect(out.find("ConfigError") != std::string::npos);
|
|
Void::Testing::expect(out.find("file: settings.toml") != std::string::npos);
|
|
Void::Testing::expect(out.find("line: 17") != std::string::npos);
|
|
Void::Testing::expect(out.find("detail: missing key 'name'") !=
|
|
std::string::npos);
|
|
}
|
|
|
|
// Result + Stacktrace: read_source_snippet returns Result, and a missing
|
|
// file produces an Error whose chained message is rendered correctly.
|
|
Void::Testing::Test stacktrace_snippet_returns_result_on_missing_file()
|
|
{
|
|
auto r = Void::Stacktrace::read_source_snippet(
|
|
"/this/path/does/not/exist.cpp", 10);
|
|
Void::Testing::expect(!r.has_value());
|
|
const auto chained = Void::Result::with_context(r, "loading test fixture");
|
|
const auto rendered = chained.error().format();
|
|
Void::Testing::expect(rendered.find("loading test fixture") !=
|
|
std::string::npos);
|
|
Void::Testing::expect(rendered.find("read_source_snippet") !=
|
|
std::string::npos);
|
|
Void::Testing::expect(rendered.find("caused by:") != std::string::npos);
|
|
}
|
|
|
|
// Logging + Result: FileLogger::open returns Result; chained context
|
|
// surfaces meaningfully.
|
|
Void::Testing::Test file_logger_open_failure_chains_into_context()
|
|
{
|
|
auto r = Void::Logging::FileLogger::open("/no/such/dir/test.log");
|
|
Void::Testing::expect(!r.has_value());
|
|
auto wrapped =
|
|
Void::Result::with_context(std::move(r), "starting test runner");
|
|
const auto rendered = wrapped.error().format();
|
|
Void::Testing::expect(rendered.find("starting test runner") !=
|
|
std::string::npos);
|
|
Void::Testing::expect(rendered.find("FileLogger") != std::string::npos);
|
|
}
|
|
|
|
// Logging emits scope boundaries that survive into the output stream.
|
|
Void::Testing::Test logger_scope_entries_render_through_console_sink()
|
|
{
|
|
std::ostringstream out;
|
|
{
|
|
Void::Logging::ConsoleLogger log(out);
|
|
log.set_level(Void::Logging::Level::Trace);
|
|
auto scope = log.push_scope("worker");
|
|
log.info("doing work");
|
|
}
|
|
const auto content = out.str();
|
|
Void::Testing::expect(content.find("doing work") != std::string::npos);
|
|
Void::Testing::expect(content.find("worker") != std::string::npos);
|
|
}
|
|
|
|
// Logging + Result + FileSystem: roundtrip a chained error into a
|
|
// FileLogger sink and read it back through Void::FileSystem::read_file
|
|
// (no manual std::filesystem boilerplate, no manual cleanup).
|
|
Void::Testing::Test error_chain_logged_to_file_roundtrip()
|
|
{
|
|
Void::FileSystem::TempDir tmp;
|
|
const auto path = tmp / "log.txt";
|
|
|
|
{
|
|
auto sink_r = Void::Logging::FileLogger::open(
|
|
path, Void::Logging::Mode::Buffered, 8);
|
|
Void::Testing::expect(sink_r.has_value());
|
|
auto& sink = **sink_r;
|
|
|
|
Void::Result::Error inner{"socket closed"};
|
|
auto outer = inner.with_context("api request /users");
|
|
sink.error(outer.format());
|
|
}
|
|
|
|
auto read_back = Void::FileSystem::read_file(path);
|
|
Void::Testing::expect(read_back.has_value());
|
|
const auto& content = *read_back;
|
|
|
|
Void::Testing::expect(content.find("api request /users") !=
|
|
std::string::npos);
|
|
Void::Testing::expect(content.find("socket closed") != std::string::npos);
|
|
Void::Testing::expect(content.find("caused by:") != std::string::npos);
|
|
}
|
|
|
|
// Void::Log + Void::Logging: make_sink() bridges the two modules so that
|
|
// internal library events routed through Void::Log::log() surface in a
|
|
// Void::Logging::ConsoleLogger captured via a stringstream.
|
|
Void::Testing::Test log_adapter_routes_to_void_logging()
|
|
{
|
|
std::ostringstream out;
|
|
Void::Logging::ConsoleLogger logger{out};
|
|
logger.set_level(Void::Logging::Level::Trace);
|
|
|
|
Void::Log::set_sink(Void::Log::make_sink(logger));
|
|
|
|
Void::Log::log(
|
|
Void::Log::Level::Info, "TestModule", "hello from Void::Log");
|
|
Void::Log::log(Void::Log::Level::Warning, "TestModule", "a warning");
|
|
|
|
Void::Log::set_sink({});
|
|
|
|
const auto text = out.str();
|
|
Void::Testing::expect(text.find("hello from Void::Log") !=
|
|
std::string::npos);
|
|
Void::Testing::expect(text.find("a warning") != std::string::npos);
|
|
Void::Testing::expect(text.find("[TestModule]") != std::string::npos);
|
|
}
|
|
|
|
// FileSystem operations now emit Void::Log events; verify they reach a sink.
|
|
Void::Testing::Test filesystem_ops_emit_log_events()
|
|
{
|
|
int debug_count = 0;
|
|
int warning_count = 0;
|
|
Void::Log::set_sink(
|
|
[&](Void::Log::Level l, std::string_view, std::string_view) {
|
|
if (l == Void::Log::Level::Debug) {
|
|
++debug_count;
|
|
}
|
|
if (l == Void::Log::Level::Warning) {
|
|
++warning_count;
|
|
}
|
|
});
|
|
|
|
Void::FileSystem::TempDir tmp;
|
|
auto p = tmp / "test.txt";
|
|
(void)Void::FileSystem::write_file(p, "data");
|
|
(void)Void::FileSystem::read_file(p);
|
|
(void)Void::FileSystem::read_file(tmp / "nonexistent.txt");
|
|
|
|
Void::Log::set_sink({});
|
|
|
|
// TempDir creation + read success + write (no debug from write_file) = at
|
|
// least 2
|
|
Void::Testing::expect(debug_count >= 2);
|
|
// Missing file read = 1 warning
|
|
Void::Testing::expect(warning_count >= 1);
|
|
}
|