19#ifndef ROOT_UNITTESTSUPPORT_H
20#define ROOT_UNITTESTSUPPORT_H
92 void requiredDiag(
int severity, std::string location, std::string message,
bool matchFullMessage =
true)
95 throw std::invalid_argument(
96 "ExpectedDiagRAII::requiredDiag(): severity is none of kInfo, kWarning, kError, kSysError");
98 fExpectedDiags.push_back({severity, std::move(location), std::move(message), matchFullMessage,
false, 0});
107 void optionalDiag(
int severity, std::string location, std::string message,
bool matchFullMessage =
true)
110 throw std::invalid_argument(
111 "ExpectedDiagRAII::optionalDiag(): severity is none of kInfo, kWarning, kError, kSysError");
113 fExpectedDiags.push_back({severity, std::move(location), std::move(message), matchFullMessage,
true, 0});
118 static void callback(
int severity,
bool abort,
const char *location,
const char *msg)
123 throw std::logic_error(
"ExpectedDiagRAII::callback called without an active message handler.");
127 std::cerr <<
"ROOT::TestSupport::CheckDiagsRAII: Forced to abort because of diagnostic with severity "
128 << severity <<
" in '" << location <<
"' reading '" << msg <<
"'\n";
134 void checkDiag(
int severity,
const char *location,
const char *msg);
173 std::remove(
fPath.c_str());
185#define ROOT_EXPECT_DIAG(diag_class, expression, where, expected_diag, match_full) \
187 using namespace ROOT::TestSupport; \
188 CheckDiagsRAII EE(diag_class, where, expected_diag, match_full); \
192#define ROOT_EXPECT_NODIAG(expression) \
194 using namespace ROOT::TestSupport; \
195 CheckDiagsRAII EE{}; \
199#define ROOT_EXPECT_ERROR(expression, where, expected_diag) \
200 ROOT_EXPECT_DIAG(kError, expression, where, expected_diag, true)
202#define ROOT_EXPECT_ERROR_PARTIAL(expression, where, expected_diag) \
203 ROOT_EXPECT_DIAG(kError, expression, where, expected_diag, false)
205#define ROOT_EXPECT_WARNING(expression, where, expected_diag) \
206 ROOT_EXPECT_DIAG(kWarning, expression, where, expected_diag, true)
208#define ROOT_EXPECT_WARNING_PARTIAL(expression, where, expected_diag) \
209 ROOT_EXPECT_DIAG(kWarning, expression, where, expected_diag, false)
211#define ROOT_EXPECT_INFO(expression, where, expected_diag) \
212 ROOT_EXPECT_DIAG(kInfo, expression, where, expected_diag, true)
214#define ROOT_EXPECT_INFO_PARTIAL(expression, where, expected_diag) \
215 ROOT_EXPECT_DIAG(kInfo, expression, where, expected_diag, false)
217#define ROOT_EXPECT_SYSERROR(expression, where, expected_diag) \
218 ROOT_EXPECT_DIAG(kSysError, expression, where, expected_diag, true)
220#define ROOT_EXPECT_SYSERROR_PARTIAL(expression, where, expected_diag) \
221 ROOT_EXPECT_DIAG(kSysError, expression, where, expected_diag, false)
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.
CheckDiagsRAII(int severity, std::string inRoutine, std::string E, bool matchFullMessage=true)
Construct from ROOT's kWarning, kError, ... and strings specifying location and message.
friend std::ostream & operator<<(std::ostream &stream, Diag_t const &diag)
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.
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
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.
FileRaii(const FileRaii &)=delete
std::string GetPath() const
FileRaii(const std::string &path)
FileRaii & operator=(const FileRaii &)=delete
FileRaii(FileRaii &&)=default
FileRaii & operator=(FileRaii &&)=default
FilterDiagsRAII(ErrorHandlerFunc_t fn)
ErrorHandlerFunc_t fPrevHandler