From adb3f447b33e42bdb6e4a5a1ac79eebd862dafb4 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Sat, 10 Aug 2019 20:33:59 -0400 Subject: DRTVWR-493: Introduce test catch_what(), catch_llerrs() functions. Use them in place of awkward try/catch test boilerplate. --- indra/llcommon/tests/wrapllerrs.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'indra/llcommon/tests/wrapllerrs.h') diff --git a/indra/llcommon/tests/wrapllerrs.h b/indra/llcommon/tests/wrapllerrs.h index 08fbf19b1c..3fb79f6b5d 100644 --- a/indra/llcommon/tests/wrapllerrs.h +++ b/indra/llcommon/tests/wrapllerrs.h @@ -37,6 +37,7 @@ #include "llerrorcontrol.h" #include "llexception.h" #include "stringize.h" +#include "../test/catch_and_store_what_in.h" #include #include #include @@ -86,6 +87,13 @@ struct WrapLLErrs LLError::FatalFunction mPriorFatal; }; +/// Convenience wrapper for catch_what() +template +std::string catch_llerrs(FUNC func) +{ + return catch_what(func); +} + /** * Capture log messages. This is adapted (simplified) from the one in * llerror_test.cpp. -- cgit v1.2.3 From f0fa4f94a5400fe5d21cf5bf7570129916bf9787 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Mon, 12 Aug 2019 08:26:51 -0400 Subject: DRTVWR-493: Make catch_llerrs() a member of WrapLLErrs. --- indra/llcommon/tests/wrapllerrs.h | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) (limited to 'indra/llcommon/tests/wrapllerrs.h') diff --git a/indra/llcommon/tests/wrapllerrs.h b/indra/llcommon/tests/wrapllerrs.h index 3fb79f6b5d..b07d5afbd8 100644 --- a/indra/llcommon/tests/wrapllerrs.h +++ b/indra/llcommon/tests/wrapllerrs.h @@ -82,18 +82,36 @@ struct WrapLLErrs LLTHROW(FatalException(message)); } + /// Convenience wrapper for catch_what() + // + // The implementation makes it clear that this function need not be a + // member; it could easily be a free function. It is a member because it + // makes no sense to attempt to catch FatalException unless there is a + // WrapLLErrs instance in scope. Without a live WrapLLErrs instance, any + // LL_ERRS() reached by code within 'func' would terminate the test + // program instead of throwing FatalException. + // + // We were tempted to introduce a free function, likewise accepting + // arbitrary 'func', that would instantiate WrapLLErrs and then call + // catch_llerrs() on that instance. We decided against it, for this + // reason: on extending a test function containing a single call to that + // free function, a maintainer would most likely make additional calls to + // that free function, instead of switching to an explicit WrapLLErrs + // declaration with several calls to its catch_llerrs() member function. + // Even a construct such as WrapLLErrs().catch_llerrs(...) would make the + // object declaration more visible; it's not unreasonable to expect a + // maintainer to extend that by naming and reusing the WrapLLErrs instance. + template + std::string catch_llerrs(FUNC func) + { + return catch_what(func); + } + std::string error; LLError::SettingsStoragePtr mPriorErrorSettings; LLError::FatalFunction mPriorFatal; }; -/// Convenience wrapper for catch_what() -template -std::string catch_llerrs(FUNC func) -{ - return catch_what(func); -} - /** * Capture log messages. This is adapted (simplified) from the one in * llerror_test.cpp. -- cgit v1.2.3