#include #include #include #include #include // ── on_exit ─────────────────────────────────────────────────────────────────── Void::Testing::Test on_exit_runs_on_normal_exit() { bool ran = false; { auto guard = Void::Scope::on_exit([&] { ran = true; }); } Void::Testing::expect(ran); } Void::Testing::Test on_exit_runs_on_exception() { bool ran = false; try { auto guard = Void::Scope::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 = Void::Scope::on_exit([&] { ran = true; }); guard.release(); } Void::Testing::expect(!ran); } 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"; }); } Void::Testing::expect_eq(order, std::string{"CBA"}); } Void::Testing::Test on_exit_captures_by_ref() { int count = 0; { auto guard = Void::Scope::on_exit([&] { count += 10; }); count = 5; } Void::Testing::expect_eq(count, 15); } // ── on_success ──────────────────────────────────────────────────────────────── Void::Testing::Test on_success_runs_on_normal_exit() { bool ran = false; { auto guard = Void::Scope::on_success([&] { ran = true; }); } Void::Testing::expect(ran); } Void::Testing::Test on_success_does_not_run_on_exception() { bool ran = false; try { auto guard = Void::Scope::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 = Void::Scope::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 = Void::Scope::on_fail([&] { ran = true; }); } Void::Testing::expect(!ran); } Void::Testing::Test on_fail_runs_on_exception() { bool ran = false; try { auto guard = Void::Scope::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 = Void::Scope::on_fail([&] { ran = true; }); guard.release(); throw std::runtime_error{"test"}; } catch (...) {} Void::Testing::expect(!ran); }