Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Why aren Google Test assertions implemented using exceptions?

0
Posted

Why aren Google Test assertions implemented using exceptions?

0

Our original motivation was to be able to use Google Test in projects that disable exceptions. Later we realized some additional benefits of this approach: • Throwing in a destructor is undefined behavior in C++. Not using exceptions means Google Test’s assertions are safe to use in destructors. • The EXPECT_* family of macros will continue even after a failure, allowing multiple failures in a TEST to be reported in a single run. This is a popular feature, as in C++ the edit-compile-test cycle is usually quite long and being able to fixing more than one thing at a time is a blessing. • If assertions are implemented using exceptions, a test may falsely ignore a failure if it’s caught by user code: try { … ASSERT_TRUE(…) … } catch (…) { … } The above code will pass even if the ASSERT_TRUE throws. While it’s unlikely for someone to write this in a test, it’s possible to run into this pattern when you write assertions in callbacks that are called by the code under test. The downs

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123