summaryrefslogtreecommitdiff
path: root/src/mongo/unittest/unittest.h
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2015-05-13 16:16:26 -0400
committerBenety Goh <benety@mongodb.com>2015-05-14 20:47:06 -0400
commitf3d242c808ec6c1b7145dd3f084da438829552cb (patch)
tree0dd6e60dd8e247d4e64e3f5b2a17588747ce0247 /src/mongo/unittest/unittest.h
parent463d3343d559590d60cfd5c48ac98ad675d5390e (diff)
downloadmongo-f3d242c808ec6c1b7145dd3f084da438829552cb.tar.gz
SERVER-18016 added unit test assertion macro to check error code in exception
Diffstat (limited to 'src/mongo/unittest/unittest.h')
-rw-r--r--src/mongo/unittest/unittest.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/mongo/unittest/unittest.h b/src/mongo/unittest/unittest.h
index b5f6f3eb850..e22f76c5f1d 100644
--- a/src/mongo/unittest/unittest.h
+++ b/src/mongo/unittest/unittest.h
@@ -135,6 +135,15 @@
::mongo::stdx::placeholders::_1)))
/**
+ * Behaves like ASSERT_THROWS, above, but also fails if calling getCode() on the thrown exception
+ * does not return an error code equal to EXPECTED_CODE.
+ */
+#define ASSERT_THROWS_CODE(STATEMENT, EXCEPTION_TYPE, EXPECTED_CODE) \
+ ASSERT_THROWS_PRED(STATEMENT, \
+ EXCEPTION_TYPE, \
+ ([](const EXCEPTION_TYPE& ex) { return (EXPECTED_CODE) == ex.getCode(); }))
+
+/**
* Behaves like ASSERT_THROWS, above, but also fails if PREDICATE(ex) for the throw exception, ex,
* is false.
*/