Specs
Beautiful C++ Test Framework
Loading...
Searching...
No Matches
LibAssertExceptionHandler.h
Go to the documentation of this file.
1#pragma once
2
3#include <assert.hpp>
4
5#ifdef NDEGUG
6#include <string>
7#include <vector>
8#include <mutex>
9#endif
10
12 inline bool ShowStackTrace = false;
13
14 #ifdef NDEBUG
15 inline std::vector<std::string> AllAssertionFailureMessages;
16 inline std::mutex AllAssertionFailureMessagesMutex;
17 #endif
18}
19
21 libassert::assert_type type, ASSERTION fatal, const libassert::assertion_printer& printer
22) {
23 std::string message = printer(libassert::utility::terminal_width(120));
25 std::string::size_type stack_trace_start = message.find("\nStack trace:");
26 if (stack_trace_start != std::string::npos) message.erase(stack_trace_start);
27 }
28 #ifdef NDEBUG
29 // In release mode, the c_str() is lost unless we hold onto the string somewhere.
30 // Here we just add it to a never-ending vector. Which is fine, whatever.
31 std::lock_guard<std::mutex> lock(SpecsCpp::LibAssert::AllAssertionFailureMessagesMutex);
32 SpecsCpp::LibAssert::AllAssertionFailureMessages.emplace_back(message);
33 throw SpecsCpp::LibAssert::AllAssertionFailureMessages.back().c_str();
34 #else
35 throw message.c_str();
36 #endif
37}
void libassert_specs_handler(libassert::assert_type type, ASSERTION fatal, const libassert::assertion_printer &printer)