Finish module consolidation: fold Memo into Pipeline, dedupe Channel/Stopwatch
Completes the in-progress merges (Optional->Either/Opt, Curry+Memo->Pipeline,
ScopeGuard->Scope, String->Str):
- Pipeline/Memo.hpp now carries the full Memo API (memoize with recursion
support, TupleHash, SimpleCache) alongside memoize_fn; old Memo module
and its test dir removed.
- Duplicate Channel module removed; Concurrency::Channel gains empty() and
the unique test cases (drain-after-close, multi-producer, string payloads).
- StopWatch module merged into Time::Stopwatch: one class with explicit
start/stop/laps plus a started() factory for the auto-start RAII style;
ScopedTimer moved along.
- Testing optional dep retargeted String->Str (pad_right lives in Str now).
- Stale empty dirs removed: src/{ScopeGuard,String,Core}, include/Void/{Core,
Filesystem,Memo,Channel,StopWatch}.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
58ff7b38a0
commit
da2e93c405
29 files changed
+752
-1593
No files matched your search
@@ -5,13 +5,15 @@
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
using namespace Void::Scope;
|
||||
|
||||
// ── on_exit ───────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test on_exit_runs_on_normal_exit()
|
||||
{
|
||||
bool ran = false;
|
||||
{
|
||||
auto guard = Void::Scope::on_exit([&] { ran = true; });
|
||||
auto guard = on_exit([&] { ran = true; });
|
||||
}
|
||||
Void::Testing::expect(ran);
|
||||
}
|
||||
@@ -20,7 +22,7 @@ Void::Testing::Test on_exit_runs_on_exception()
|
||||
{
|
||||
bool ran = false;
|
||||
try {
|
||||
auto guard = Void::Scope::on_exit([&] { ran = true; });
|
||||
auto guard = on_exit([&] { ran = true; });
|
||||
throw std::runtime_error{"test"};
|
||||
} catch (...) {}
|
||||
Void::Testing::expect(ran);
|
||||
@@ -30,31 +32,82 @@ Void::Testing::Test on_exit_release_prevents_run()
|
||||
{
|
||||
bool ran = false;
|
||||
{
|
||||
auto guard = Void::Scope::on_exit([&] { ran = true; });
|
||||
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 = Void::Scope::on_exit([&] { order += "A"; });
|
||||
auto b = Void::Scope::on_exit([&] { order += "B"; });
|
||||
auto c = Void::Scope::on_exit([&] { order += "C"; });
|
||||
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_captures_by_ref()
|
||||
Void::Testing::Test on_exit_multiple_guards_lifo()
|
||||
{
|
||||
int count = 0;
|
||||
int order = 0, a = 0, b = 0;
|
||||
{
|
||||
auto guard = Void::Scope::on_exit([&] { count += 10; });
|
||||
count = 5;
|
||||
auto ga = on_exit([&] { a = ++order; });
|
||||
auto gb = on_exit([&] { b = ++order; });
|
||||
}
|
||||
Void::Testing::expect_eq(count, 15);
|
||||
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 ────────────────────────────────────────────────────────────────
|
||||
@@ -63,7 +116,7 @@ Void::Testing::Test on_success_runs_on_normal_exit()
|
||||
{
|
||||
bool ran = false;
|
||||
{
|
||||
auto guard = Void::Scope::on_success([&] { ran = true; });
|
||||
auto guard = on_success([&] { ran = true; });
|
||||
}
|
||||
Void::Testing::expect(ran);
|
||||
}
|
||||
@@ -72,7 +125,7 @@ Void::Testing::Test on_success_does_not_run_on_exception()
|
||||
{
|
||||
bool ran = false;
|
||||
try {
|
||||
auto guard = Void::Scope::on_success([&] { ran = true; });
|
||||
auto guard = on_success([&] { ran = true; });
|
||||
throw std::runtime_error{"test"};
|
||||
} catch (...) {}
|
||||
Void::Testing::expect(!ran);
|
||||
@@ -82,7 +135,7 @@ Void::Testing::Test on_success_release_prevents_run()
|
||||
{
|
||||
bool ran = false;
|
||||
{
|
||||
auto guard = Void::Scope::on_success([&] { ran = true; });
|
||||
auto guard = on_success([&] { ran = true; });
|
||||
guard.release();
|
||||
}
|
||||
Void::Testing::expect(!ran);
|
||||
@@ -94,7 +147,7 @@ Void::Testing::Test on_fail_does_not_run_on_normal_exit()
|
||||
{
|
||||
bool ran = false;
|
||||
{
|
||||
auto guard = Void::Scope::on_fail([&] { ran = true; });
|
||||
auto guard = on_fail([&] { ran = true; });
|
||||
}
|
||||
Void::Testing::expect(!ran);
|
||||
}
|
||||
@@ -103,7 +156,7 @@ Void::Testing::Test on_fail_runs_on_exception()
|
||||
{
|
||||
bool ran = false;
|
||||
try {
|
||||
auto guard = Void::Scope::on_fail([&] { ran = true; });
|
||||
auto guard = on_fail([&] { ran = true; });
|
||||
throw std::runtime_error{"test"};
|
||||
} catch (...) {}
|
||||
Void::Testing::expect(ran);
|
||||
@@ -113,9 +166,39 @@ Void::Testing::Test on_fail_release_prevents_run()
|
||||
{
|
||||
bool ran = false;
|
||||
try {
|
||||
auto guard = Void::Scope::on_fail([&] { ran = true; });
|
||||
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);
|
||||
}
|
||||
Reference in new issue
Block a user