You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It might be useful to have a new logger called UNSCOPED_CAPTURE, which relates to CAPTURE in the same way that UNSCOPED_INFO relates to INFO. That is, it works like CAPTURE but its lifetime is not limited to its scope. This would permit invoking CAPTURE inside control flow or inner functions which do not encounter an assertion (like REQUIRE) before the end-of-scope, yet still have the output displayed when the calling scope (like a TEST_CASE) hits the assertion.
Motivation
Currently, CAPTURE's limited lifetime has the same limitations of INFO. This means running code like:
voidinner(x) {
CAPTURE( x );
// no assertions here, so CAPTURE silent
}
TEST_CASE( "demo" ) {
int x = 2;
inner(x);
FAIL( );
}
will not display x := 2. Such a use-case is motivated by inner() being a customisation of CAPTURE which (for example) chooses which variables to display based on compile-time constants. For example:
template <bool Show>
voidrunTest() {
int x = 2;
// this will never showifconstexpr (Show) {
CAPTURE( x );
}
FAIL();
}
TEST_CASE( "demoA" ) {
runTest<true>();
}
TEST_CASE( "demoB" ) {
runTest<false>();
}
Even the constexpr branch has a scope, so CAPTURE's output is lost. Above is akin to my situation; I have a templated function used to automate many TEST_CASEs (yucky I know - woe scientific software) and I must consult the template parameters to choose which variables CAPTURE should show if/when the test subsequently fails.
In principle, I can manually invoke UNSCOPED_INFO myself, but then I have to re-implement CAPTURE's lovely printing of nested vectors, for example.
Description
A new macro UNSCOPED_CAPTURE which works exactly like CAPTURE, but which has the scoping behaviour of UNSCOPED_INFO.
The text was updated successfully, but these errors were encountered:
It might be useful to have a new logger called
UNSCOPED_CAPTURE
, which relates toCAPTURE
in the same way thatUNSCOPED_INFO
relates toINFO
. That is, it works likeCAPTURE
but its lifetime is not limited to its scope. This would permit invokingCAPTURE
inside control flow or inner functions which do not encounter an assertion (likeREQUIRE
) before the end-of-scope, yet still have the output displayed when the calling scope (like aTEST_CASE
) hits the assertion.Motivation
Currently,
CAPTURE
's limited lifetime has the same limitations ofINFO
. This means running code like:will not display
x := 2
. Such a use-case is motivated byinner()
being a customisation ofCAPTURE
which (for example) chooses which variables to display based on compile-time constants. For example:Even the
constexpr
branch has a scope, soCAPTURE
's output is lost. Above is akin to my situation; I have a templated function used to automate manyTEST_CASE
s (yucky I know - woe scientific software) and I must consult the template parameters to choose which variablesCAPTURE
should show if/when the test subsequently fails.In principle, I can manually invoke
UNSCOPED_INFO
myself, but then I have to re-implementCAPTURE
's lovely printing of nested vectors, for example.Description
A new macro
UNSCOPED_CAPTURE
which works exactly likeCAPTURE
, but which has the scoping behaviour ofUNSCOPED_INFO
.The text was updated successfully, but these errors were encountered: