summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorADAM David Alan Martin <adam.martin@10gen.com>2018-10-02 18:01:59 -0400
committerADAM David Alan Martin <adam.martin@10gen.com>2018-10-02 18:03:42 -0400
commit0380ac1465fcd05e2577351d5df226eb6bbccaa5 (patch)
tree68112921bf2524cb3da13f6255577edb7917ab7b /src
parent2d379ce39872fdfc04e6775ed8adea7ccdd1d1c1 (diff)
downloadmongo-0380ac1465fcd05e2577351d5df226eb6bbccaa5.tar.gz
SERVER-37365 Don't use `ignore()` in some tests.
It shouldn't be necessary to explicitly ignore status returns in functions when testing their throw behavior - the test is sufficient to indicate that `Status` is ignored.
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/auth/authorization_session_test.cpp2
-rw-r--r--src/mongo/db/catalog/database_test.cpp3
-rw-r--r--src/mongo/db/catalog/drop_database_test.cpp4
-rw-r--r--src/mongo/db/catalog/rename_collection_test.cpp7
-rw-r--r--src/mongo/db/keys_collection_manager_sharding_test.cpp7
-rw-r--r--src/mongo/db/logical_clock_test.cpp3
-rw-r--r--src/mongo/db/repl/rs_rollback_test.cpp37
-rw-r--r--src/mongo/db/repl/storage_interface_impl_test.cpp30
-rw-r--r--src/mongo/db/repl/sync_tail_test.cpp21
-rw-r--r--src/mongo/db/views/view_catalog_test.cpp16
-rw-r--r--src/mongo/dbtests/validate_tests.cpp3
-rw-r--r--src/mongo/unittest/unittest.h32
-rw-r--r--src/mongo/unittest/unittest_main.cpp2
13 files changed, 85 insertions, 82 deletions
diff --git a/src/mongo/db/auth/authorization_session_test.cpp b/src/mongo/db/auth/authorization_session_test.cpp
index 35eb7e5c56d..4ae564a3518 100644
--- a/src/mongo/db/auth/authorization_session_test.cpp
+++ b/src/mongo/db/auth/authorization_session_test.cpp
@@ -845,7 +845,7 @@ TEST_F(AuthorizationSessionTest, AddPrivilegesForStageFailsIfOutNamespaceIsNotVa
<< ""));
BSONObj cmdObj =
BSON("aggregate" << testFooNss.coll() << "pipeline" << pipeline << "cursor" << BSONObj());
- ASSERT_THROWS_CODE(authzSession->checkAuthForAggregate(testFooNss, cmdObj, false).ignore(),
+ ASSERT_THROWS_CODE(authzSession->checkAuthForAggregate(testFooNss, cmdObj, false),
AssertionException,
ErrorCodes::InvalidNamespace);
}
diff --git a/src/mongo/db/catalog/database_test.cpp b/src/mongo/db/catalog/database_test.cpp
index 2554b5e3df6..a64e61b12c8 100644
--- a/src/mongo/db/catalog/database_test.cpp
+++ b/src/mongo/db/catalog/database_test.cpp
@@ -315,8 +315,7 @@ void _testDropCollectionThrowsExceptionIfThereAreIndexesInProgress(OperationCont
ASSERT_GREATER_THAN(indexCatalog->numIndexesInProgress(opCtx), 0);
WriteUnitOfWork wuow(opCtx);
- ASSERT_THROWS_CODE(
- db->dropCollection(opCtx, nss.ns()).transitional_ignore(), AssertionException, 40461);
+ ASSERT_THROWS_CODE(db->dropCollection(opCtx, nss.ns()), AssertionException, 40461);
});
}
diff --git a/src/mongo/db/catalog/drop_database_test.cpp b/src/mongo/db/catalog/drop_database_test.cpp
index 9cf3c7eefa7..7ede18b7321 100644
--- a/src/mongo/db/catalog/drop_database_test.cpp
+++ b/src/mongo/db/catalog/drop_database_test.cpp
@@ -301,7 +301,7 @@ TEST_F(DropDatabaseTest, DropDatabaseResetsDropPendingStateOnException) {
auto db = autoDb.getDb();
ASSERT_TRUE(db);
- ASSERT_THROWS_CODE_AND_WHAT(dropDatabase(_opCtx.get(), _nss.db().toString()).ignore(),
+ ASSERT_THROWS_CODE_AND_WHAT(dropDatabase(_opCtx.get(), _nss.db().toString()),
AssertionException,
ErrorCodes::OperationFailed,
"onDropCollection() failed");
@@ -455,7 +455,7 @@ TEST_F(DropDatabaseTest,
TEST_F(DropDatabaseTest, DropDatabaseFailsToDropAdmin) {
NamespaceString adminNSS(NamespaceString::kAdminDb, "foo");
_createCollection(_opCtx.get(), adminNSS);
- ASSERT_THROWS_CODE_AND_WHAT(dropDatabase(_opCtx.get(), adminNSS.db().toString()).ignore(),
+ ASSERT_THROWS_CODE_AND_WHAT(dropDatabase(_opCtx.get(), adminNSS.db().toString()),
AssertionException,
ErrorCodes::IllegalOperation,
"Dropping the 'admin' database is prohibited.");
diff --git a/src/mongo/db/catalog/rename_collection_test.cpp b/src/mongo/db/catalog/rename_collection_test.cpp
index e74ae6ed833..35c28353486 100644
--- a/src/mongo/db/catalog/rename_collection_test.cpp
+++ b/src/mongo/db/catalog/rename_collection_test.cpp
@@ -1070,10 +1070,9 @@ TEST_F(RenameCollectionTest, RenameCollectionAcrossDatabaseDropsTemporaryCollect
_insertDocument(_opCtx.get(), _sourceNss, BSON("_id" << 0));
_opObserver->onInsertsThrows = true;
_opObserver->oplogEntries.clear();
- ASSERT_THROWS_CODE(
- renameCollection(_opCtx.get(), _sourceNss, _targetNssDifferentDb, {}).ignore(),
- AssertionException,
- ErrorCodes::OperationFailed);
+ ASSERT_THROWS_CODE(renameCollection(_opCtx.get(), _sourceNss, _targetNssDifferentDb, {}),
+ AssertionException,
+ ErrorCodes::OperationFailed);
_checkOplogEntries(_opObserver->oplogEntries, {"create", "index", "drop"});
}
diff --git a/src/mongo/db/keys_collection_manager_sharding_test.cpp b/src/mongo/db/keys_collection_manager_sharding_test.cpp
index 005eaf049d8..994840091c3 100644
--- a/src/mongo/db/keys_collection_manager_sharding_test.cpp
+++ b/src/mongo/db/keys_collection_manager_sharding_test.cpp
@@ -90,10 +90,9 @@ TEST_F(KeysManagerShardedTest, GetKeyForValidationTimesOutIfRefresherIsNotRunnin
operationContext()->setDeadlineAfterNowBy(Microseconds(250 * 1000),
ErrorCodes::ExceededTimeLimit);
- ASSERT_THROWS(keyManager()
- ->getKeyForValidation(operationContext(), 1, LogicalTime(Timestamp(100, 0)))
- .status_with_transitional_ignore(),
- DBException);
+ ASSERT_THROWS(
+ keyManager()->getKeyForValidation(operationContext(), 1, LogicalTime(Timestamp(100, 0))),
+ DBException);
}
TEST_F(KeysManagerShardedTest, GetKeyForValidationErrorsIfKeyDoesntExist) {
diff --git a/src/mongo/db/logical_clock_test.cpp b/src/mongo/db/logical_clock_test.cpp
index 0db83d6dbee..5a895dca22e 100644
--- a/src/mongo/db/logical_clock_test.cpp
+++ b/src/mongo/db/logical_clock_test.cpp
@@ -326,8 +326,7 @@ TEST_F(LogicalClockTest, RejectsLogicalTimesGreaterThanMaxTime) {
auto almostMaxSecs =
Seconds(maxVal) - LogicalClock::kMaxAcceptableLogicalClockDriftSecs + Seconds(10);
setMockClockSourceTime(Date_t::fromDurationSinceEpoch(almostMaxSecs));
- ASSERT_THROWS(getClock()->advanceClusterTime(beyondMaxTime).transitional_ignore(),
- std::exception);
+ ASSERT_THROWS(getClock()->advanceClusterTime(beyondMaxTime), std::exception);
ASSERT_TRUE(getClock()->getClusterTime() == LogicalTime());
}
diff --git a/src/mongo/db/repl/rs_rollback_test.cpp b/src/mongo/db/repl/rs_rollback_test.cpp
index 8b254a65988..11133a1bd6f 100644
--- a/src/mongo/db/repl/rs_rollback_test.cpp
+++ b/src/mongo/db/repl/rs_rollback_test.cpp
@@ -246,8 +246,7 @@ TEST_F(RSRollbackTest, RemoteGetRollbackIdThrows) {
RollbackSourceLocal(stdx::make_unique<OplogInterfaceMock>()),
{},
_coordinator,
- _replicationProcess.get())
- .transitional_ignore(),
+ _replicationProcess.get()),
AssertionException,
ErrorCodes::UnknownError);
}
@@ -270,8 +269,7 @@ TEST_F(RSRollbackTest, RemoteGetRollbackIdDiffersFromRequiredRBID) {
RollbackSourceLocal(stdx::make_unique<OplogInterfaceMock>()),
1,
_coordinator,
- _replicationProcess.get())
- .transitional_ignore(),
+ _replicationProcess.get()),
AssertionException,
ErrorCodes::duplicateCodeForTest(40506));
}
@@ -1521,8 +1519,7 @@ TEST_F(RSRollbackTest, RollbackCollModCommandFailsIfRBIDChangesWhileSyncingColle
rollbackSource,
0,
_coordinator,
- _replicationProcess.get())
- .transitional_ignore(),
+ _replicationProcess.get()),
DBException,
40508);
ASSERT(rollbackSource.getCollectionInfoCalled);
@@ -2029,9 +2026,8 @@ TEST(RSRollbackTest, LocalEntryWithoutNsIsFatal) {
<< ""
<< "o"
<< BSON("_id" << 1 << "a" << 1));
- ASSERT_THROWS(
- updateFixUpInfoFromLocalOplogEntry(fui, invalidOplogEntry, false).transitional_ignore(),
- RSFatalException);
+ ASSERT_THROWS(updateFixUpInfoFromLocalOplogEntry(fui, invalidOplogEntry, false),
+ RSFatalException);
}
TEST(RSRollbackTest, LocalEntryWithoutOIsFatal) {
@@ -2065,9 +2061,8 @@ TEST(RSRollbackTest, LocalEntryWithoutOIsFatal) {
<< "test.t"
<< "o"
<< BSONObj());
- ASSERT_THROWS(
- updateFixUpInfoFromLocalOplogEntry(fui, invalidOplogEntry, false).transitional_ignore(),
- RSFatalException);
+ ASSERT_THROWS(updateFixUpInfoFromLocalOplogEntry(fui, invalidOplogEntry, false),
+ RSFatalException);
}
TEST(RSRollbackTest, LocalUpdateEntryWithoutO2IsFatal) {
@@ -2103,9 +2098,8 @@ TEST(RSRollbackTest, LocalUpdateEntryWithoutO2IsFatal) {
<< "test.t"
<< "o"
<< BSON("_id" << 1 << "a" << 1));
- ASSERT_THROWS(
- updateFixUpInfoFromLocalOplogEntry(fui, invalidOplogEntry, false).transitional_ignore(),
- RSFatalException);
+ ASSERT_THROWS(updateFixUpInfoFromLocalOplogEntry(fui, invalidOplogEntry, false),
+ RSFatalException);
}
TEST(RSRollbackTest, LocalUpdateEntryWithEmptyO2IsFatal) {
@@ -2143,9 +2137,8 @@ TEST(RSRollbackTest, LocalUpdateEntryWithEmptyO2IsFatal) {
<< BSON("_id" << 1 << "a" << 1)
<< "o2"
<< BSONObj());
- ASSERT_THROWS(
- updateFixUpInfoFromLocalOplogEntry(fui, invalidOplogEntry, false).transitional_ignore(),
- RSFatalException);
+ ASSERT_THROWS(updateFixUpInfoFromLocalOplogEntry(fui, invalidOplogEntry, false),
+ RSFatalException);
}
DEATH_TEST_F(RSRollbackTest, LocalEntryWithTxnNumberWithoutSessionIdIsFatal, "invariant") {
@@ -2165,8 +2158,7 @@ DEATH_TEST_F(RSRollbackTest, LocalEntryWithTxnNumberWithoutSessionIdIsFatal, "in
const auto stmtId = BSON("stmtId" << 1);
const auto noSessionId = noSessionIdOrStmtId.addField(stmtId.firstElement());
- ASSERT_THROWS(updateFixUpInfoFromLocalOplogEntry(fui, noSessionId, false).transitional_ignore(),
- RSFatalException);
+ ASSERT_THROWS(updateFixUpInfoFromLocalOplogEntry(fui, noSessionId, false), RSFatalException);
}
DEATH_TEST_F(RSRollbackTest, LocalEntryWithTxnNumberWithoutStmtIdIsFatal, "invariant") {
@@ -2187,8 +2179,7 @@ DEATH_TEST_F(RSRollbackTest, LocalEntryWithTxnNumberWithoutStmtIdIsFatal, "invar
const auto lsid = makeLogicalSessionIdForTest();
const auto sessionId = BSON("lsid" << lsid.toBSON());
const auto noStmtId = noSessionIdOrStmtId.addField(sessionId.firstElement());
- ASSERT_THROWS(updateFixUpInfoFromLocalOplogEntry(fui, noStmtId, false).transitional_ignore(),
- RSFatalException);
+ ASSERT_THROWS(updateFixUpInfoFromLocalOplogEntry(fui, noStmtId, false), RSFatalException);
}
TEST_F(RSRollbackTest, LocalEntryWithTxnNumberWithoutTxnTableUUIDIsFatal) {
@@ -2212,7 +2203,7 @@ TEST_F(RSRollbackTest, LocalEntryWithTxnNumberWithoutTxnTableUUIDIsFatal) {
<< lsid.toBSON());
FixUpInfo fui;
- ASSERT_THROWS(updateFixUpInfoFromLocalOplogEntry(fui, entryWithTxnNumber, false).ignore(),
+ ASSERT_THROWS(updateFixUpInfoFromLocalOplogEntry(fui, entryWithTxnNumber, false),
RSFatalException);
}
diff --git a/src/mongo/db/repl/storage_interface_impl_test.cpp b/src/mongo/db/repl/storage_interface_impl_test.cpp
index c14d6a9c00b..66787596d28 100644
--- a/src/mongo/db/repl/storage_interface_impl_test.cpp
+++ b/src/mongo/db/repl/storage_interface_impl_test.cpp
@@ -525,7 +525,7 @@ TEST_F(StorageInterfaceImplTest, InsertDocumentThrowsNamespaceNotFoundIfOplogUUI
auto opCtx = getOperationContext();
StorageInterfaceImpl storage;
ASSERT_THROWS_CODE(
- storage.insertDocuments(opCtx, {"local", UUID::gen()}, transformInserts({op})).ignore(),
+ storage.insertDocuments(opCtx, {"local", UUID::gen()}, transformInserts({op})),
DBException,
ErrorCodes::NamespaceNotFound);
}
@@ -1910,10 +1910,9 @@ TEST_F(StorageInterfaceImplTest, FindByIdThrowsIfUUIDNotInCatalog) {
auto obj = BSON("_id"
<< "kyle");
StorageInterfaceImpl storage;
- ASSERT_THROWS_CODE(
- storage.findById(opCtx, {"local", UUID::gen()}, obj["_id"]).getStatus().ignore(),
- DBException,
- ErrorCodes::NamespaceNotFound);
+ ASSERT_THROWS_CODE(storage.findById(opCtx, {"local", UUID::gen()}, obj["_id"]).getStatus(),
+ DBException,
+ ErrorCodes::NamespaceNotFound);
}
TEST_F(StorageInterfaceImplTest, FindByIdReturnsNamespaceNotFoundWhenDatabaseDoesNotExist) {
@@ -2003,10 +2002,9 @@ TEST_F(StorageInterfaceImplTest, DeleteByIdThrowsIfUUIDNotInCatalog) {
auto obj = BSON("_id"
<< "kyle");
StorageInterfaceImpl storage;
- ASSERT_THROWS_CODE(
- storage.deleteById(opCtx, {"local", UUID::gen()}, obj["_id"]).getStatus().ignore(),
- DBException,
- ErrorCodes::NamespaceNotFound);
+ ASSERT_THROWS_CODE(storage.deleteById(opCtx, {"local", UUID::gen()}, obj["_id"]).getStatus(),
+ DBException,
+ ErrorCodes::NamespaceNotFound);
}
TEST_F(StorageInterfaceImplTest, DeleteByIdReturnsNamespaceNotFoundWhenDatabaseDoesNotExist) {
@@ -2078,7 +2076,7 @@ TEST_F(StorageInterfaceImplTest, UpsertByIdThrowsIfUUIDNotInCatalog) {
auto obj = BSON("_id"
<< "kyle");
StorageInterfaceImpl storage;
- ASSERT_THROWS_CODE(storage.upsertById(opCtx, {"local", UUID::gen()}, obj["_id"], obj).ignore(),
+ ASSERT_THROWS_CODE(storage.upsertById(opCtx, {"local", UUID::gen()}, obj["_id"], obj),
DBException,
ErrorCodes::NamespaceNotFound);
}
@@ -2265,17 +2263,15 @@ TEST_F(StorageInterfaceImplTest,
auto unknownUpdateOp = BSON("$unknownUpdateOp" << BSON("x" << 1000));
ASSERT_THROWS_CODE_AND_WHAT(
- storage.upsertById(opCtx, nss, BSON("" << 1).firstElement(), unknownUpdateOp).ignore(),
+ storage.upsertById(opCtx, nss, BSON("" << 1).firstElement(), unknownUpdateOp),
AssertionException,
ErrorCodes::FailedToParse,
"Unknown modifier: $unknownUpdateOp");
- ASSERT_THROWS_CODE(storage
- .upsertById(opCtx,
- {nss.db().toString(), *options.uuid},
- BSON("" << 1).firstElement(),
- unknownUpdateOp)
- .ignore(),
+ ASSERT_THROWS_CODE(storage.upsertById(opCtx,
+ {nss.db().toString(), *options.uuid},
+ BSON("" << 1).firstElement(),
+ unknownUpdateOp),
DBException,
ErrorCodes::FailedToParse);
}
diff --git a/src/mongo/db/repl/sync_tail_test.cpp b/src/mongo/db/repl/sync_tail_test.cpp
index 6c2d6d42258..32cb9afa7f2 100644
--- a/src/mongo/db/repl/sync_tail_test.cpp
+++ b/src/mongo/db/repl/sync_tail_test.cpp
@@ -232,9 +232,8 @@ auto parseFromOplogEntryArray(const BSONObj& obj, int elem) {
TEST_F(SyncTailTest, SyncApplyNoNamespaceBadOp) {
const BSONObj op = BSON("op"
<< "x");
- ASSERT_THROWS(
- SyncTail::syncApply(_opCtx.get(), op, OplogApplication::Mode::kInitialSync).ignore(),
- ExceptionFor<ErrorCodes::BadValue>);
+ ASSERT_THROWS(SyncTail::syncApply(_opCtx.get(), op, OplogApplication::Mode::kInitialSync),
+ ExceptionFor<ErrorCodes::BadValue>);
}
TEST_F(SyncTailTest, SyncApplyNoNamespaceNoOp) {
@@ -249,16 +248,15 @@ TEST_F(SyncTailTest, SyncApplyBadOp) {
<< "x"
<< "ns"
<< "test.t");
- ASSERT_THROWS(
- SyncTail::syncApply(_opCtx.get(), op, OplogApplication::Mode::kInitialSync).ignore(),
- ExceptionFor<ErrorCodes::BadValue>);
+ ASSERT_THROWS(SyncTail::syncApply(_opCtx.get(), op, OplogApplication::Mode::kInitialSync),
+ ExceptionFor<ErrorCodes::BadValue>);
}
TEST_F(SyncTailTest, SyncApplyInsertDocumentDatabaseMissing) {
NamespaceString nss("test.t");
auto op = makeOplogEntry(OpTypeEnum::kInsert, nss, {});
ASSERT_THROWS(
- SyncTail::syncApply(_opCtx.get(), op.toBSON(), OplogApplication::Mode::kSecondary).ignore(),
+ SyncTail::syncApply(_opCtx.get(), op.toBSON(), OplogApplication::Mode::kSecondary),
ExceptionFor<ErrorCodes::NamespaceNotFound>);
}
@@ -274,7 +272,7 @@ TEST_F(SyncTailTest, SyncApplyInsertDocumentCollectionLookupByUUIDFails) {
NamespaceString otherNss(nss.getSisterNS("othername"));
auto op = makeOplogEntry(OpTypeEnum::kInsert, otherNss, kUuid);
ASSERT_THROWS(
- SyncTail::syncApply(_opCtx.get(), op.toBSON(), OplogApplication::Mode::kSecondary).ignore(),
+ SyncTail::syncApply(_opCtx.get(), op.toBSON(), OplogApplication::Mode::kSecondary),
ExceptionFor<ErrorCodes::NamespaceNotFound>);
}
@@ -294,7 +292,7 @@ TEST_F(SyncTailTest, SyncApplyInsertDocumentCollectionMissing) {
// implicitly create the collection and lock the database in MODE_X.
auto op = makeOplogEntry(OpTypeEnum::kInsert, nss, {});
ASSERT_THROWS(
- SyncTail::syncApply(_opCtx.get(), op.toBSON(), OplogApplication::Mode::kSecondary).ignore(),
+ SyncTail::syncApply(_opCtx.get(), op.toBSON(), OplogApplication::Mode::kSecondary),
ExceptionFor<ErrorCodes::NamespaceNotFound>);
ASSERT_FALSE(collectionExists(_opCtx.get(), nss));
}
@@ -382,9 +380,8 @@ TEST_F(SyncTailTest, SyncApplyCommandThrowsException) {
<< BSON("create"
<< "t"));
// This test relies on the namespace type check in applyCommand_inlock().
- ASSERT_THROWS(
- SyncTail::syncApply(_opCtx.get(), op, OplogApplication::Mode::kInitialSync).ignore(),
- ExceptionFor<ErrorCodes::InvalidNamespace>);
+ ASSERT_THROWS(SyncTail::syncApply(_opCtx.get(), op, OplogApplication::Mode::kInitialSync),
+ ExceptionFor<ErrorCodes::InvalidNamespace>);
}
DEATH_TEST_F(SyncTailTest, MultiApplyAbortsWhenNoOperationsAreGiven, "!ops.empty()") {
diff --git a/src/mongo/db/views/view_catalog_test.cpp b/src/mongo/db/views/view_catalog_test.cpp
index ac22a1b6247..28200ffc616 100644
--- a/src/mongo/db/views/view_catalog_test.cpp
+++ b/src/mongo/db/views/view_catalog_test.cpp
@@ -220,8 +220,7 @@ TEST_F(ViewCatalogFixture, CreateViewWithPipelineFailsOnInvalidStageName) {
auto invalidPipeline = BSON_ARRAY(BSON("INVALID_STAGE_NAME" << 1));
ASSERT_THROWS(
- viewCatalog.createView(opCtx.get(), viewName, viewOn, invalidPipeline, emptyCollation)
- .transitional_ignore(),
+ viewCatalog.createView(opCtx.get(), viewName, viewOn, invalidPipeline, emptyCollation),
AssertionException);
}
@@ -233,8 +232,7 @@ TEST_F(ReplViewCatalogFixture, CreateViewWithPipelineFailsOnIneligibleStage) {
auto invalidPipeline = BSON_ARRAY(BSON("$changeStream" << BSONObj()));
ASSERT_THROWS_CODE(
- viewCatalog.createView(opCtx.get(), viewName, viewOn, invalidPipeline, emptyCollation)
- .ignore(),
+ viewCatalog.createView(opCtx.get(), viewName, viewOn, invalidPipeline, emptyCollation),
AssertionException,
ErrorCodes::OptionNotSupportedOnView);
}
@@ -248,8 +246,7 @@ TEST_F(ReplViewCatalogFixture, CreateViewWithPipelineFailsOnIneligibleStagePersi
<< "someOtherCollection"));
ASSERT_THROWS_CODE(
- viewCatalog.createView(opCtx.get(), viewName, viewOn, invalidPipeline, emptyCollation)
- .ignore(),
+ viewCatalog.createView(opCtx.get(), viewName, viewOn, invalidPipeline, emptyCollation),
AssertionException,
ErrorCodes::OptionNotSupportedOnView);
}
@@ -424,10 +421,9 @@ TEST_F(ReplViewCatalogFixture, ModifyViewWithPipelineFailsOnIneligibleStage) {
ASSERT_OK(viewCatalog.createView(opCtx.get(), viewName, viewOn, validPipeline, emptyCollation));
// Now attempt to replace it with a pipeline containing $changeStream.
- ASSERT_THROWS_CODE(
- viewCatalog.modifyView(opCtx.get(), viewName, viewOn, invalidPipeline).ignore(),
- AssertionException,
- ErrorCodes::OptionNotSupportedOnView);
+ ASSERT_THROWS_CODE(viewCatalog.modifyView(opCtx.get(), viewName, viewOn, invalidPipeline),
+ AssertionException,
+ ErrorCodes::OptionNotSupportedOnView);
}
TEST_F(ViewCatalogFixture, LookupMissingView) {
diff --git a/src/mongo/dbtests/validate_tests.cpp b/src/mongo/dbtests/validate_tests.cpp
index 5cc747e128f..ddc62bffc0e 100644
--- a/src/mongo/dbtests/validate_tests.cpp
+++ b/src/mongo/dbtests/validate_tests.cpp
@@ -698,8 +698,7 @@ public:
<< "background"
<< false
<< "partialFilterExpression"
- << BSON("a" << BSON("$eq" << 2))))
- .transitional_ignore(),
+ << BSON("a" << BSON("$eq" << 2)))),
AssertionException);
// Create a partial geo index that does not index the document.
diff --git a/src/mongo/unittest/unittest.h b/src/mongo/unittest/unittest.h
index 29a6c76f5b9..17e9c9416b3 100644
--- a/src/mongo/unittest/unittest.h
+++ b/src/mongo/unittest/unittest.h
@@ -153,13 +153,43 @@
}))
/**
+ * This internal helper is used to ignore warnings about unused results. Some unit tests which test
+ * `ASSERT_THROWS` and its variations are used on functions which both throw and return `Status` or
+ * `StatusWith` objects. Although such function designs are undesirable, they do exist, presently.
+ * Therefore this internal helper macro is used by `ASSERT_THROWS` and its variations to silence
+ * such warnings without forcing the caller to invoke `.ignore()` on the called function.
+ *
+ * NOTE: This macro should NOT be used inside regular unit test code to ignore unchecked `Status` or
+ * `StatusWith` instances -- if a `Status` or `StatusWith` result is to be ignored, please use the
+ * normal `.ignore()` code. This macro exists only to make using `ASSERT_THROWS` less inconvenient
+ * on functions which both throw and return `Status` or `StatusWith`.
+ */
+//#define UNIT_TEST_INTERNALS_IGNORE_UNUSED_RESULT_WARNINGS(STATEMENT)
+#ifdef __GNUC__
+// The `(void) 0`s are to permit more readable formatting of these in-macro pragma statements.
+#define UNIT_TEST_INTERNALS_IGNORE_UNUSED_RESULT_WARNINGS(STATEMENT) \
+ do { \
+ _Pragma("GCC diagnostic push")(void) 0; \
+ _Pragma("GCC diagnostic ignored \"-Wunused\"")(void) 0; \
+ _Pragma("GCC diagnostic ignored \"-Wunused-result\"")(void) 0; \
+ STATEMENT; \
+ _Pragma("GCC diagnostic pop")(void) 0; \
+ } while (false)
+#else
+#define UNIT_TEST_INTERNALS_IGNORE_UNUSED_RESULT_WARNINGS(STATEMENT) \
+ do { \
+ STATEMENT; \
+ } while (false)
+#endif
+
+/**
* Behaves like ASSERT_THROWS, above, but also calls CHECK(caughtException) which may contain
* additional assertions.
*/
#define ASSERT_THROWS_WITH_CHECK(STATEMENT, EXCEPTION_TYPE, CHECK) \
do { \
try { \
- STATEMENT; \
+ UNIT_TEST_INTERNALS_IGNORE_UNUSED_RESULT_WARNINGS(STATEMENT); \
FAIL("Expected statement " #STATEMENT " to throw " #EXCEPTION_TYPE \
" but it threw nothing."); \
} catch (const EXCEPTION_TYPE& ex) { \
diff --git a/src/mongo/unittest/unittest_main.cpp b/src/mongo/unittest/unittest_main.cpp
index 33e99099020..a5910a5b50c 100644
--- a/src/mongo/unittest/unittest_main.cpp
+++ b/src/mongo/unittest/unittest_main.cpp
@@ -1,5 +1,3 @@
-// mongo/unittest/unittest_main.cpp
-
/* Copyright 2010 10gen Inc.
*
* This program is free software: you can redistribute it and/or modify