19#ifndef ROOT_UNITTESTSUPPORT_H
20#define ROOT_UNITTESTSUPPORT_H
28#include "gtest/gtest.h"
31namespace TestSupport {
93 void requiredDiag(
int severity, std::string location, std::string message,
bool matchFullMessage =
true) {
95 throw std::invalid_argument(
"ExpectedDiagRAII::requiredDiag(): severity is none of kInfo, kWarning, kError, kSysError");
97 fExpectedDiags.push_back({severity, std::move(location), std::move(message), matchFullMessage,
false, 0});
106 void optionalDiag(
int severity, std::string location, std::string message,
bool matchFullMessage =
true) {
108 throw std::invalid_argument(
"ExpectedDiagRAII::optionalDiag(): severity is none of kInfo, kWarning, kError, kSysError");
110 fExpectedDiags.push_back({severity, std::move(location), std::move(message), matchFullMessage,
true, 0});
115 static void callback(
int severity,
bool abort,
const char * location,
const char * msg) {
119 throw std::logic_error(
"ExpectedDiagRAII::callback called without an active message handler.");
123 std::cerr <<
"ROOT::TestSupport::CheckDiagsRAII: Forced to abort because of diagnostic with severity "
124 << severity <<
" in '" << location <<
"' reading '" << msg <<
"'\n";
130 void checkDiag(
int severity,
const char *location,
const char *msg);
153#define ROOT_EXPECT_ERROR(expression, where, expected_diag ) \
155 using namespace ROOT::TestSupport; \
156 CheckDiagsRAII EE(kError, where, \
161#define ROOT_EXPECT_WARNING(expression, where, expected_diag) \
163 using namespace ROOT::TestSupport; \
164 CheckDiagsRAII EE(kWarning, where, \
169#define ROOT_EXPECT_INFO(expression, where, expected_diag) \
171 using namespace ROOT::TestSupport; \
172 CheckDiagsRAII EE(kInfo, where, \
177#define ROOT_EXPECT_NODIAG(expression) \
179 using namespace ROOT::TestSupport; \
180 CheckDiagsRAII EE{}; \
184#define ROOT_EXPECT_SYSERROR(expression, where, expected_diag) \
186 using namespace ROOT::TestSupport; \
187 CheckDiagsRAII EE(kSysError, where, \
ErrorHandlerFunc_t GetErrorHandler()
Returns the current error handler function.
void(* ErrorHandlerFunc_t)(int level, Bool_t abort, const char *location, const char *msg)
constexpr Int_t kSysError
ErrorHandlerFunc_t SetErrorHandler(ErrorHandlerFunc_t newhandler)
Set an errorhandler function. Returns the old handler.
Install a ROOT diagnostic handler to analyse diagnostics.
static void callback(int severity, bool abort, const char *location, const char *msg)
Message handler that hands over all diagnostics to the currently active instance.
CheckDiagsRAII(int severity, std::string inRoutine, std::string E)
Construct from ROOT's kWarning, kError, ... and strings specifying location and message.
ErrorHandlerFunc_t const fOldErrorHandler
Last active handler in case handlers are nested.
void optionalDiag(int severity, std::string location, std::string message, bool matchFullMessage=true)
Register a diagnostic that can, but need not necessarily be issued.
static CheckDiagsRAII * sActiveInstance
Last active error handler function.
std::vector< Diag_t > fUnexpectedDiags
std::vector< Diag_t > fExpectedDiags
void checkDiag(int severity, const char *location, const char *msg)
Check all received diags against list of expected ones.
CheckDiagsRAII *const fOldInstance
friend std::ostream & operator<<(std::ostream &stream, Diag_t const &diag)
void requiredDiag(int severity, std::string location, std::string message, bool matchFullMessage=true)
Register a new diagnostic to check for.
CheckDiagsRAII()
Register this instance as diagnostic handler.
Allows a user function to catch and filter/analyse ROOT and cling diagnostics, e.g.
FilterDiagsRAII(ErrorHandlerFunc_t fn)
ErrorHandlerFunc_t fPrevHandler
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...