summaryrefslogtreecommitdiffstats
path: root/googletest/docs/AdvancedGuide.md
diff options
context:
space:
mode:
Diffstat (limited to 'googletest/docs/AdvancedGuide.md')
-rw-r--r--googletest/docs/AdvancedGuide.md30
1 files changed, 25 insertions, 5 deletions
diff --git a/googletest/docs/AdvancedGuide.md b/googletest/docs/AdvancedGuide.md
index e1df20d..6605f44 100644
--- a/googletest/docs/AdvancedGuide.md
+++ b/googletest/docs/AdvancedGuide.md
@@ -872,13 +872,33 @@ TEST(FooTest, Bar) {
}
```
-Since we don't use exceptions, it is technically impossible to
-implement the intended behavior here. To alleviate this, Google Test
-provides two solutions. You could use either the
-`(ASSERT|EXPECT)_NO_FATAL_FAILURE` assertions or the
-`HasFatalFailure()` function. They are described in the following two
+To alleviate this, gUnit provides three different solutions. You could use
+either exceptions, the `(ASSERT|EXPECT)_NO_FATAL_FAILURE` assertions or the
+`HasFatalFailure()` function. They are described in the following two
subsections.
+#### Asserting on Subroutines with an exception
+
+The following code can turn ASSERT-failure into an exception:
+
+```c++
+class ThrowListener : public testing::EmptyTestEventListener {
+ void OnTestPartResult(const testing::TestPartResult& result) override {
+ if (result.type() == testing::TestPartResult::kFatalFailure) {
+ throw testing::AssertionException(result);
+ }
+ }
+};
+int main(int argc, char** argv) {
+ ...
+ testing::UnitTest::GetInstance()->listeners().Append(new ThrowListener);
+ return RUN_ALL_TESTS();
+}
+```
+
+This listener should be added after other listeners if you have any, otherwise
+they won't see failed `OnTestPartResult`.
+
### Asserting on Subroutines ###
As shown above, if your test calls a subroutine that has an `ASSERT_*`