Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion core/metacling/test/TClingTests.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -467,4 +467,46 @@ using func0_ret_t = typename ROOT::TypeTraits::CallableTraits<decltype(func0)>::
auto res = gInterpreter->Declare(expression.c_str());
EXPECT_TRUE(res);
}
#endif
#endif

// https://github.com/root-project/root/issues/22235
TEST_F(TClingTests, ErrorHandling)
{
// Tests of error handling of various TInterpreter APIs.
const char *wrongCode{"rndm_stuff"};

auto processLineWithError = [](const char *code) {
// ProcessLine
ROOT::TestSupport::CheckDiagsRAII diags;
diags.requiredDiag(kError, "cling", "use of undeclared identifier 'rndm_stuff'",
/*matchFullMessage=*/false);
diags.requiredDiag(kError, "HandleInterpreterException", "Error evaluating expression (rndm_stuff)",
/*matchFullMessage=*/false);
TInterpreter::EErrorCode error = TInterpreter::kNoError;
gInterpreter->ProcessLine(code, &error);
EXPECT_NE(error, TInterpreter::kNoError);
};
EXPECT_NO_THROW(processLineWithError(wrongCode));

auto calcWithError = [](const char *code) {
// Calc
ROOT::TestSupport::CheckDiagsRAII diags;
diags.requiredDiag(kError, "cling", "use of undeclared identifier 'rndm_stuff'",
/*matchFullMessage=*/false);
diags.requiredDiag(kError, "Calc", "Error evaluating expression (rndm_stuff)",
/*matchFullMessage=*/false);
TInterpreter::EErrorCode error = TInterpreter::kNoError;
gInterpreter->Calc(code, &error);
EXPECT_NE(error, TInterpreter::kNoError);
};
EXPECT_NO_THROW(calcWithError(wrongCode));

// Evaluate
try {
std::unique_ptr<TInterpreterValue> v = gInterpreter->MakeInterpreterValue();
gInterpreter->Evaluate(wrongCode, *v);
FAIL() << "expected exception thrown by Evaluate";
} catch (const std::runtime_error &e) {
EXPECT_THAT(e.what(), testing::HasSubstr("Error evaluating expression (rndm_stuff)"));
}
}
Loading