xo-umbrella2/xo-ppsink/utest/verify_policy.test.cpp
Roland Conybeare fb013ea267
All checks were successful
cmake-docker / cmake-build (clang, clang++) (push) Successful in 30m28s
cmake-docker / cmake-build (gcc, g++) (push) Successful in 29m12s
CI / smoke-test (push) Successful in 53m49s
xo-ppsink +: use appcx for pretty printer config [REFACTOR]
2026-09-02 00:10:49 -04:00

54 lines
1.8 KiB
C++

/** @file verify_policy.test.cpp
*
* exercise xo::verify_policy (moved from xo-arena into xo-ppsink) -- its
* report_error() dispatch over a ppsink scope + xo::pp::tostr message.
**/
#include <xo/ppsink/FlatSink.hpp>
#include <xo/ppsink/scope_macros.hpp>
#include <xo/ppsink/tag.hpp>
#include <xo/ppsink/verify_policy.hpp>
#include <catch2/catch.hpp>
#include <sstream>
#include <stdexcept>
namespace ut {
using xo::verify_policy;
using xo::pp::scope;
using xo::pp::xtag;
using xo::pp::FlatSink;
using xo::pp::ThreadLogState;
using std::stringstream;
TEST_CASE("verify_policy-flags", "[verify_policy]") {
REQUIRE(verify_policy::log_only().log_flag());
REQUIRE_FALSE(verify_policy::log_only().throw_flag());
REQUIRE(verify_policy::throw_only().throw_flag());
REQUIRE_FALSE(verify_policy::throw_only().log_flag());
REQUIRE(verify_policy::chatty().log_flag());
REQUIRE(verify_policy::chatty().throw_flag());
}
TEST_CASE("verify_policy-report-error", "[verify_policy]") {
stringstream ss;
{
auto sink = std::make_unique<FlatSink>(ss.rdbuf());
ThreadLogState::log_set_sink(std::move(sink));
}
scope log(XO_ENTER0_(always));
/* throw_only: report_error builds the message via tostr and throws it */
verify_policy thrower = verify_policy::throw_only();
REQUIRE_THROWS_AS(thrower.report_error(log, "boom", xtag("x", 42)),
std::runtime_error);
/* silent (flags_ = 0): no throw, no log */
verify_policy silent = verify_policy{.flags_ = 0};
REQUIRE_FALSE(silent.report_error(log, "quiet"));
ThreadLogState::log_set_sink(nullptr);
}
} /*namespace ut*/
/* end verify_policy.test.cpp */