googletest
googletest copied to clipboard
Advanced googletest documentation's "Assertion Placement" section missing a compact workaround on non-void contexts
Describe the issue
A Googletest assertion requires the calling method to return void
. The advanced documentation on that topic suggests refactoring the method if required.
A more straightforward way to circumvent this limitation is to encompass the assertion call in an immediately called lambda expression.
ASSERT_TRUE(someCondition); // Doesn't compile in non-void context
[&](){ ASSERT_TRUE(someCondition); }(); // Compiles even in non-void context
With this issue I'd like to suggest adding this possibility to the Googletest advanced documentation.
Steps to reproduce the problem
Not applicable, it's a documentation improvement suggestion.
What version of GoogleTest are you using?
https://github.com/google/googletest/commit/934542165899c786cb5d8a710529c37184730183
What operating system and version are you using?
Not applicable, it's a documentation improvement suggestion.
What compiler and version are you using?
Not applicable, it's a documentation improvement suggestion.
What build system are you using?
Not applicable, it's a documentation improvement suggestion.
Additional context
I'm not the author of this creative workaround, but I don't manage to retrieve the original answer (probably on stackoverflow) that suggested it.