16#include "gtest/gtest.h"
39 static void handler(
int level,
bool abort,
44 std::cerr <<
"ROOT::TestSupport::ForbidDiagnostics::handler(): Diagnostic in '" << location <<
"':\n"
50 std::cerr <<
"ROOT::TestSupport::ForbidDiagnostics::handler(): Forced to abort because of diagnostic with severity "
51 << level <<
" in '" << location <<
"' reading '" << msg <<
"'\n";
56 if (level ==
kError && strcmp(location,
"TCling::LoadPCM") == 0 && strstr(msg,
"file does not exist") !=
nullptr) {
57 std::cerr <<
"Error in " << location <<
" " << msg << std::endl;
62 if (level ==
kWarning && strstr(msg,
"Merging RNTuples is experimental") !=
nullptr) {
63 std::cerr <<
"Warning in " << location <<
" " << msg << std::endl;
69 && strstr(msg,
"The DAOS backend is experimental and still under development") !=
nullptr) {
70 std::cerr <<
"Warning in " << location <<
" " << msg << std::endl;
76 && strcmp(msg,
"Fast recovery from undefined function values only implemented for little-endian machines. If necessary, request an extension of functionality on https://root.cern") == 0) {
77 std::cerr <<
"Warning in " << location <<
" " << msg << std::endl;
81 if (level ==
kWarning && strcmp(location,
"RIoUring") == 0 &&
82 strstr(msg,
"io_uring is unexpectedly not available because:") !=
nullptr) {
83 std::cerr <<
"Warning in " << location <<
" " << msg << std::endl;
87 if (level ==
kWarning && strcmp(location,
"RRawFileUnix") == 0 &&
88 strcmp(msg,
"io_uring setup failed, falling back to blocking I/O in ReadV") == 0) {
89 std::cerr <<
"Warning in " << location <<
" " << msg << std::endl;
93 FAIL() <<
"Received unexpected diagnostic of severity "
95 <<
" at '" << location <<
"' reading '" << msg <<
"'.\n"
96 <<
"Suppress those using ROOT/TestSupport.hxx";
111 if (!diag.optional && diag.receivedCount < 1) {
112 ADD_FAILURE() <<
"ROOT::TestSupport::CheckDiagsRAII: Expected diagnostic message missing:\n" << diag;
117 ADD_FAILURE() <<
"ROOT::TestSupport::CheckDiagsRAII: Unexpected diagnostic message:\n" << diag;
125 const std::string message = msg;
126 const auto expectedMatch =
128 return expectedDiag.severity == severity
129 && strstr(location, expectedDiag.location.c_str()) != nullptr
130 && (expectedDiag.matchFullString ? expectedDiag.message == message : (message.find(expectedDiag.message) != std::string::npos));
134 expectedMatch->receivedCount += 1;
135 }
else if (severity <=
kInfo) {
144 std::map<int, std::string> dict = {
147 constexpr auto indent = 15;
148 stream << std::right << std::setw(
indent) <<
"severity: " << dict[diag.
severity];
156 << std::setw(
indent) <<
"origin: " <<
'"' << diag.
location <<
"\""
static void indent(ostringstream &buf, int indent_level)
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
externInt_t gErrorIgnoreLevel
errors with level below this value will be ignored. Default is kUnset.
ErrorHandlerFunc_t SetErrorHandler(ErrorHandlerFunc_t newhandler)
Set an errorhandler function. Returns the old handler.
The file contains facilities allowing easier writing of in-tree unit tests.
ErrorHandlerFunc_t const fOldErrorHandler
Last active handler in case handlers are nested.
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
static struct ROOT::TestSupport::ForbidDiagnostics noDiagCheckerInstance
std::ostream & operator<<(std::ostream &stream, CheckDiagsRAII::Diag_t const &diag)
ErrorHandlerFunc_t const sOldErrorHandler
static void handler(int level, bool abort, const char *location, const char *msg)
Diagnostic handler that's installed for all google tests.