[SERVER-14106] Implement expectDeath enhancements for unit testing Created: 30/May/14  Updated: 11/Dec/15  Resolved: 11/Dec/15

Status: Closed
Project: Core Server
Component/s: Testing Infrastructure
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Eric Milkie Assignee: Andy Schwerin
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-19005 Support C++ death tests which test th... Closed
Backwards Compatibility: Fully Compatible
Participants:

 Description   

To allow for full code coverage of fassert() calls in C++ unit tests.



 Comments   
Comment by Kamran K. [ 11/Dec/15 ]

I believe this functionality is now supported by the DEATH_TEST* macros that were added as part of SERVER-19005.

Comment by Andrew Morrow (Inactive) [ 04/Jun/14 ]

Ah, I see. I think we were talking about slightly different things. The problem that we encountered more frequently when converting was that there would be functions using non-void return types that used ASSERT/FAIL, and those would not compile.

For the issue you are pointing out, this seems to be explicitly intended behavior. This seems to be how to cope: https://code.google.com/p/googletest/wiki/AdvancedGuide#Propagating_Fatal_Failures

Comment by Andy Schwerin [ 04/Jun/14 ]

If FAIL doesn't work, then ASSERT_ doesn't, either, I suspect. The problem is that ASSERT_* in googletest devolves to return, which has the effect of converting ASSERTs inside function calls into EXPECTs with some caveats.

For example,

void myAssert(...) {
    ASSERT_GT(...);
}
 
TEST(A, B) {
  myAssert(...);
  FAIL("Should only be reachable if myAssert passes")
} 

I posit that TEST(A, B) will always call FAIL, regardless of whether or not the assert in myAssert passes.

Comment by Andrew Morrow (Inactive) [ 04/Jun/14 ]

I think that ASSERT_* works ok, but FAIL doesn't work in functions that return something other than void, from what I remember. That was a bit of a pain, but there really weren't that many instances of FAIL.

For some evidence that ASSERT_ works ok, here is a function using ASSERT_ in the C++ driver unit tests: https://github.com/mongodb/mongo-cxx-driver/blob/legacy/src/mongo/base/parse_number_test.cpp#L48

Comment by Andy Schwerin [ 04/Jun/14 ]

Not that radical. Currently the unittest framework drives test.exe, which is why I went the current route two years ago, but that's a diminishing fraction of our tests, now, so I'd be ready to move away. It used to be that you couldn't use ASSERT_* macros productively inside of function calls, because they just returned to the caller. Is that better, now?

Comment by Andrew Morrow (Inactive) [ 04/Jun/14 ]

As a somewhat radical suggestion or though experiment: we could just move to googletest and get that for free. Our existing unit tests are almost directly portable. The C++ driver switched, the shim that we wrote to make our existing C++ unit tests work: https://github.com/mongodb/mongo-cxx-driver/blob/legacy/src/mongo/unittest/unittest.h

Generated at Thu Feb 08 03:33:53 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.