Files
Library/tests/standalone/Functional/ResultContext.cpp
faumarayandClaude Fable 5 28b94883fd Restructure into umbrella modules (~55 -> 16 targets)
Headers move, CMake targets merge, C++ namespaces stay unchanged:
- Core: Scope, Lazy, Counted, Flags, Hash, Bits, Uuid, TypeList, TypeMap, Variant
- Functional: Pipeline, Either, Result, Retry
- Containers: Ring, Pool, PriorityQueue, LRU, Trie, Graph, DisjointSet, Bitset, Interval
- Math: +Matrix, Numeric, Random, Histogram
- Text: Str, Format, Tokenizer, Diff, Encoding, Semver
- Data: Json, Csv, Ini
- Async: Coro, Concurrency, EventBus, Observable
- Time: +Bench
- Log: Log facade + Logging framework (facade now header-only, breaking
  the Stacktrace<->Log link cycle the merge would have created)
- System: FileSystem + Process
- Configuration: +Argparse
- Unchanged: Stacktrace, Plugin, StateMachine, Testing, TestingMock, Detail

Module system fixes:
- OPTIONAL_DEPS resolution deferred to void_finalize_modules() so it no
  longer depends on the alphabetical discovery order of src/ subdirs
  (Testing -> Text would have been silently dropped).
- Every header-only module now has a tracked module.cmake; previously the
  empty src/<Name> marker dirs were untracked, so a fresh clone would have
  silently skipped those modules.
- VOID_HAS_LOGGING/CONCURRENCY/STR consumers renamed to LOG/ASYNC/TEXT.

Tests move to tests/standalone/<Umbrella>/<Feature>.cpp (Result suite files
prefixed: ResultBasic etc.). Test count verified identical (831) before and
after. README/CLAUDE.md module tables updated.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-12 18:50:02 +03:00

57 lines
1.6 KiB
C++

#include <Void/Functional/Error.hpp>
#include <Void/Functional/Result.hpp>
#include <Void/Testing/Assert.hpp>
#include <Void/Testing/Test.hpp>
#include <string>
namespace
{
Void::Result::Result<int> read_file()
{
return Void::Result::fail("disk read error");
}
Void::Result::Result<int> parse_config()
{
return Void::Result::with_context(read_file(), "parsing config.toml");
}
Void::Result::Result<int> load()
{
return Void::Result::with_context(parse_config(), "starting up");
}
} // namespace
Void::Testing::Test context_chain_preserves_root_message()
{
auto r = load();
Void::Testing::expect(!r.has_value());
const auto& e = r.error();
Void::Testing::expect_eq(e.message(), std::string{"starting up"});
Void::Testing::expect(e.cause() != nullptr);
Void::Testing::expect_eq(e.cause()->message(),
std::string{"parsing config.toml"});
Void::Testing::expect_eq(e.cause()->cause()->message(),
std::string{"disk read error"});
}
Void::Testing::Test format_renders_full_chain()
{
auto r = load();
const auto rendered = r.error().format();
Void::Testing::expect(rendered.find("starting up") != std::string::npos);
Void::Testing::expect(rendered.find("parsing config.toml") !=
std::string::npos);
Void::Testing::expect(rendered.find("disk read error") !=
std::string::npos);
Void::Testing::expect(rendered.find("caused by:") != std::string::npos);
}
Void::Testing::Test with_context_no_op_on_success()
{
auto r = Void::Result::with_context(Void::Result::ok(42), "unused context");
Void::Testing::expect(r.has_value());
Void::Testing::expect_eq(*r, 42);
}