Skip to content

Commit

Permalink
Make DRAKE_EXPECT_THROWS_MESSAGE behave like EXPECT_THROW (RobotLocom…
Browse files Browse the repository at this point in the history
…otion#12078)

* Make DRAKE_EXPECT_THROWS_MESSAGE behave like EXPECT_THROW

If DRAKE_EXPECT_THROWS_MESSAGE was used with an incompatible exception type
the test would fail just like it fails if an exception is thrown anywhere
in the code. EXPECT_THROW reports that a different exception type was
thrown and then moves on with the test. Now the drake macro has the same
behavior.

NOTE: It also gets the same behavior as ASSERT_THROW in that it prints
a nice message and then stops the rest of the test -- but it doesn't
crash out of the test.
  • Loading branch information
SeanCurtis-TRI authored Sep 23, 2019
1 parent 193a403 commit a0966ce
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions common/test_utilities/expect_throws_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,13 @@ do { \
try { \
expression; \
if (must_throw) { \
std::string message = "\tExpected: " #expression " throws an exception " \
"of type " #exception ".\n Actual: it throws " \
"nothing"; \
if (fatal_failure) { \
GTEST_FATAL_FAILURE_("\t" #expression " failed to throw " #exception); \
GTEST_FATAL_FAILURE_(message.c_str()); \
} else { \
GTEST_NONFATAL_FAILURE_("\t" #expression " failed to throw " #exception);\
GTEST_NONFATAL_FAILURE_(message.c_str());\
} \
} \
} catch (const exception& err) { \
Expand All @@ -75,6 +78,14 @@ try { \
} else { \
EXPECT_PRED2(matcher, err.what(), regexp); \
} \
} catch (...) { \
std::string message = "\tExpected: " #expression " throws an exception of " \
"type " #exception ".\n Actual: it throws a different type."; \
if (fatal_failure) { \
GTEST_FATAL_FAILURE_(message.c_str()); \
} else { \
GTEST_NONFATAL_FAILURE_(message.c_str()); \
} \
} \
} while (0)

Expand Down

0 comments on commit a0966ce

Please sign in to comment.