Skip to content

Commit

Permalink
[test] Moved FilterDiagsRAII class to ROOTUnitTestSupport.h
Browse files Browse the repository at this point in the history
  • Loading branch information
jalopezg-git committed Nov 7, 2021
1 parent ac2e418 commit 5dfb0c7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
15 changes: 1 addition & 14 deletions core/metacling/test/TClingCallFuncTests.cxx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "TError.h"
#include "ROOTUnitTestSupport.h"
#include "TInterpreter.h"

#include "gtest/gtest.h"
Expand All @@ -15,19 +15,6 @@
// system, feel free to delete them as these tests here don't represent things the user
// should do in his code.

class FilterDiagsRAII {
ErrorHandlerFunc_t fPrevHandler;
public:
FilterDiagsRAII(ErrorHandlerFunc_t fn) : fPrevHandler(::GetErrorHandler()) {
::SetErrorHandler(fn);
gInterpreter->ReportDiagnosticsToErrorHandler();
}
~FilterDiagsRAII() {
gInterpreter->ReportDiagnosticsToErrorHandler(/*enable=*/false);
::SetErrorHandler(fPrevHandler);
}
};

TEST(TClingCallFunc, FunctionWrapper)
{
gInterpreter->Declare(R"cpp(
Expand Down
25 changes: 25 additions & 0 deletions test/unit_testing_support/ROOTUnitTestSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
#ifndef ROOT_UNITTESTSUPPORT_H
#define ROOT_UNITTESTSUPPORT_H

#include "TError.h"
#include "TInterpreter.h"

#include "gtest/gtest.h"
#include "gmock/gmock.h"

Expand All @@ -27,6 +30,28 @@ using testing::StrEq;
using testing::internal::GetCapturedStderr;
using testing::internal::CaptureStderr;
using testing::internal::RE;

/// \brief Allows a user function to filter ROOT/cling diagnostics, e.g.
/// ```c++
/// FilterDiagsRAII RAII([] (int level, Bool_t abort,
/// const char *location, const char *msg) {
/// if (...)
/// FAIL() << "...";
/// });
/// ```
class FilterDiagsRAII {
ErrorHandlerFunc_t fPrevHandler;
public:
FilterDiagsRAII(ErrorHandlerFunc_t fn) : fPrevHandler(::GetErrorHandler()) {
::SetErrorHandler(fn);
gInterpreter->ReportDiagnosticsToErrorHandler();
}
~FilterDiagsRAII() {
gInterpreter->ReportDiagnosticsToErrorHandler(/*enable=*/false);
::SetErrorHandler(fPrevHandler);
}
};

class ExpectedDiagRAII {
public:
enum ExpectedDiagKind {
Expand Down

0 comments on commit 5dfb0c7

Please sign in to comment.