16#include "gtest/gtest.h"
24namespace TestSupport {
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;
82 strstr(
msg,
"io_uring is unexpectedly not available because:") !=
nullptr) {
83 std::cerr <<
"Warning in " << location <<
" " <<
msg << std::endl;
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;
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));
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];
149 if (
diag.receivedCount >= 0) {
151 << std::setw(
indent) <<
"received: " <<
diag.receivedCount <<
" times ("
152 << (
diag.optional ?
"optional" :
"required") <<
", " << (
diag.matchFullString ?
"fullMatch" :
"subMatch")
156 << std::setw(
indent) <<
"origin: " <<
'"' <<
diag.location <<
"\""
158 << std::setw(
indent) <<
"message: " <<
diag.message <<
"\n";
static void indent(ostringstream &buf, int indent_level)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
ErrorHandlerFunc_t GetErrorHandler()
Returns the current error handler function.
void(* ErrorHandlerFunc_t)(int level, Bool_t abort, const char *location, const char *msg)
Int_t gErrorIgnoreLevel
errors with level below this value will be ignored. Default is kUnset.
constexpr Int_t kSysError
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.
const_iterator end() const
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)
Namespace for new ROOT classes and functions.
@ kInfo
Informational messages; used for instance for tracing.
@ kWarning
Warnings about likely unexpected behavior.
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.