Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions include/log/log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,14 @@ ALWAYS_INLINE static auto log(TArgs &&...args) -> void {
CIB_LOG(logging::default_flavor_t, logging::level::ERROR, __VA_ARGS__)

#define CIB_FATAL(MSG, ...) \
[] { \
constexpr auto str = sc::format(MSG##_sc __VA_OPT__(, ) __VA_ARGS__); \
[](auto &&str) { \
logging::log<logging::default_flavor_t, logging::level::FATAL, \
cib_log_env_t>(__FILE__, __LINE__, str); \
str.apply([]<typename S, typename... Args>(S s, Args... args) { \
FWD(str).apply([]<typename S, typename... Args>(S s, Args... args) { \
constexpr auto cts = stdx::ct_string_from_type(s); \
stdx::panic<cts>(args...); \
}); \
}()
}(sc::format(MSG##_sc __VA_OPT__(, ) __VA_ARGS__))

#define CIB_ASSERT(expr) \
((expr) ? void(0) : CIB_FATAL("Assertion failure: " #expr))
Expand Down
9 changes: 8 additions & 1 deletion test/log/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ bool panicked{};
struct injected_handler {
template <stdx::ct_string Why, typename... Ts>
static auto panic(Ts &&...) noexcept -> void {
static_assert(std::string_view{Why} == "Hello");
static_assert(std::string_view{Why}.starts_with("Hello"));
panicked = true;
}
};
Expand Down Expand Up @@ -55,3 +55,10 @@ TEST_CASE("CIB_FATAL pre-formats arguments passed to panic", "[log]") {
CIB_FATAL("{}", "Hello"_sc);
CHECK(panicked);
}

TEST_CASE("CIB_FATAL can format stack arguments", "[log]") {
panicked = false;
auto x = 42;
CIB_FATAL("Hello {}", x);
CHECK(panicked);
}
Loading