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>
205 lines
5.0 KiB
C++
205 lines
5.0 KiB
C++
#include <Void/Core/Scope.hpp>
|
|
#include <Void/Testing/Assert.hpp>
|
|
#include <Void/Testing/Test.hpp>
|
|
|
|
#include <stdexcept>
|
|
#include <string>
|
|
|
|
using namespace Void::Scope;
|
|
|
|
// ── on_exit ───────────────────────────────────────────────────────────────────
|
|
|
|
Void::Testing::Test on_exit_runs_on_normal_exit()
|
|
{
|
|
bool ran = false;
|
|
{
|
|
auto guard = on_exit([&] { ran = true; });
|
|
}
|
|
Void::Testing::expect(ran);
|
|
}
|
|
|
|
Void::Testing::Test on_exit_runs_on_exception()
|
|
{
|
|
bool ran = false;
|
|
try {
|
|
auto guard = on_exit([&] { ran = true; });
|
|
throw std::runtime_error{"test"};
|
|
} catch (...) {}
|
|
Void::Testing::expect(ran);
|
|
}
|
|
|
|
Void::Testing::Test on_exit_release_prevents_run()
|
|
{
|
|
bool ran = false;
|
|
{
|
|
auto guard = on_exit([&] { ran = true; });
|
|
guard.release();
|
|
}
|
|
Void::Testing::expect(!ran);
|
|
}
|
|
|
|
Void::Testing::Test on_exit_dismiss_prevents_run()
|
|
{
|
|
bool ran = false;
|
|
{
|
|
auto guard = on_exit([&] { ran = true; });
|
|
guard.dismiss();
|
|
}
|
|
Void::Testing::expect(!ran);
|
|
}
|
|
|
|
Void::Testing::Test on_exit_active_reflects_state()
|
|
{
|
|
auto guard = on_exit([] {});
|
|
Void::Testing::expect(guard.active());
|
|
guard.dismiss();
|
|
Void::Testing::expect(!guard.active());
|
|
}
|
|
|
|
Void::Testing::Test on_exit_move_transfers_ownership()
|
|
{
|
|
int called = 0;
|
|
{
|
|
auto g1 = on_exit([&] { ++called; });
|
|
auto g2 = std::move(g1);
|
|
Void::Testing::expect(!g1.active());
|
|
Void::Testing::expect(g2.active());
|
|
}
|
|
Void::Testing::expect_eq(called, 1);
|
|
}
|
|
|
|
Void::Testing::Test on_exit_lifo_order()
|
|
{
|
|
std::string order;
|
|
{
|
|
auto a = on_exit([&] { order += "A"; });
|
|
auto b = on_exit([&] { order += "B"; });
|
|
auto c = on_exit([&] { order += "C"; });
|
|
}
|
|
Void::Testing::expect_eq(order, std::string{"CBA"});
|
|
}
|
|
|
|
Void::Testing::Test on_exit_multiple_guards_lifo()
|
|
{
|
|
int order = 0, a = 0, b = 0;
|
|
{
|
|
auto ga = on_exit([&] { a = ++order; });
|
|
auto gb = on_exit([&] { b = ++order; });
|
|
}
|
|
Void::Testing::expect(b < a);
|
|
}
|
|
|
|
Void::Testing::Test on_exit_resource_cleanup()
|
|
{
|
|
bool released = false;
|
|
{
|
|
int handle = 42;
|
|
auto cleanup = on_exit([&] { if (handle) released = true; });
|
|
(void)handle;
|
|
}
|
|
Void::Testing::expect(released);
|
|
}
|
|
|
|
Void::Testing::Test on_exit_conditional_commit()
|
|
{
|
|
int value = 10;
|
|
{
|
|
auto rollback = on_exit([&] { value = 0; });
|
|
rollback.dismiss();
|
|
}
|
|
Void::Testing::expect_eq(value, 10);
|
|
}
|
|
|
|
// ── on_success ────────────────────────────────────────────────────────────────
|
|
|
|
Void::Testing::Test on_success_runs_on_normal_exit()
|
|
{
|
|
bool ran = false;
|
|
{
|
|
auto guard = on_success([&] { ran = true; });
|
|
}
|
|
Void::Testing::expect(ran);
|
|
}
|
|
|
|
Void::Testing::Test on_success_does_not_run_on_exception()
|
|
{
|
|
bool ran = false;
|
|
try {
|
|
auto guard = on_success([&] { ran = true; });
|
|
throw std::runtime_error{"test"};
|
|
} catch (...) {}
|
|
Void::Testing::expect(!ran);
|
|
}
|
|
|
|
Void::Testing::Test on_success_release_prevents_run()
|
|
{
|
|
bool ran = false;
|
|
{
|
|
auto guard = on_success([&] { ran = true; });
|
|
guard.release();
|
|
}
|
|
Void::Testing::expect(!ran);
|
|
}
|
|
|
|
// ── on_fail ───────────────────────────────────────────────────────────────────
|
|
|
|
Void::Testing::Test on_fail_does_not_run_on_normal_exit()
|
|
{
|
|
bool ran = false;
|
|
{
|
|
auto guard = on_fail([&] { ran = true; });
|
|
}
|
|
Void::Testing::expect(!ran);
|
|
}
|
|
|
|
Void::Testing::Test on_fail_runs_on_exception()
|
|
{
|
|
bool ran = false;
|
|
try {
|
|
auto guard = on_fail([&] { ran = true; });
|
|
throw std::runtime_error{"test"};
|
|
} catch (...) {}
|
|
Void::Testing::expect(ran);
|
|
}
|
|
|
|
Void::Testing::Test on_fail_release_prevents_run()
|
|
{
|
|
bool ran = false;
|
|
try {
|
|
auto guard = on_fail([&] { ran = true; });
|
|
guard.release();
|
|
throw std::runtime_error{"test"};
|
|
} catch (...) {}
|
|
Void::Testing::expect(!ran);
|
|
}
|
|
|
|
// ── scope_exit / scope_success / scope_failure aliases ───────────────────────
|
|
|
|
Void::Testing::Test scope_exit_alias_fires()
|
|
{
|
|
int called = 0;
|
|
{
|
|
auto g = scope_exit([&] { ++called; });
|
|
}
|
|
Void::Testing::expect_eq(called, 1);
|
|
}
|
|
|
|
Void::Testing::Test scope_success_alias_fires_on_normal()
|
|
{
|
|
int called = 0;
|
|
{
|
|
auto g = scope_success([&] { ++called; });
|
|
}
|
|
Void::Testing::expect_eq(called, 1);
|
|
}
|
|
|
|
Void::Testing::Test scope_failure_alias_fires_on_exception()
|
|
{
|
|
int called = 0;
|
|
try {
|
|
auto g = scope_failure([&] { ++called; });
|
|
throw std::runtime_error{"x"};
|
|
} catch (...) {}
|
|
Void::Testing::expect_eq(called, 1);
|
|
}
|