diff options
author | Leonardo Menti <leonardo.menti@mongodb.com> | 2022-07-08 14:24:30 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-07-12 15:37:57 +0000 |
commit | f3fb3ba01807ef304fb374223095a5fd01126f51 (patch) | |
tree | 2fb0aad54ecf4662a7197466dbfeeacf2d6762d9 /src/mongo | |
parent | 131c84d87f754210993c334b4825c69f042ee776 (diff) | |
download | mongo-f3fb3ba01807ef304fb374223095a5fd01126f51.tar.gz |
SERVER-66760 Add ASSERT_DOES_NOT_THROW to unittest assertions
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/db/commands/map_reduce_agg_test.cpp | 9 | ||||
-rw-r--r-- | src/mongo/db/index_builds_coordinator_test.cpp | 9 | ||||
-rw-r--r-- | src/mongo/db/pipeline/expression_context_test.cpp | 9 | ||||
-rw-r--r-- | src/mongo/db/pipeline/pipeline_metadata_tree_test.cpp | 10 | ||||
-rw-r--r-- | src/mongo/db/update/update_driver_test.cpp | 9 | ||||
-rw-r--r-- | src/mongo/dbtests/query_stage_update.cpp | 9 | ||||
-rw-r--r-- | src/mongo/unittest/unittest.h | 15 |
7 files changed, 15 insertions, 55 deletions
diff --git a/src/mongo/db/commands/map_reduce_agg_test.cpp b/src/mongo/db/commands/map_reduce_agg_test.cpp index 52ee67c416b..b47b2bfa0e4 100644 --- a/src/mongo/db/commands/map_reduce_agg_test.cpp +++ b/src/mongo/db/commands/map_reduce_agg_test.cpp @@ -46,15 +46,6 @@ #include "mongo/db/pipeline/expression_context_for_test.h" #include "mongo/unittest/unittest.h" -#define ASSERT_DOES_NOT_THROW(EXPRESSION) \ - try { \ - EXPRESSION; \ - } catch (const AssertionException& e) { \ - str::stream err; \ - err << "Threw an exception incorrectly: " << e.toString(); \ - ::mongo::unittest::TestAssertionFailure(__FILE__, __LINE__, err).stream(); \ - } - namespace mongo { namespace { diff --git a/src/mongo/db/index_builds_coordinator_test.cpp b/src/mongo/db/index_builds_coordinator_test.cpp index cc3b847874f..eb4e7a7ad20 100644 --- a/src/mongo/db/index_builds_coordinator_test.cpp +++ b/src/mongo/db/index_builds_coordinator_test.cpp @@ -31,15 +31,6 @@ #include "mongo/db/catalog/catalog_test_fixture.h" -#define ASSERT_DOES_NOT_THROW(EXPRESSION) \ - try { \ - EXPRESSION; \ - } catch (const AssertionException& e) { \ - str::stream err; \ - err << "Threw an exception incorrectly: " << e.toString(); \ - ::mongo::unittest::TestAssertionFailure(__FILE__, __LINE__, err).stream(); \ - } - namespace mongo { namespace { diff --git a/src/mongo/db/pipeline/expression_context_test.cpp b/src/mongo/db/pipeline/expression_context_test.cpp index b105dce531b..2ff0ef20b1e 100644 --- a/src/mongo/db/pipeline/expression_context_test.cpp +++ b/src/mongo/db/pipeline/expression_context_test.cpp @@ -39,15 +39,6 @@ #include "mongo/db/vector_clock_mutable.h" #include "mongo/unittest/unittest.h" -#define ASSERT_DOES_NOT_THROW(EXPRESSION) \ - try { \ - EXPRESSION; \ - } catch (const AssertionException& e) { \ - str::stream err; \ - err << "Threw an exception incorrectly: " << e.toString(); \ - ::mongo::unittest::TestAssertionFailure(__FILE__, __LINE__, err).stream(); \ - } - namespace mongo { namespace { diff --git a/src/mongo/db/pipeline/pipeline_metadata_tree_test.cpp b/src/mongo/db/pipeline/pipeline_metadata_tree_test.cpp index 8b8f6597596..b34a1cfc2c3 100644 --- a/src/mongo/db/pipeline/pipeline_metadata_tree_test.cpp +++ b/src/mongo/db/pipeline/pipeline_metadata_tree_test.cpp @@ -58,16 +58,6 @@ #include "mongo/unittest/temp_dir.h" #include "mongo/unittest/unittest.h" -#define ASSERT_DOES_NOT_THROW(EXPRESSION) \ - try { \ - EXPRESSION; \ - } catch (const AssertionException& e) { \ - ::mongo::str::stream err; \ - err << "Threw an exception incorrectly: " << e.toString() \ - << " Exception occured in: " << #EXPRESSION; \ - ::mongo::unittest::TestAssertionFailure(__FILE__, __LINE__, err).stream(); \ - } - namespace mongo { namespace { diff --git a/src/mongo/db/update/update_driver_test.cpp b/src/mongo/db/update/update_driver_test.cpp index 2d03e4b7886..86f6ae492bf 100644 --- a/src/mongo/db/update/update_driver_test.cpp +++ b/src/mongo/db/update/update_driver_test.cpp @@ -46,15 +46,6 @@ #include "mongo/db/update_index_data.h" #include "mongo/unittest/unittest.h" -#define ASSERT_DOES_NOT_THROW(EXPRESSION) \ - try { \ - EXPRESSION; \ - } catch (const AssertionException& e) { \ - ::mongo::str::stream err; \ - err << "Threw an exception incorrectly: " << e.toString(); \ - ::mongo::unittest::TestAssertionFailure(__FILE__, __LINE__, err).stream(); \ - } - namespace mongo { namespace { diff --git a/src/mongo/dbtests/query_stage_update.cpp b/src/mongo/dbtests/query_stage_update.cpp index 2ae8011e9c8..1c6d2302260 100644 --- a/src/mongo/dbtests/query_stage_update.cpp +++ b/src/mongo/dbtests/query_stage_update.cpp @@ -55,15 +55,6 @@ #include "mongo/db/update/update_driver.h" #include "mongo/dbtests/dbtests.h" -#define ASSERT_DOES_NOT_THROW(EXPRESSION) \ - try { \ - EXPRESSION; \ - } catch (const AssertionException& e) { \ - ::str::stream err; \ - err << "Threw an exception incorrectly: " << e.toString(); \ - ::mongo::unittest::TestAssertionFailure(__FILE__, __LINE__, err).stream(); \ - } - namespace QueryStageUpdate { using std::make_unique; diff --git a/src/mongo/unittest/unittest.h b/src/mongo/unittest/unittest.h index 3b37a565261..728de3e38d2 100644 --- a/src/mongo/unittest/unittest.h +++ b/src/mongo/unittest/unittest.h @@ -150,6 +150,21 @@ ASSERT_THROWS_WITH_CHECK(EXPRESSION, EXCEPTION_TYPE, ([](const EXCEPTION_TYPE&) {})) /** + * Verify that the evaluation of "EXPRESSION" does not throw any exceptions. + * + * If "EXPRESSION" throws an exception the test is considered a failure and further evaluation + * halts. + */ +#define ASSERT_DOES_NOT_THROW(EXPRESSION) \ + try { \ + EXPRESSION; \ + } catch (const AssertionException& e) { \ + str::stream err; \ + err << "Threw an exception incorrectly: " << e.toString(); \ + FAIL(err); \ + } + +/** * Behaves like ASSERT_THROWS, above, but also fails if calling what() on the thrown exception * does not return a string equal to EXPECTED_WHAT. */ |