21namespace TestSupport {
36 static void handler(
int level,
bool abort,
41 std::cerr <<
"Diagnostic in '" << location <<
"': " << msg << std::endl;
46 std::cerr <<
"ROOT::TestSupport::ForbidDiagnostics::handler(): Forced to abort because of diagnostic with severity "
47 << level <<
" in '" << location <<
"' reading '" << msg <<
"'\n";
52 if (level ==
kError && strcmp(location,
"TCling::LoadPCM") == 0 && strstr(msg,
"file does not exist") !=
nullptr) {
53 std::cerr <<
"Error in " << location <<
" " << msg << std::endl;
59 && strstr(msg,
"The RNTuple file format will change. Do not store real data with this version of RNTuple!") !=
nullptr) {
60 std::cerr <<
"Warning in " << location <<
" " << msg << std::endl;
64 && strstr(msg,
"Pre-release format version: RC ") !=
nullptr) {
65 std::cerr <<
"Warning in " << location <<
" " << msg << std::endl;
71 && strstr(msg,
"The DAOS backend is experimental and still under development") !=
nullptr) {
72 std::cerr <<
"Warning in " << location <<
" " << msg << std::endl;
76 FAIL() <<
"Received unexpected diagnostic of severity "
78 <<
" at '" << location <<
"' reading '" << msg <<
"'.\n"
79 <<
"Suppress those using ROOT/TestSupport.hxx";
93 if (!
fUnexpectedDiags.empty()) ADD_FAILURE() <<
"ROOT::TestSupport::CheckDiagsRAII: Unexpected diagnostic messages received.";
96 if (missingDiag) ADD_FAILURE() <<
"ROOT::TestSupport::CheckDiagsRAII: Diagnostic message missing.";
99 std::cout <<
"-------------------------\nPre-registered messages:\n";
101 std::cout <<
"Unexpected messages received:\n";
103 std::cout <<
"-------------------------" << std::endl;
111 const std::string message = msg;
113 return expectedDiag.severity == severity
114 && strstr(location, expectedDiag.location.c_str()) != nullptr
115 && (expectedDiag.matchFullString ? expectedDiag.message == message : (message.find(expectedDiag.message) != std::string::npos));
119 expectedMatch->receivedCount += 1;
120 }
else if (severity <=
kInfo) {
128 std::map<int, std::string> dict = {
135 for (
auto const & diag : diags) {
136 std::cout << std::setw(10) << dict[diag.severity] <<
"\t";
137 if (diag.receivedCount >= 0) {
138 std::cout << diag.receivedCount <<
"x received\t"
139 <<
"(" << (diag.optional ?
"optional" :
"required") <<
", " << (diag.matchFullString ?
"fullMatch" :
"subMatch") <<
")\t";
141 std::cout <<
"'" << diag.location <<
"' msg='" << diag.message <<
"'\n";
ErrorHandlerFunc_t GetErrorHandler()
Returns the current error handler function.
void(* ErrorHandlerFunc_t)(int level, Bool_t abort, const char *location, const char *msg)
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.
void printDiags(std::vector< Diag_t > const &diags) const
Print the diags in diags to the terminal.
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
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
Error handler for gtests that generates failures for every received diagnostic > kInfo when this file...
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.